# The Art of Programming Math: Code Art Principles Part 2

Posted by Michelle Chandra on

Over the past year, I have been building upon a spirograph-ish program in Processing exploring different math concepts in conjunction with visual design! In Part 1 of this two-part blog series, I talked about my favorite visual design concepts in relationship to generative art.

In this "part 2", I will break down the different math concepts I have explored programmatically as an artist (listed in no particular order!) Coding tutorials (mainly by Dan Shiffman of Coding Train) linked to within each section!

### Sine Waves

Probably my favorite math concept to play with is the sine wave! There are so many ways you can insert a sine wave into your generative program. Here are two ways I have used sine waves in my generative art:

• why draw a shape or line with straight edges?! why not apply a sine wave instead to create curvy forms?!
• map values like color or size to a sine wave for beautiful rhythmic variation in your design, especially useful if your program creates repeating patterns

Here is a design that demos both of the above principles in one spirograph-ish design:

To get started with understanding sine waves, you will need to understand the properties of a waveform (the amplitude, and the frequency). For a breakdown, check out section 3.6 Oscillation Amplitude and Period in Dan Shiffman's Nature of Code.

### Probability

Probability is something I have played around with less, but is the backbone of my 10 print inspired patterns! Setting up conditions such that 40% of the time, you might draw one shape, and 60% of the time, draw another shape. Check out this Coding Train tutorial on the 10 Print algorithm for more info.

(The below print is now available in my shop! 50% of proceeds from the sale of this print will be donated to the Santa Cruz Community Foundation's Fire Response Fund.)

### Noise

Noise is a famous way to generate smooth and beautiful "random" numbers that you can plug into your program. If you have a hard coded value in your program, why not try generating values with noise instead and see what happens?

Dan Shiffman has a great breakdown on noise in Chapter 1 (section 1.6) of his Nature of Code book.

### Geometry: Shapes!

Sure, it's nice that Processing provides built-in functions to draw circles and rectangles, but at some point, you will want to branch out to draw polygons.

Here is a design drawn with the built-in circles provided in Processing:

A similar variation of that design drawn with a function that generates polygons instead (check out the Processing function for creating regular polygons here):

Also make sure to brush up on PVectors so you can branch out into making irregular shapes!

### Phyllotaxis Spiral

The famous spiral common to romanesco broccoli and sunflowers! At one point, I modulated a phyllotaxis spiral to lovely effect. Check out this Coding Train video for a breakdown on the lovely phyllotaxis spiral.

Here are a few additional math concepts you might want to explore (these are all concepts I have dabbled in with my spirograph-ish program, but that I don't necessarily have a great example for you, hopefully one day in the future!)