Creators on a Mazey Loop

This week we took a closer look at one of the most useful commands in javascript – the for loop!.    We first used a for loop to first generate a grid of circles:

Next, we made a slight change to get the for loop to display rectangles and circles in form that would make any Mayo supporter teary-eyed:

Finally, we used the for loop to recreate a classic 1980’s basic program to javascript.  This uses a trick of picking random forward or backward slashes to automatically generate a maze:

We then spent the rest of the class experimenting with different colors, animations, strokes, framerates, probabilities, etc to get some really interesting effects (often by accident!).

For anyone that’s interested, the classic program is below and it was amazing in that it did it in a single line on a commodore 64!:

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

There is a whole book out there on this line of code!  It’s worth flicking through as it shows lots of other maze variants that are possible with some tweaking.

For a good explanation of the for loop – head over the W3C Schools Javascript site – it does quite a good job on explaining it, or else this tutorial from digitalocean is also good.

As usual, all the code is up on github!  Happy creating!!

2 thoughts on “Creators on a Mazey Loop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s