Shimmia Zoobie Yinyo SnakeCharmer Resonata Squared Rosaly Dragoria Curlicor Dragoric Curlicue Fractal Quadrina Toroidia Net of Indra Trochor

An Introduction to Programming, Using Processing. Part 1: Why Program?

Filed under: Uncategorized — ferrous @ 14:19

Processing is a language created by Ben Fry and Casey Reas of MIT, designed to make computer programming accessible to people who might imagine it will always be beyond their grasp. Processing makes it easy to create beautiful, interactive graphics.

The principles of computer programming are surprisingly simple and powerful. They also provide an easy way in to understanding some very important concepts in mathematics and science, by making them into things you can play around with. Messing about with stuff is one of the ways that people learn best.

For scientists and engineers, it is crucial to be able to solve equations, to apply the methods of mathematics to practical or theoretical problems. For the rest of us, that might be less important but there is still great value in having an intuitive understanding of the way the world works. Often, this is much easier if we have a handle on the mathematics expressing scientific laws.

This is only one of the reasons almost everyone should be exposed to the fundamentals of programming. Another reason is that there is huge practical value in even quite simple programming. Most web sites, for example, are built using one or more scripting languages. In general this makes them far easier to maintain, but since many people imagine that programming at all is beyond them, they get put off trying to make fundamental changes.

The biggest reason for everyone to have a go at programming is also the simplest: Programming can be tremendous fun, and you’ll never know how much until you try it. It’s a toy, a tool, and a tool for making toys.

To give you an idea of how easy it is to get started with Processing, and a taste of what beautiful and seemingly complex forms can arise from a tiny amount of mathematics, I have included below a very short program to draw a fractal – a mathematical form which shows similar structures at many different scales, in this case spirals of spirals of spirals. The comments within the program should give you some clues what is going on, but do not worry if you are not able to follow all of the steps in it, especially if you have never programmed before. Soon, it will all make perfect sense!

I would encourage you to download Processing from now and install it following the simple instructions there. Then paste in the code below and hit ‘run’.

// Double slashes indicate this line is a comment that Processing can ignore.
// Comments in your code make it easier to follow.
// The first thing to do is declare all the variables we will use.
float x, y, seed=420, f; // Each seed value gives a different fractal.
double df=0, ddf=TWO_PI/seed;
int i=0;
void setup(){ // ‘setup’ is called just once, when the program is run.
size(200,200); // Tell Processing how big a window it should use.
void draw(){ // ‘draw’ is called every time the program draws a frame.
// We need to reset most of the variables every frame.
background(255); // This fills in the frame with a white background.
while (i<9000){ // Repeat the next block 9000 times.
ddf+=0.00000005; // So ddf changes every frame, causing animation to happen.

Feel free to play around with this code, setting the variable named 'seed' to different numbers, changing the size of the window and so on. You might also like to start looking at some of the examples that come with Processing. Next time we will start looking in more detail in what's going on here.

Leave a Reply