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

Username:   Password: 
 RegisterRegister   
 pixel graphics program (swapping)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slimshadyy




PostPosted: Mon Apr 22, 2013 8:04 pm   Post subject: pixel graphics program (swapping)

What is it you are trying to achieve?

create 4 filled circles side by side with these colors: red, green, yellow, blue (from left to right). when the user presses g or G, the colors should start to cycle and continue even if the user doesn't press anything. modify this so that a random color will appear at the end and the other colors move.

Starting: Red Green Yellow Blue

1st change Green Yellow Blue 1st random color

2nd change Yellow Blue 1st random color 2nd random color


What is the problem you are having?

i don't know how to put the random colors in the cycle. i know you have to use randint but where in the program do i put it.


Describe what you have tried to solve this problem

i have wrote the rest of the program excluding the random colors part.


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
startStop := 0

elsif
input = 's' or input = 'S' then
run := 0
startStop := 1

end if
end if
if run = 1 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
exit when input = 'x' or input = 'X'
end loop
put "Goodbye"

Turing:






Please specify what version of Turing you are using

4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Mon Apr 22, 2013 8:16 pm   Post subject: RE:pixel graphics program (swapping)

Lets say you wanted a variable to be a random number from 1 to 10.

var x : int

x := Rand.Int (1, 10)
slimshadyy




PostPosted: Mon Apr 22, 2013 9:07 pm   Post subject: Re: pixel graphics program (swapping)

var c1 : int := 12
var c2 : int := 2
var c3 : int := 14
var c4 : int := 9
var c5 : int
randint (c5, 1, 255)
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
startStop := 0

elsif
input = 's' or input = 'S' then
run := 0
startStop := 1

end if
end if
if run = 1 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)
drawfilloval (500, 100, 20, 20, 31)

delay (3000)
swap := c1
c1 := c2
c2 := c3
c3 := c4
c4 := c5
c5 := swap
end if
exit when input = 'x' or input = 'X'
end loop
put "Goodbye"

how do i make the random color change to a new color after each cycle and not just the same random color throughout the whole program?
Raknarg




PostPosted: Tue Apr 23, 2013 1:04 pm   Post subject: RE:pixel graphics program (swapping)

Change it during the loop
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  [ 4 Posts ]
Jump to:   


Style:  
Search: