Posted: Sat Oct 01, 2005 7:17 pm Post subject: Does anyone know how to randomize colours?
I have an assignment due and I can't for the life of me remember how to randomize colours. Could someone tell me the code or where I can find it?
It would be greatly appreciated!! Thanks!!
Sponsor Sponsor
[Gandalf]
Posted: Sat Oct 01, 2005 7:34 pm Post subject: (No subject)
You see, I would help you, but I don't really know the answer since I'm only doing a compsci "gig", while my real job is stand up comedy (how did you know?).
Read the rules. At least you've followed my advice and stopped overusing smilies. Good job!!
Cervantes
Posted: Sat Oct 01, 2005 7:39 pm Post subject: (No subject)
You don't "randomize the colours". Well, you could, but that would be a very inefficient way to do it. Instead, just generate a random number, using Rand.Int(), and then use that number as the colour number.
Tony
Posted: Sat Oct 01, 2005 11:11 pm Post subject: (No subject)
[Gandalf] wrote:
At least you've followed my advice and stopped overusing smilies. Good job!!
Now if you can only teach lawyer_chelsea to use more contrasting text colours...
Hikaru79
Posted: Sun Oct 02, 2005 12:26 am Post subject: (No subject)
code:
loop
Draw.FillOval (maxx div 2, maxy div 2, 50, 50, Rand.Int(1,256))
end loop
There is an INTENTIONAL BUG in there just because I don't want you copying and pasting this if its an assignment. If you understand what I did, you'll understand what to fix. Enjoy
codemage
Posted: Mon Oct 03, 2005 8:15 am Post subject: (No subject)
Maybe you've already been doing it, but your absent-minded teacher forgot to install the Draw.Random.Colour(# of random colours) library.
TokenHerbz
Posted: Mon Oct 03, 2005 1:04 pm Post subject: (No subject)
i just do this for random colors
code:
var color: int
loop
randint(color,1,255)
drawfilloval(20,20,20,20,color)
end loop
Then again, i seem to make more work the is nessesary...
jamonathin
Posted: Mon Oct 03, 2005 1:16 pm Post subject: (No subject)
Hikaru79 wrote:
code:
loop
Draw.FillOval (maxx div 2, maxy div 2, 50, 50, Rand.Int(1,256))
end loop
There is an INTENTIONAL BUG in there just because I don't want you copying and pasting this if its an assignment. If you understand what I did, you'll understand what to fix. Enjoy
Or, we could just use [Censored: Hikaru79 had his reasons] No more bug
tokenherbz wrote:
Then again, i seem to make more work the is nessesary...
For the most part, a lazy programmer makes a good programmer, code wise, not work ethic wise.
Sponsor Sponsor
Cervantes
Posted: Mon Oct 03, 2005 4:43 pm Post subject: (No subject)
tokenherbz wrote:
i just do this for random colors
code:
var color: int
loop
randint(color,1,255)
drawfilloval(20,20,20,20,color)
end loop
Then again, i seem to make more work the is nessesary...
Yeah, you did in this situation as well. Use functions over procedures. The better way to do this is seen in Hikaru's post.
TokenHerbz
Posted: Tue Oct 04, 2005 1:22 am Post subject: (No subject)
why's a function better then a proc?
what are the differenc's?
Tony
Posted: Tue Oct 04, 2005 7:37 am Post subject: (No subject)
a procedure is a function that doesn't return a value.
brief comparison
codemage
Posted: Tue Oct 04, 2005 7:47 am Post subject: (No subject)
That question was asked really recently in another thread... but I can't seem to find it.
Functions return a value, procs don't.
Because of that, you can write tighter, better code with functions - and they enable recursion.
Tony
Posted: Tue Oct 04, 2005 8:20 am Post subject: (No subject)
codemage wrote:
Because of that, you can write tighter, better code with functions - and they enable recursion.
It's the other way around. You can't write tighter, better code with procedures.
Functions do enable recursion though.
codemage
Posted: Tue Oct 04, 2005 9:06 am Post subject: (No subject)
I write tighter code with functions all the time.
Here's an elementary program which does the same thing with both a function and a procedure. The section which uses the function does in 1 line what it takes 2 lines for the procedure to do.
code:
var test1 : int := 5
function doubleit (num : int) : int
result num * 2
end doubleit
procedure doubleit2 (var num : int)
num := num * 2
end doubleit2
%Double & put a number with a function
put doubleit(test1)
%Double & put a number with a procedure
doubleit2(test1)
put test2
beard0
Posted: Tue Oct 04, 2005 9:34 am Post subject: (No subject)
codemage wrote:
you can write tighter, better code with functions
Tony wrote:
You can't write tighter, better code with procedures.
Tony is talking about a slight nuance, but saying the same thing in the end - in your example, you could just have well written
code:
put num * 2
(1 line) which, incidentally, would actually cause less instruction cycles in the processor than your function call, meaning that your use of a function has not actually made tighter code.