This sketch is created with an older version of Processing,
and doesn't work on browsers anymore.
xxxxxxxxxx
// rose curve
// http://en.wikipedia.org/wiki/Rose_(mathematics)
void setup()
{
size(400, 400, P2D);
smooth();
noStroke();
colorMode(HSB);
frameRate(30);
background(0);
}
int d = 7;
int n = 1;
float theta = 0;
float speed = 0.03;
int radius = 10;
void draw()
{
int halfWidth = width/2;
int halfHeight = height/2;
float k = (float)n/(float)d;
float r = cos( k * theta );
float x = r * cos(theta) * halfWidth/2;
float y = r * sin(theta) * halfWidth/2;
float h = lerp(0, 255, (frameCount % 600) / 600.0f);
fill(h, 200, 200, 64);
ellipse(x+halfWidth, y+halfHeight, radius, radius);
theta += speed;
}
void keyPressed()
{
if(key == 'd')
{
d++;
if( d>7) d-=7;
background(0);
}
else if( key == 'n' )
{
n++;
if( n>7 ) n-=7;
background(0);
}
else if( key == CODED)
{
if( keyCode == UP )
{
speed += 0.01;
if( speed>0.5 ) speed = 0.5;
}
else if( keyCode == DOWN )
{
speed -= 0.01;
if( speed<0.01 ) speed = 0.01;
}
}
}