Computer Science Canada Drawing a Chessboard using repetition |
Author: | Derpmemes [ Wed Jun 20, 2012 6:29 pm ] |
Post subject: | Drawing a Chessboard using repetition |
I don't know how to write a program to draw a chessboard using repetition. (8x8) I know how to do it without using repetition. The code it tried was: drawfillbox (0,0,640,400,black) for i: 1..640 by 160 drawfillbox (0+i,0,80,50,white) end for I know this is not the code but at least I tried. Please Help. :'( The Chessboard I made without using repetition was easy. Here is the code: drawfillbox (0,0,640,400,black) %1 drawfillbox (0,0,80,50,white) drawfillbox (160,0,240,50,white) drawfillbox (320,0,400,50,white) drawfillbox (480,0,560,50,white) %2 drawfillbox (80,50,160,100,white) drawfillbox (240,50,320,100,white) drawfillbox (400,50,480,100,white) drawfillbox (560,50,640,100,white) %3 drawfillbox (0,100,80,150,white) drawfillbox (160,100,240,150,white) drawfillbox (320,100,400,150,white) drawfillbox (480,100,560,150,white) %4 drawfillbox (80,150,160,200,white) drawfillbox (240,150,320,200,white) drawfillbox (400,150,480,200,white) drawfillbox (560,150,640,200,white) %5 drawfillbox (0,200,80,250,white) drawfillbox (160,200,240,250,white) drawfillbox (320,200,400,250,white) drawfillbox (480,200,560,250,white) %6 drawfillbox (80,250,160,300,white) drawfillbox (240,250,320,300,white) drawfillbox (400,250,480,300,white) drawfillbox (560,250,640,300,white) %7 drawfillbox (0,300,80,350,white) drawfillbox (160,300,240,350,white) drawfillbox (320,300,400,350,white) drawfillbox (480,300,560,350,white) %8 drawfillbox (80,350,160,400,white) drawfillbox (240,350,320,400,white) drawfillbox (400,350,480,400,white) drawfillbox (560,350,640,400,white) Thank you. |
Author: | Zren [ Wed Jun 20, 2012 8:17 pm ] |
Post subject: | RE:Drawing a Chessboard using repetition |
To figure out where you went wrong, use this: drawbox (0+i,0,80,50, i % maxcolor) It will only draw the borders of the boxes, and each box will be a different colour. Edit: Also throw a delay in there, delay(1000) to watch how it draws it. |
Author: | blaffypoo [ Thu Jun 21, 2012 10:38 am ] |
Post subject: | RE:Drawing a Chessboard using repetition |
View.Set ("graphics:400;400,offscreenonly,nobuttonbar,nocursor") var Mx, My, Press : int := 0 loop cls Mouse.Where (Mx, My, Press) for i : 0 .. 7 for j : 0 .. 7 if Mx > i * 50 and Mx < i * 50 + 50 and My > j * 50 and My < j * 50 + 50 then Draw.FillBox (i * 50, j * 50, i * 50 + 50, j * 50 + 50, brightgreen) else Draw.FillBox (i * 50, j * 50, i * 50 + 50, j * 50 + 50, black) end if Draw.Box (i * 50, j * 50, i * 50 + 50, j * 50 + 50, white) end for end for delay (10) View.Update end loop |
Author: | SNIPERDUDE [ Fri Jun 22, 2012 11:49 am ] | ||
Post subject: | Re: Drawing a Chessboard using repetition | ||
Using mod might be simpler:
More on modulus: http://simple.wikipedia.org/wiki/Modular_arithmetic A useful thing you can do with mod is return whether a number is even (result = 0) or odd (result = 1) (number mod 2), which we did in the code above. |
Author: | blaffypoo [ Sat Jun 23, 2012 7:37 am ] |
Post subject: | RE:Drawing a Chessboard using repetition |
I added in a mouse over block to the board to show which square your mouse is on |