Code
void setup(){
size(400,400);
}
float a,x,y;
float mw = 0;
float mh = 0;
float drift = -5;
float speed = .1;
int wh = 0;
int res = 50;
boolean piriform = false;
boolean bubble = false;
float[][] points = new float[res][2];
void loop(){
background(255);
if(piriform==true){
wh++;
noStroke();
beginShape(POLYGON);
for(int i=0;i<res;i++){
a = i*TWO_PI/res;
x = 2*wh*(1+sin(a));
y = wh*cos(a)*(1+sin(a));
fill(150,200,255,y+x);
points[i][0] = mouseX+x;
points[i][1] = mouseY+y;
vertex(mouseX+x,mouseY+y);
mw = max(x+mouseX,mw);
mh = max(y+mouseY,mh);
}
endShape();
}
if(bubble==true){
beginShape(POLYGON);
for(int i=0;i<res;i++){
a = PI/2-i*TWO_PI/res;
x = -wh/2+mw+cos(a)*wh;
y = -wh/2+mh+sin(a)*wh;
points[i][0] += (x-points[i][0])*speed;
points[i][1] += (y-points[i][1])*speed;
vertex(points[i][0],points[i][1]+drift);
}
endShape();
drift -= 1;
}
}
void mousePressed(){
wh = 0;
mw = 0;
mh = 0;
drift = -5;
piriform = true;
bubble = false;
}
void mouseReleased(){
drift = -5;
piriform = false;
bubble = true;
}
020 -- Rendering A Curve: Curve-Generating Equations
Statement:All assignments numbered 02x are due Thursday 10/7.
In a 400x400 pixel applet: Select one curve (yes, just one) from the Mathworld curves site. I recommend selecting curves whose equations take the standard explicit form y = f(x), or curves which take the parametric form y = f(t), x = g(t). See this example for some code that deals with Polar curves in the form r = f(theta). (Curves with implicit-form equations may be too difficult! For some easy starters, try the Spirograph-like roulette curves.) Create a simple interaction in which the mouseX and mouseY are used to continuously govern two parameters of the curve. You may also want to look at these interactive applets for some more inspiration.
Advanced students: experiment with rendering 3D surfaces, if you wish.