
-----------------------------------
lawyer_chelsea
Sat Oct 01, 2005 7:17 pm

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!! :D 

-----------------------------------
[Gandalf]
Sat Oct 01, 2005 7:34 pm


-----------------------------------
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
Sat Oct 01, 2005 7:39 pm


-----------------------------------
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
Sat Oct 01, 2005 11:11 pm


-----------------------------------
"]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... :lol:

-----------------------------------
Hikaru79
Sun Oct 02, 2005 12:26 am


-----------------------------------
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
Mon Oct 03, 2005 8:15 am


-----------------------------------
Maybe you've already been doing it, but your absent-minded teacher forgot to install the Draw.Random.Colour(# of random colours) library.

 :wink:

-----------------------------------
TokenHerbz
Mon Oct 03, 2005 1:04 pm


-----------------------------------
i just do this for random colors


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
Mon Oct 03, 2005 1:16 pm


-----------------------------------
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 :P
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.

-----------------------------------
Cervantes
Mon Oct 03, 2005 4:43 pm


-----------------------------------
i just do this for random colors


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
Tue Oct 04, 2005 1:22 am


-----------------------------------
why's a function better then a proc?

what are the differenc's?

-----------------------------------
Tony
Tue Oct 04, 2005 7:37 am


-----------------------------------
a procedure is a function that doesn't return a value.
[url=http://www.compsci.ca/v2/viewtopic.php?t=407]brief comparison

-----------------------------------
codemage
Tue Oct 04, 2005 7:47 am


-----------------------------------
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
Tue Oct 04, 2005 8:20 am


-----------------------------------
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. :wink: 

Functions do enable recursion though.

-----------------------------------
codemage
Tue Oct 04, 2005 9:06 am


-----------------------------------
:shock:  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.


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
Tue Oct 04, 2005 9:34 am


-----------------------------------
you can write tighter, better code with functions
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 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.

-----------------------------------
codemage
Tue Oct 04, 2005 12:00 pm


-----------------------------------
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...

-----------------------------------
Tony
Tue Oct 04, 2005 12:49 pm


-----------------------------------
what the? :shock: I think somebody is playing a joke on me there.

Anyways, functions are where it's at, since procedures are just functions that don't return a value.


procedure(var x)
procedure(var y)
call(x,y)

vs

call(function(x), function(y))


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.

-----------------------------------
Mazer
Tue Oct 04, 2005 2:57 pm


-----------------------------------
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.

-----------------------------------
[Gandalf]
Tue Oct 04, 2005 3:16 pm


-----------------------------------
This is a very useless example of that:
var product, numA, numB, cnt : int := 0

proc multiply (numA, numB : int)
    product += numA
    cnt += 1
    if cnt ~= numB then
        multiply (numA, numB)
    end if
end multiply

multiply (5, 5)
put product

But then it comes back to, procedures are functions.
