Computer Science Canada pixel graphics program (swapping) |
Author: | slimshadyy [ Mon Apr 22, 2013 6:55 pm ] | ||
Post subject: | pixel graphics program (swapping) | ||
What is it you are trying to achieve? create 4 filled circles side by side with these colours: red, green, yellow, blue (from left to right). if the user presses g or G the colours should start to cycle and continue even if the user doesnt press anything. if the user presses S or s, then stop cycling. if the user presses x or X, then exit the program. hint: you will need a variable startStop to keep track of whether the colours should cycle or not. What is the problem you are having? i cant get the program to stop cycling when i press s or S. i dont really know how to do the startStop thing. Describe what you have tried to solve this problem i tried to write the code for it but i think its wrong. nothing shows up on the run screen. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) var c1 : int := 12 var c2 : int := 2 var c3 : int := 14 var c4 : int := 9 var swap : int var input : string (1) := ' ' var run : int := 0 var startStop : int := 0 loop if hasch then getch (input) if input = 'g' or input = 'G' then run := 1 if input = 's' or input = 'S' then startStop := 0 else run := 0 startStop := 1 end if end if if run = 1 and startStop = 0 then drawfilloval (100, 100, 20, 20, c1) drawfilloval (200, 100, 20, 20, c2) drawfilloval (300, 100, 20, 20, c3) drawfilloval (400, 100, 20, 20, c4) delay (500) swap := c1 c1 := c2 c2 := c3 c3 := c4 c4 := swap end if end if exit when input = 'x' or input = 'X' end loop put "Goodbye"
Please specify what version of Turing you are using 4.1.1 |
Author: | Raknarg [ Mon Apr 22, 2013 6:59 pm ] | ||
Post subject: | RE:pixel graphics program (swapping) | ||
How is that second if statement ever supposed to run? |
Author: | slimshadyy [ Mon Apr 22, 2013 7:02 pm ] |
Post subject: | Re: pixel graphics program (swapping) |
oh true. so do i put all as one statement? |
Author: | Raknarg [ Mon Apr 22, 2013 7:04 pm ] |
Post subject: | RE:pixel graphics program (swapping) |
Sure. They're different conditions for the same event, basically. If you press g, do this. Otherwise, if you press s, do this. Otherwise, if it's anything else, do this. |
Author: | slimshadyy [ Mon Apr 22, 2013 7:06 pm ] |
Post subject: | Re: pixel graphics program (swapping) |
but they are 2 different variables. if you press g or s, it can never be both. only one or the other. so how would u put it in one statement. |
Author: | Raknarg [ Mon Apr 22, 2013 7:13 pm ] | ||
Post subject: | RE:pixel graphics program (swapping) | ||
Were you ever taught elsif before? If not I'll give you a breakdown:
This is how it will run. First, it will see if condition a is true (could be if a certain key is pressed, or a variable is a vertain value). If it's true, it'ss do something. Otherwise, if b is true, it'll do something else. Otherwise, if c is true, it'll do something else. Otherwise, it'll do_d(). The order matters. If both a and b are true, it will do whatever is in a, and then exit the if. You can't do two conditions in an if statement. This is what you're looking for. |
Author: | slimshadyy [ Mon Apr 22, 2013 7:21 pm ] |
Post subject: | Re: pixel graphics program (swapping) |
okay thanks i figured it out ![]() |