Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Colours and Boxes
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
stef_ios




PostPosted: Tue Apr 11, 2006 8:02 am   Post subject: Colours and Boxes

Hey. So I have yet another code that needs fixing. This time, there are boxes with selections and when you pick a box it does what the box says. There are five selections: red, blue, green, exit, and clear. If your pick one of the colours, the oval should turn that colour, but if you pick clear it goes blank, and exit will stop the program. So here is my code.
code:

procedure gui
    locatexy (110,285)
    put "RED"
    locatexy (110,200)
    put "BLUE"
    locatexy (110,75)
    put "GREEN"
    locatexy (290,75)
    put "EXIT"
    locatexy (500,75)
    put "CLEAR"
    drawbox (50,275,175,375,red)   %Red
    drawbox (50,150,175,250,red)   %Blue
    drawbox (50,25,175,125,red)    %Green
    drawbox (400,25,175,125,red)   %Exit
    drawbox (600,25,175,125,red)   %Clear
    drawoval (450,250,25,25,black) %Oval   
end gui

var x, y, button: int
gui
loop
    mousewhere (x,y,button)
    if button = 1 and 50 <= x and x <= 175 and 275 <= y and y <= 375 then
        drawfill (450,250,red,black)
    end if
    if button = 1 and 50 <= x and x <= 175 and 150 <= y and y <= 250 then
        drawfill (450,250,blue,black)
    end if   
    if button = 1 and 50 <= x and x <= 175 and 25 <= y and y <= 125 then
        drawfill (450,250,green,black)
    end if   
    if button = 1 and 500 <= x and x <= 175 and 75 <=y and y <= 125 then
        drawfill (450,250,white,black)
    end if
    exit when button = 1 and 290 <= x and x <= 175 and 75 <= y and y <= 125
end loop


I have a problem with the exit box, and the clear box. I can't place them properly and I can't get them to work. Could someone help me out with these two lines.
code:

exit when button = 1 and 290 <= x and x <= 175 and 75 <= y and y <= 125

code:

if button = 1 and 500 <= x and x <= 175 and 75 <=y and y <= 125 then
        drawfill (450,250,white,black)
    end if


Thanks!
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Tue Apr 11, 2006 9:19 am   Post subject: (No subject)

code:
drawfillbox(x,y,x1,y1,color)
Legolas




PostPosted: Tue Apr 11, 2006 9:29 am   Post subject: (No subject)

First of all for simplicity I would change your code around. I would make the color boxes a solid color, this way you could use whatdotcolor instead to change the oval in one if statement. For example:

code:

loop
mousewhere (x, y, button)
if button = 1 then
drawfill (450, 250, whatdotcolor (x, y), black)
end if
end loop


To do this just make your color boxes drawfillbox so that the box is a solid color. It will also eliminate the need for a clear box because just clicking off those boxes will clear the circle.

The problem with your exit box code was you were attempting to have it exit when x is larger then 290 and smaller then 175 which is an impossibility and will never happen. Just change the signs on your x statements.

code:

exit when button = 1 and 290 >= x and x >= 175 and 75 <= y and y <= 125



As for placement just play around with the values untill it looks how you want it.
code:
stef_ios




PostPosted: Tue Apr 11, 2006 2:20 pm   Post subject: (No subject)

Great. Thanks alot. But how do I get the clear button to work? I can't seem to get that piece of code right. I have:
code:

if button = 1 and 600 <= x and x <= 175 and 25 <= y and y <= 125 then
        drawfill (450,250,white,black)

This piece of code is to clear, and my clear box has the coordinates of:
code:

 drawbox (600,25,175,125,red)


If someone could tell me why it doesn't work that would be great! Thanks!
TokenHerbz




PostPosted: Tue Apr 11, 2006 2:27 pm   Post subject: (No subject)

you can use cls to clear the SCREEN, but i recommend making a WHITE square, perhaps with a black background.

code:

if soinso then
    %%draw white
    drawfilloval(x,y,x+s,y+s,white)
    %%add a border (to see the box?)
    drawoval(x,y,x+s,y+s,black)
end if


I don't completly get what your asking though, hope i helped.
stef_ios




PostPosted: Tue Apr 11, 2006 2:53 pm   Post subject: (No subject)

Well I have a clear box, and when you click it, it should clear the little oval (LED). So I need my code fixed so that the clear button works because for some reason it doesn't.
TokenHerbz




PostPosted: Tue Apr 11, 2006 3:12 pm   Post subject: (No subject)

can you post your current code?
stef_ios




PostPosted: Tue Apr 11, 2006 4:32 pm   Post subject: (No subject)

Here is my current code.

code:

procedure gui
    locatexy (110,250)
    put "RED"
    locatexy (110,150)
    put "BLUE"
    locatexy (110,45)
    put "GREEN"
    locatexy (275,75)
    put "EXIT"
    locatexy (500,75)
    put "CLEAR"
    drawbox (50,200,175,295,red)   %Red
    drawbox (50,100,175,200,red)   %Blue
    drawbox (50,0,175,100,red)     %Green
    drawbox (400,25,175,125,red)   %Exit
    drawbox (600,25,175,125,red)   %Clear
    drawoval (450,250,25,25,black) %Oval   
