Random Colours
Author |
Message |
cam
|
Posted: Sat Nov 11, 2006 2:49 pm Post subject: Random Colours |
|
|
I want to do 3 colours switching from red to black to green. I want to do this as a variable. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
richcash
|
Posted: Sat Nov 11, 2006 3:11 pm Post subject: (No subject) |
|
|
Something like this?
code: | 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.
code: | 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

|
|
|
|
 |
TokenHerbz

|
Posted: Sun Nov 12, 2006 5:49 am Post subject: (No subject) |
|
|
zylum, would those colors work with whatdotcolor red, black, green?
perhaps later he would want to use a different variety of colors. |
|
|
|
|
 |
richcash
|
Posted: Sun Nov 12, 2006 12:10 pm Post subject: (No subject) |
|
|
Oops, I must've deleted too much when I took out my drawing stuff. Here :
switching orderly :
code: | 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 :
code: | 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
|
Posted: Sun Nov 12, 2006 1:43 pm Post subject: (No subject) |
|
|
alright thx |
|
|
|
|
 |
zylum

|
Posted: Sun Nov 12, 2006 4:44 pm Post subject: (No subject) |
|
|
nah, dont use my way
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  |
|
|
|
|
 |
|
|