Computer Science Canada

How To Make Loop on This Program

Author:  darkage43 [ Mon May 02, 2011 10:53 am ]
Post subject:  How To Make Loop on This Program

What is it you are trying to achieve?
I'm trying to make my flashing text loop.

What is the problem you are having?
I can't seem to make my text loop and whenever I do, my quit button doesn't work.


Describe what you have tried to solve this problem
I tried adding loop but whenever I do add it, it cancels out my quit button.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
import GUI

var winID := Window.Open ("graphics:500;500")

put "Enter your message here please: "..
var message:string
get message
put " "
put "You'll be able to quit once the program is done going through all possible colours in Turing"

var font1:int
font1 := Font.New ("times:50")

for integer:0..16
colour (integer)
Font.Draw (message, 200, 250, font1, integer)
delay (250)
end for

var quitBtn : int := GUI.CreateButton (250, 10, 0, "Quit", GUI.Quit)

loop
exit when GUI.ProcessEvent
end loop

Window.Close (winID)

Turing:


<Add your code here>



Please specify what version of Turing you are using
I'm using version 4.1.1

Author:  munt4life [ Mon May 02, 2011 5:48 pm ]
Post subject:  Re: How To Make Loop on This Program

put it inside the loop then.

Author:  Raknarg [ Mon May 02, 2011 5:51 pm ]
Post subject:  RE:How To Make Loop on This Program

It's because of the amount of time you have to click the button. You have four windows of opportunity every second to click the button, each about a millisecond long.
Instead of a delay, I would use a counter that goes up to 250, then changes the colour and goes back down to zero. That way it'll always be checking the button. I just tried it, and it works.

Author:  darkage43 [ Mon May 02, 2011 7:13 pm ]
Post subject:  RE:How To Make Loop on This Program

So how would I use this counter? I can't find it on the turing reference.

Author:  Raknarg [ Mon May 02, 2011 7:24 pm ]
Post subject:  RE:How To Make Loop on This Program

Use a variable and set it to int. Every time the loop passes, you add one to it.
You would set the counter up like so:

counter := counter + 1
if counter = 250 then
integer := integer + 1
counter := 0
end if

Author:  darkage43 [ Mon May 02, 2011 7:33 pm ]
Post subject:  RE:How To Make Loop on This Program

Like this?

import GUI

var winID := Window.Open ("graphics:500;500")
var counter: int:=0

put "Enter your message here please: "..
var message:string
get message
put " "
put "You'll be able to quit once the program is done going through all possible colours in Turing"

var font1:int
font1 := Font.New ("times:50")
for integer:0..255
colour (integer)
Font.Draw (message, 200, 250, font1, integer)
counter := counter + 1
if counter = 250 then
int := int + 1
counter := 0
end if
end for
var quitBtn : int := GUI.CreateButton (250, 10, 0, "Quit", GUI.Quit)

loop
exit when GUI.ProcessEvent
end loop

Window.Close (winID)

Author:  darkage43 [ Mon May 02, 2011 7:35 pm ]
Post subject:  RE:How To Make Loop on This Program

I really don't understand this.

Author:  Raknarg [ Mon May 02, 2011 7:43 pm ]
Post subject:  RE:How To Make Loop on This Program

Explain to me exactly what you want it to do.

Author:  darkage43 [ Mon May 02, 2011 7:47 pm ]
Post subject:  RE:How To Make Loop on This Program

Oh! I see, thanks a lot Raknarg, but how do I make the program cycle through a specific set of colours?

Author:  Raknarg [ Mon May 02, 2011 7:52 pm ]
Post subject:  RE:How To Make Loop on This Program

Umm... Well, unless there's colors in order already, you'll just have to use a lot of ifs. Like if you wanted to have red, blue and yellow, you could do something like
Turing:

for i : 1 .. 3
     if i = 1 then
          color := blue
     elsif i = 2 then
          color := red
     elsif i = 3 then
          color := yellow
     end if
end for

However, colors 32 to 80 are pretty nice, I would just cycle through those.

Author:  Raknarg [ Mon May 02, 2011 7:55 pm ]
Post subject:  RE:How To Make Loop on This Program

If that helped, there's always tipping with karma to show appreciation Wink

Author:  darkage43 [ Mon May 02, 2011 7:57 pm ]
Post subject:  RE:How To Make Loop on This Program

So if I wanted colors from 1 to 16 I would put

for i :1..16
colour (integer)
Font.Draw (message, 350, 425, font1, integer)
counter += 1
if counter = 200 then
integer += 1
counter := 0
end if
end for

Author:  darkage43 [ Mon May 02, 2011 7:59 pm ]
Post subject:  RE:How To Make Loop on This Program

Actually never mind I got it to cycle through the colours that I want. One final question though. How do I slow down the cycling of the colours?

Author:  Raknarg [ Mon May 02, 2011 8:01 pm ]
Post subject:  RE:How To Make Loop on This Program

Change the counter length, right? Thats the thing making the change.

Author:  darkage43 [ Mon May 02, 2011 8:11 pm ]
Post subject:  RE:How To Make Loop on This Program

Which ones the counter length? I tried changing all of the counters but they are still flashing too fast.

Author:  Raknarg [ Mon May 02, 2011 8:13 pm ]
Post subject:  RE:How To Make Loop on This Program

if counter = 200
Try changing that.

Author:  darkage43 [ Mon May 02, 2011 8:26 pm ]
Post subject:  RE:How To Make Loop on This Program

I changed the counter=200 to a much greater value but the message is still flashing at the same rate as before.

Author:  Raknarg [ Mon May 02, 2011 8:28 pm ]
Post subject:  RE:How To Make Loop on This Program

Show me your new code.

Author:  darkage43 [ Mon May 02, 2011 8:29 pm ]
Post subject:  RE:How To Make Loop on This Program

%Adds the ability to use GUI in this program
import GUI

%Declaring all variables used in the program
var counter : int := 0
var integer := 1
var winID := Window.Open ("graphics:800;800")
var message : string
var font1 : int

put "Enter your message here please: " ..
get message
put " "
put "Click quit to exit the program"

font1 := Font.New ("times:50")

loop
for i:0..16
colour (integer)
Font.Draw (message, 350, 425, font1, i)
counter += 1
if counter = 1000 then
integer += 1
counter := 0
end if

var quitBtn : int := GUI.CreateButton (375, 100, 0, "Quit", GUI.Quit)
end for
exit when GUI.ProcessEvent
end loop

Window.Close (winID)

Author:  Raknarg [ Mon May 02, 2011 8:35 pm ]
Post subject:  RE:How To Make Loop on This Program

Its because you set the color of Font.Draw to i, not integer. Why do you have that for loop?

Author:  darkage43 [ Mon May 02, 2011 8:40 pm ]
Post subject:  RE:How To Make Loop on This Program

If I change Font.Draw into integer, the program wouldn't flash the text in the specified colours.

Author:  Raknarg [ Mon May 02, 2011 8:41 pm ]
Post subject:  RE:How To Make Loop on This Program

Well, then do the same thing you did with the counter. When it hits 17, reset it.

Author:  darkage43 [ Mon May 02, 2011 8:49 pm ]
Post subject:  RE:How To Make Loop on This Program

How do I reset it? I'm really new to turing.

Author:  Raknarg [ Mon May 02, 2011 8:52 pm ]
Post subject:  RE:How To Make Loop on This Program

lol, ok then Razz
So you do the same thing you did with the counter. When counter = 200, you set it back to zero. What you can do with integer is set it to zero after it reaches 17. That way you'll only get the colors 1 - 16 instead of it continuing on.

Author:  darkage43 [ Mon May 02, 2011 9:01 pm ]
Post subject:  RE:How To Make Loop on This Program

How do I set my counter to 0 once it hits 17?

Author:  darkage43 [ Mon May 02, 2011 10:45 pm ]
Post subject:  RE:How To Make Loop on This Program

K I've finally figured it out. Thank you so much Raknarg for being so helpful.

Author:  Raknarg [ Tue May 03, 2011 9:19 am ]
Post subject:  RE:How To Make Loop on This Program

No problem.


: