Tag Archives: circles

Perlin Star

14 Dec

This star is similar to the aster from my Stars and Asters tutorial. Here, I’m stretching the outer points using Perlin noise.

Normally, I would draw the outer point using

   vertex( cos( a * i) * orad, 
           sin( a * i) * orad);

But instead I’m using

   vertex( cos( a * i) * (orad+noise(i,0,millis()*mutateSpeed)*dev), 
           sin( a * i) * (orad+noise(i,1,millis()*mutateSpeed)*dev));

Let’s break this down. orad is the radius of the vertex, from the center of the star.
I’m adding a value to it which is noise(something)*dev. noise returns a value from 0 to 1, so I’m using dev to specify how much I want to mutate the point by.

Noise is like a sponge that is being sampled in 3d space. You pass it x,y,z parameters, and you get the value of the sponge at that point in space. By carefully controlling what x,y,z coordinates you pass, you can get different effects. Here, I’m passing

(i,0,millis()*mutateSpeed) to mutate the X coordinate and
(i,1,millis()*mutateSpeed) to mutate the Y coordinate.

x = i
This corresponds to the point of the star, and insures I get a unique noise grid coordinate for each point in the star. As long as the positions in noise space are separated by at least 1, you’ll get very different values.

y = 0 or 1
Again, this is used to get a unique noise grid cell for each coordinate.

z = millis()*mutateSpeed
This is a slowly increasing number which causes the mutation effect. If I passed a constant here, the star wouldn’t move.