Algorithm question: how to flip the colors on a checkerboard using Xojo

sub flipEvenRows
for i = 0 to 500
for j = 0 to 500
 if (j mod 2)=(i mod 2) then myStates(i,j) = not( myStates(i,j) )
next 
next
end sub

no need for two logic statements

Thanks, Dave. Butwhat do I put for “myStates”? I just want to flip the colors, not the underlying values of the squares themselves.

I want to flip half the squares on the checkerboard: the squares that are on even rows along with even columns AND the squares that are on odd rows along with odd columns, so I think that Jeff’s code might be closer to what I’m looking for… but I still don’t understand what to put for “myStates” to get it to implement.

OK, I made myStates(500,500) a boolean. Why does it need to be (500,500)? My array can be as large as 300x300 and is resized by using least common multiples of 600 so the other booleans I have are, for instance, s(599,599).

Also, Jeff (or anybody), I have some questions about the following… for the first part of the code, do I include that in the method ColorSquares(i,j,thisS)? And how do I draw the box? I thought that the box is drawn already by GraphicsWindow.Paint ? And when do I call flipThecolors?

for i = 0 to 500
for j = 0 to 500
if myStates(i,j) = True then
//use color1
else
//use color2
end if
//draw the box
next
next

Here’s the current version of the program: https://www.dropbox.com/s/eizsitufrzufo9u/MyApp_v2.xojo_binary_project?dl=0

500 was just a guess at the maximum dimension.
myStates holds the data.

The paint event draws a representation of the data.
In the MVC (model view controller) methodology, the myStates array represents the model
The canvas represents the view
The controllers are the buttons.

You change the data.
The view displays it: in your case as coloured squares.

To paint it in the paint event you would:

[code]//fill the canvas with color 1

g.forecolor = color1
g.fillrect 0,0,g.width,g.height
g.forecolor = color2

for i = 0 to 500
for j = 0 to 500
if myStates(i,j) = True then
//draw a small rectangle in colour 2
g.fillrect isquaresize,j squaresize, squaresize,squaresize
end if

next
next[/code]

Thanks so much, Jeff. In my “paint” event I already have

App.ColorAll

Should I delete that then? If I delete that I get the entire canvas to have just one color, which is not what I want. I’m still not sure how to use the flipThecolors method or when I should call ColorSquares.

Here’s the current version of the program: https://www.dropbox.com/s/eizsitufrzufo9u/MyApp_v2.xojo_binary_project?dl=0

Where do I call the flipThecolors method?

App.flipThecolors
for i = 0 to size-1
for j = 0 to size-1
if j mod 2 = 0 and i mod 2 = 0 then myStates(i,j) = not( myStates(i,j) )
if j mod 2 = 1 and i mod 2 = 1 then myStates(i,j) = not( myStates(i,j) )
next
next
end Sub