Computer Science Canada Does anyone know how to randomize colours? |
Author: | lawyer_chelsea [ 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!! ![]() |
Author: | [Gandalf] [ Sat Oct 01, 2005 7:34 pm ] |
Post 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!! |
Author: | Cervantes [ Sat Oct 01, 2005 7:39 pm ] |
Post 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. |
Author: | Tony [ Sat Oct 01, 2005 11:11 pm ] |
Post 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... ![]() |
Author: | Hikaru79 [ Sun Oct 02, 2005 12:26 am ] | ||
Post subject: | |||
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 ![]() |
Author: | codemage [ Mon Oct 03, 2005 8:15 am ] |
Post subject: | |
Maybe you've already been doing it, but your absent-minded teacher forgot to install the Draw.Random.Colour(# of random colours) library. ![]() |
Author: | TokenHerbz [ Mon Oct 03, 2005 1:04 pm ] | ||
Post subject: | |||
i just do this for random colors
Then again, i seem to make more work the is nessesary... |
Author: | jamonathin [ Mon Oct 03, 2005 1:16 pm ] | ||
Post subject: | |||
Hikaru79 wrote:
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. |
Author: | Cervantes [ Mon Oct 03, 2005 4:43 pm ] | ||
Post subject: | |||
tokenherbz wrote: i just do this for random colors
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. ![]() |
Author: | TokenHerbz [ Tue Oct 04, 2005 1:22 am ] |
Post subject: | |
why's a function better then a proc? what are the differenc's? |
Author: | Tony [ Tue Oct 04, 2005 7:37 am ] |
Post subject: | |
a procedure is a function that doesn't return a value. brief comparison |
Author: | codemage [ Tue Oct 04, 2005 7:47 am ] |
Post 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. |
Author: | Tony [ Tue Oct 04, 2005 8:20 am ] |
Post 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. |
Author: | codemage [ Tue Oct 04, 2005 9:06 am ] | ||
Post subject: | |||
![]() 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.
|
Author: | beard0 [ Tue Oct 04, 2005 9:34 am ] | ||
Post 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
|
Author: | codemage [ Tue Oct 04, 2005 12:00 pm ] |
Post subject: | |
Just trying to show the difference between the two. The nuance makes more sense now, with the Freudian slip changed. Tony had written: You can't write tighter, better code with functions. ...either that, or my eyes (or mind) are going. Anyhow - as long as tokenherbz understands the difference... |
Author: | Tony [ Tue Oct 04, 2005 12:49 pm ] | ||||
Post subject: | |||||
what the? ![]() Anyways, functions are where it's at, since procedures are just functions that don't return a value.
vs
though ultimatly your main aim is for redability of your code. Just because you can compact your program down to twenty lines of nested chain functions, doesn't mean you have to. |
Author: | Mazer [ Tue Oct 04, 2005 2:57 pm ] |
Post subject: | |
codemage wrote: Because of that, you can write tighter, better code with functions - and they enable recursion.
I'm pretty sure recursion is possible with procedures. If anything, they just won't allow as much freedom as you get with recursive functions. |
Author: | [Gandalf] [ Tue Oct 04, 2005 3:16 pm ] | ||
Post subject: | |||
This is a very useless example of that:
But then it comes back to, procedures are functions. |