## Want to keep learning?

This content is taken from the Monash University's online course, Creative Coding. Join the course to learn more.
3.10

The w3_03 sketch

# Where do rules come from?

If rule-based art is concerned with creating rules that generate a work, how do you devise rules that make interesting art?

This is an fascinating question, perhaps it is the question for this course. Some rules seem deceptively simple and it isn’t always clear where the interest they generate comes from.

One approach to developing your own rule-based systems is to start with something very simple and make small, incremental changes to it. At each change, observe the ‘generative complexity’ of what is produced. As you explore this space of possibilities you can pursue the interesting options while discarding those that are less so.

Earlier we discussed the sin() function and looked at a simple sketch with oscillating circles moving horizontally at different speeds (w3_02). We could use this sketch as a starting point to develop a rule-based generative art system.

After some brief experimentation, here’s what we came up with:

• A series of oscillating points move horizontally across the screen. The points divide the screen evenly.
• If a point and its next neighbour point are closer than some fixed distance, draw a line between the points.

If we want a computer to generate our art, we’ll need to convert these rules into computer code. To do this, we need to interpret our rules or ‘algorithm’ in a way that gives us an unambiguous set of instructions that can be executed by the computer.

We’ve already implemented the first part of our algorithm in the w3_02 sketch, we just need to change the circles to points, then implement the distance rule.

Open the w3_03 sketch. This version implements the rules as code. Run the sketch and observe the results. Some points to note:

• The sketch makes use of the entire screen: size(displayWidth, displayHeight);. If you’d prefer working with a smaller display window comment out this line and uncomment size(500, 500); directly below.
• Change the values of num and distanceMargin and observe the results. Make sure you understand what these two variables are doing.
• If you want to see the moving points, uncomment the stroke(255); statement within the draw() function.
• As with the other sketches this week, you can change the background colour using the mouse.
• Note the use of many of the functions we’ve covered this week: sin(), cos(), radians(), dist() and map();

One final thing to be aware of: the draw() function does not call background() at all. What effect is this having on the drawing? Uncomment the line ‘background(128);’ and run the sketch.

Another way to devise rules is to start with some physical process using simplification and abstraction to devise a set of rules. We’ll look at this approach next.