Code
void setup(){
size(400,400);
smooth();
}
float offset = 200;
float nPoints = 300;
void draw(){
stroke(30,190,190);
background(255);
float scl = ((float)mouseY/(float)height)*TWO_PI;
fill(255,70,0);
translate(offset,offset);
scale(scl,scl);
float a = mouseX * 0.01; // 1.1;
float b = sin(millis()*0.001); // 0.66666;
float f = mouseY * 0.015; //1.0
beginShape(POLYGON);
for (int i=0; i<nPoints; i++){
float t = TWO_PI*(float)i/nPoints;
// Parametric Cartesian equation:
// x = (a2 + f2sin2(t))cos(t)/a
// y = (a2 - 2f2 + f2sin2(t))sin(t)/b
float x = (a*a + f*f*sin(t)*sin(t)) * cos(t)/a;
float y = (a*a + 2*f*f+ f*f*sin(t)*sin(t)) * sin(t)/b;
vertex(x,y);
}
endShape();
}
void mousePressed(){
// println(mouseY+" "+r);
}
040 -- Explicit Curves: (Due W October 25)
Statement:Exercises 40 and 41 treat the topics of explicit and implicit curves, respectively. For this exercise, select a 2D curve 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). (For some simple parametric curves to get started with, consider 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.
Connect the shape's internal parameters to the mouse in such a way as to develop a satisfying exploration of the graphic and dynamic possibilities of this shape. You might wish to use a shaping function to change how the curve responds to the mouse. In converting mathematical notations into code, make sure you familiarize yourself with the exp(), pow(), abs(), sqrt(), sq(), log(), and other mathematical functions available in Java. Also, don't forget your trigonometric identities.
Please be sure to use a 2D curve. Later this semester we will use your applet for an in-class exercise involving PDF/DXF output and the computer-controlled laser cutter.