dark mode light mode Search Menu
Search

Experimental Code

Valerie Everett on Flickr

When working with program code, a great way to increase your understanding of how the program works — and programming in general — is to experiment, by changing values or logic to see what happens. It’s also a lot of fun.

In the last issue, we showed you how to download and install a virtual computer called Mini Micro. This time we’re going to Mini Micro with a program that is particularly good for experimental coding.

Fire up Mini Micro, use the edit command to open the code editor, and then carefully type in Listing 1. Click the Close & Run button at the top of the editor or exit the editor and type run at the prompt. It should make a simple kaleidoscope animation with a bunch of colored, pixelated stars swirling around. If you get any errors, edit again and double-check your typing, being sure to match the capitalization and punctuation shown.

Now comes the fun part. Try changing some of the values and running the program after each change to see what happens. For example, in line 5, try changing the shape from StarThin to HexagonThin, or perhaps SquareThinInv. (Use dir "/sys/pics/shapes" to see what your options are here.)

Line 7 determines how big the shapes are. Try changing the 0.5, which is the smallest shape, or the 1.2, which determines how quickly they grow bigger. Or even make up your own formula.

If you want a different number of shapes, change the 20 in line 3 and also in line 8. But perhaps most interesting of all is the rotation amount, which is determined by lines 17 and 20. What happens if you change -r to just r?

Experimenting with code is a fun way to explore a program and see what the computer can do. You can create your own unique animation, which no one else has ever seen. Happy coding.

Learn More

Experimental Coding

https://openprocessing.org/curation/74/