I need help !!!
Author |
Message |
japer88
|
Posted: Thu Jun 10, 2010 11:31 am Post subject: I need help !!! |
|
|
hey, can someone tell how to make a black and red checker board on turing
i have made a one that is black and white and one that is red and white. heres the code i used.
const SIZE := 50
var num_square : int
procedure Draw_square (row, colum : int)
drawfillbox (row * SIZE, colum * SIZE - 1, row * SIZE - SIZE, colum * SIZE - SIZE, ((row + colum * 7) mod 2) * black)
end Draw_square
procedure Checker_board
for row : 1 .. num_square
for colum : 1 .. num_square
Draw_square (row, colum)
end for
end for
end Checker_board
setscreen ("graphics:1000;650")
put " welcome to my cheaker board program "
put ""
put "how many square's would you like?? " ..
get num_square
Checker_board |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cezna
|
Posted: Thu Jun 10, 2010 11:44 am Post subject: RE:I need help !!! |
|
|
Just draw a red box in the area that the checker board pattern will be drawn over, or have colourback (red) at the top.
For future reference, look at the sticky topic at the top of the topic list for the help section, titled: "Don't post I need help topics" |
|
|
|
|
|
japer88
|
Posted: Thu Jun 10, 2010 11:51 am Post subject: Re: I need help !!! |
|
|
thx but i tryed that and it doesent work. |
|
|
|
|
|
USEC_OFFICER
|
Posted: Thu Jun 10, 2010 11:55 am Post subject: RE:I need help !!! |
|
|
Did you draw it before the other boxes, i.e. before the main loop/procedure? |
|
|
|
|
|
Cezna
|
Posted: Thu Jun 10, 2010 11:56 am Post subject: RE:I need help !!! |
|
|
You tried drawing a box, or changing the background colour? |
|
|
|
|
|
TheGuardian001
|
Posted: Thu Jun 10, 2010 12:06 pm Post subject: Re: I need help !!! |
|
|
Neither will work. The drawing code draws both black and white squares. The colour parameter:
((row + colum * 7) mod 2) * black
Will return either white or black depending on the row and column.
Instead of using math based colour choosing, you should just use an if statement, IE:
code: |
if (row_is_even and column_is_odd) or (row_is_odd and column_is_even)
draw_black_square
else if (row_is even and column_is_even) or (row_is_odd and column_is_odd)
draw_coloured_square
end if
|
|
|
|
|
|
|
chrisbrown
|
Posted: Thu Jun 10, 2010 12:31 pm Post subject: Re: I need help !!! |
|
|
TheGuardian001 @ Thu Jun 10, 2010 12:06 pm wrote: Instead of using math based colour choosing, you should just use an if statement
Or an array with 2 elements, one for each colour. Then draw(..., colours(column mod 2 xor row mod 2) ) |
|
|
|
|
|
japer88
|
Posted: Fri Jun 11, 2010 9:28 am Post subject: Re: I need help !!! |
|
|
wow sweet, but were would i put the if statment??? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
andrew.
|
Posted: Fri Jun 11, 2010 10:23 am Post subject: RE:I need help !!! |
|
|
In your draw square procedure. So it would be something like:
Turing: | proc drawSquare (row, column : int)
if row mod 2 = 0 xor column mod 2 = 0 then:
put "Draw a black square"
else
put "Draw a white square"
end if
end drawSquare |
Edit: I would like to say what the xor function is because it may be new to you. Basically "xor", or "exclusive or", works like this: it's either one or the other, but not both. So for example, if both are the same (ie. true and true, or false and false) it will return false. If they are different, it will return true. It's pretty much TheGuardian's method, but simplified with a different operator. I hope I explained it well enough. |
|
|
|
|
|
chrisbrown
|
Posted: Fri Jun 11, 2010 11:10 am Post subject: Re: RE:I need help !!! |
|
|
Actually, I was thinking something more along the lines of:
Turing: | var colours : array 0 .. 1 of string := init ("white", "black")
proc drawSquare (row, column : int)
put "Draw a " + colours(row mod 2 xor column mod 2) + " square"
end drawSquare |
A slightly different example:
Turing: | var colours : array 0 .. 1 of string := init ("white", "black")
for y : 1 .. 8
for x : 1 .. 8
put colours (x mod 2 xor y mod 2), " " ..
end for
put ""
put ""
end for |
I really don't like code repetition. |
|
|
|
|
|
TheGuardian001
|
Posted: Fri Jun 11, 2010 11:14 am Post subject: Re: I need help !!! |
|
|
using an array seems somewhat more complicated in this case. I wouldn't bother using an array for 2 colours, it's short enough to just throw it in a conditional.
Also, I'm pretty sure you can't specify a string as a colour parameter. You'd need to replace those with the number constants to draw a box. |
|
|
|
|
|
chrisbrown
|
Posted: Fri Jun 11, 2010 11:27 am Post subject: Re: I need help !!! |
|
|
TheGuardian001 @ Fri Jun 11, 2010 11:14 am wrote: using an array seems somewhat more complicated in this case. I wouldn't bother using an array for 2 colours, it's short enough to just throw it in a conditional.
True, it's pretty trivial; I just find functional solutions more elegant, and since he was using a formula to determine his colours, I just wanted to demonstrate a more abstracted solution.
TheGuardian001 @ Fri Jun 11, 2010 11:14 am wrote: Also, I'm pretty sure you can't specify a string as a colour parameter. You'd need to replace those with the number constants to draw a box.
Also true, but that's a simple change and the concept still holds. |
|
|
|
|
|
japer88
|
Posted: Mon Jun 14, 2010 11:36 am Post subject: Re: I need help !!! |
|
|
hey thx guys/girls
but could u maybe give me all of the code plz |
|
|
|
|
|
chrisbrown
|
Posted: Mon Jun 14, 2010 11:50 am Post subject: Re: I need help !!! |
|
|
japer88 @ Mon Jun 14, 2010 11:36 am wrote: could u maybe give me all of the code plz
Nope. You have more than enough information to figure it out. If you're still stuck, ask specific questions and we'll point you in the right direction, but you're not going to get free answers. |
|
|
|
|
|
|
|