Functions that function

--Originally published at Ricardo's Blog

First of all, that title tho…

tim-and-eric-mind-blown.gif

Functions work as a big command but simplified. Like, if you want to draw things, instead of typing the loops iver and over again, you can just define a word or something, then make that function do the loops for you, and only type the word you setted up. Instead of doing what it’s show here, repeating commands.

functions1

In the example, if I don’t want to type the Loop to make a square everytime I want a square. I create a function that will make a square, by just typing “square”, it’ll do it.

functions0

Where it says “size” you can either type a number, so the square size will be a default with the value you specified, or type the word “size” inside the parenthesis, so when you enter the function you can choose the size of the square.

functions2

Then I made a ton of squares appear, with random colors, in random places and random sizes. For this, I made another loop, and in this loop I started by creating this sort of a workspace that only goes from -200 to 200 in the X scale, and from -200 to 20 on the Y scale. Then I told my turtle to lift the pen up, and asked it to move to a random place in X and a random place in Y, aske it to put the pen down and choose a random color to change to, using the color list that is above in the program. After that, Fred will change  its color and make a square, with a random size that is specified to go from either 10 or 200 pixels.

And I guess that is it about functions (And a little extra).

Thank you for reading.

Byeeeeee.