end gui

var x, y, button: int
gui
loop
    mousewhere (x,y,button)
    if button = 1 and 50 <= x and x <= 175 and 200 <= y and y <= 295 then
        drawfill (450,250,red,black)
    end if
    if button = 1 and 50 <= x and x <= 175 and 100 <= y and y <= 200 then
        drawfill (450,250,blue,black)
    end if   
    if button = 1 and 50 <= x and x <= 175 and 0 <= y and y <= 100 then
        drawfill (450,250,green,black)
    end if   
    if button = 1 and 600 <= x and x <= 175 and 25 <= y and y <= 125 then
        drawfill (450,250,white,black)
    end if
    exit when button = 1 and 290 >= x and x >= 175 and 75 <= y and y <= 125   
end loop

Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Tue Apr 11, 2006 4:44 pm   Post subject: (No subject)

Here's your problem:
code:
  if button = 1 and 600 <= x and x <= 175 and 25 <= y and y <= 125 then

this condition can never be fulfilled because x can never be greater than 600 while at the same time be less than 175.

you need to change it to this:
code:
  if button = 1 and 600 >= x and x >= 400 and 25 <= y and y <= 125 then

i changed the values around because they didn't apply to the coordinates of your button.
Clayton




PostPosted: Wed Apr 12, 2006 7:04 am   Post subject: (No subject)

Quote:

[turing]
loop
mousewhere (x,y,button)
if button = 1 and 50 <= x and x <= 175 and 200 <= y and y <= 295 then
drawfill (450,250,red,black)
end if
if button = 1 and 50 <= x and x <= 175 and 100 <= y and y <= 200 then
drawfill (450,250,blue,black)
end if
if button = 1 and 50 <= x and x <= 175 and 0 <= y and y <= 100 then
drawfill (450,250,green,black)
end if
if button = 1 and 600 <= x and x <= 175 and 25 <= y and y <= 125 then
drawfill (450,250,white,black)
end if
exit when button = 1 and 290 >= x and x >= 175 and 75 <= y and y <= 125
end loop
[/turing]

ok wat youve got going on here is a problem, as stated above, your if and exit conditions are a problem, read above to find out what you did wrong, its not hard to fix
TokenHerbz




PostPosted: Wed Apr 12, 2006 4:59 pm   Post subject: (No subject)

superfreak, i hope a mod reads what you just posted, its absolutly useless information to which your wasting time for readers, and i think your doing it ALOT lately,... cut it out.

HellblazerX fixed the problem and that should of been it, and to make my post usfull i have an idea:

stef_ios: why not make it so when you exit, it will close the window?

code:

%%to make the window
var game_window: int
game_window := Open.Window("Graphics: 500;500")

%%to close the window
Window.Close(game_window)


Here it is as a whole...
code:

var game_window : int
game_window := Window.Open ("graphics: max;max")

procedure gui
    locatexy (110, 250)
    put "RED"
    locatexy (110, 150)
    put "BLUE"
    locatexy (110, 45)
    put "GREEN"
    locatexy (275, 75)
    put "EXIT"
    locatexy (500, 75)
    put "CLEAR"
    drawbox (50, 200, 175, 295, red) %Red
    drawbox (50, 100, 175, 200, red) %Blue
    drawbox (50, 0, 175, 100, red) %Green
    drawbox (400, 25, 175, 125, red) %Exit
    drawbox (600, 25, 175, 125, red) %Clear
    drawoval (450, 250, 25, 25, black) %Oval
end gui

var x, y, button : int
gui
loop
    mousewhere (x, y, button)
    if button = 1 and 50 <= x and x <= 175 and 200 <= y and y <= 295 then
        drawfill (450, 250, red, black)
    elsif button = 1 and 50 <= x and x <= 175 and 100 <= y and y <= 200 then
        drawfill (450, 250, blue, black)
    elsif button = 1 and 50 <= x and x <= 175 and 0 <= y and y <= 100 then
        drawfill (450, 250, green, black)
    elsif button = 1 and 600 >= x and x >= 400 and 25 <= y and y <= 125 then
        drawfill (450, 250, white, black)
    elsif button = 1 and 290 >= x and x >= 175 and 75 <= y and y <= 125 then
        exit
    end if
end loop
Window.Close (game_window)


SmileSmileSmileSmileSmileSmileSmileSmileSmileSmileSmileSmile
MysticVegeta




PostPosted: Wed Apr 12, 2006 5:24 pm   Post subject: (No subject)

TokenHerbz wrote:
superfreak, i hope a mod reads what you just posted, its absolutly useless information to which your wasting time for readers, and i think your doing it ALOT lately,... cut it out.

I think SuperFreak makes a valid point because he lets the person figure it out instead of posting the code! I would actually haev to say to you, Watch out for the mods because we DO NOT do the assignments completely, which I guess you have forgetton, can some mod please remove the code/edit the code so its in bits.
TokenHerbz




PostPosted: Wed Apr 12, 2006 5:25 pm   Post subject: (No subject)

AWs!

i thought we was in the same side :S

I leave with this then, let bigons be bigons, and post what ever you want cause its all good Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: