
-----------------------------------
cam
Sat Nov 11, 2006 2:49 pm

Random Colours
-----------------------------------
I want to do 3 colours switching from red to black to green. I want to do this as a variable.

-----------------------------------
richcash
Sat Nov 11, 2006 3:11 pm


-----------------------------------
Something like this?
var c : array 1 .. 3 of int := init (red, black, green)
var clr : int
loop
     clr := Rand.Int (c, 1, 3)
end loop
That's if you want it random, as the post title suggests.

This could be for swithching in an orderly fashion.
var c : array 1 .. 3 := init (red, black, green)
var n := 0
var clr : int
loop
    n += 1
    clr := c (n mod 3 + 1)
end loop

-----------------------------------
zylum
Sun Nov 12, 2006 2:52 am


-----------------------------------
both your code examples dont work  :? 

to choose one of those three colours at random you could do:

round (Rand.Int (1, 3) * 2.2)

 :lol:

-----------------------------------
TokenHerbz
Sun Nov 12, 2006 5:49 am


-----------------------------------
zylum, would those colors work with whatdotcolor red, black, green?

perhaps later he would want to use a different variety of colors.

-----------------------------------
richcash
Sun Nov 12, 2006 12:10 pm


-----------------------------------
Oops, I must've deleted too much when I took out my drawing stuff. Here :
switching orderly :
var c : array 1 .. 3 of int := init (red, black, green)
var n := 0
var clr : int
loop
    n += 1
    clr := c (n mod 3 + 1)
    Draw.FillOval (50, 50, 15, 15, clr)
    delay (200)
end loop

randomly :
var c : array 1 .. 3 of int := init (red, black, green)
var clr : int
loop
    clr := c (Rand.Int (1, 3))
    Draw.FillOval (50, 50, 15, 15, clr)
    delay (200)
end loop

Use zylum's way for simplicity, but use mine if you want to change the colours later on (or come up with your formula!).

-----------------------------------
cam
Sun Nov 12, 2006 1:43 pm


-----------------------------------
alright thx

-----------------------------------
zylum
Sun Nov 12, 2006 4:44 pm


-----------------------------------
nah, dont use my way  :lol: 

the code is not self explanitory and you cant extend it to use other colours. i was just fooling around. unless you are trying to ubfuscate your code then by all means use it  :wink:
