Dear all,

When printing a grid, for example a chess board, I was hoping it wouldn't have the same output as the console.

When I want the position to be grid[x][y] = 5, 5, it will place the counter in the bottom right corner in a 5x5 grid, (5,1) instead of the reverse in the top right corner.

I've used the usual inner for loop stepping through and drawing the line.

Anyone experienced this before and know how to deal with this?

Any advice would be much appreciated.

Thanks,
Cleo

Recommended Answers

All 4 Replies

Because the graphics coordinates 00 is the upper right corner. simply subtract the coordinate you want to paint to from the over all height and use that as the y coordinate.

Thank you for your response.

The height of the screen resolution or the grid?

Using the resolution seems a little unreliable as I would have to find the difference based on the grid size...which is going to be dynamically chosen.

For the grid, yes this would work for the position 5,5 of a grid size 5,5, but when the y position = 2, minus by the y grid size 5, this would result in -3, going off the grid.

Am I interpreting this correct?

From the overall height of the desired image, of course.

Edit: And, of course, it is 5 - 2, not 2 - 5, in your example.

Ah, your correction to my sum made a lot of sense.

I could minus the y co-ordinate from the grid size and the image would be in the right position for each in each case...

for x ..
for y ..
grid[x][gridSize - y]
//paint image here

Thanks for your ideas!
I will actually test this later :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.