syrup.

Noise waves using Perlin noise.


NOTE: This piece displays with an extremely low framerate, I'm currently trying to find a way around this.

The program is setup by creating a number of Flow objects (the Perlin noise waves) and adding them to an ArrayList. There will be as many Flow objects as it takes to fill the screen from top to bottom. In each tick of the draw loop, each wave in the ArrayList will be updated and drawn on the screen.

A Flow object holds an origin Y co-ordinate (a waves vertical position on the screen), a random y-offset value (for use in the Perlin noise function), a PShape object (which holds the vertices of the shape of the wave and gets updated in every tick of the draw loop), and finally a colour which is chosen randomly from an array holding colour palette values.

When a Flow object is updated, first the wave PShape is created and given its fill colour, an x-offset value is created to be used along with the y-offset value to plug into the Perlin noise function. Each wave starts off as a straight horizontal line at the specified Y origin point where a loop will then run through each vertex that makes up the wave (with a horizontal step of 10) and offset each point by a Perlin noise value using the x-offset and y-offset values. Since Perlin noise values will always return between 0 and 1, the value is multiplied by 400 to make the transformation visible. Once the new y co-ordinate has been calculated, the vertex is added to the wave PShape and the x-offset value is incremented. Once all vertices have been transformed, the y-offset value is also incremented and two more points are added to the shape which stretches it to the bottom of the screen, allowing it to appear filled in. The wave PShape is drawn to the screen and the update is complete.