이 공식을 기본으로 이런 저런 수치를 변수로 바꾸어 줌으로 다양한 모양을 만들어 낸다는 것이다.
import peasy.*;
PeasyCam cam;
void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 800);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
noFill();
stroke(255);
strokeWeight(2);
}
float t;
void draw() {
background(0);
//translate(width/2, height/2);
beginShape();
//add some vertices
for (float theta =0; theta <= 2 * PI; theta += 0.01) {
float rad = r(theta,
3, //mouseX / 100.0, //a
2, // mouseY / 100.0, //b
6, //m
1, //mouseX / 100.0, //n1
sin(t) * 1 + 1, //mouseX / 100.0, //n2
cos(t) * 1 + 1//mouseY / 100.0 //n3
);
float x = rad * cos(theta) * 50;
float y = rad * sin(theta) * 50;
vertex(x, y);
}
endShape();
//2nd
translate(width/4, height/4);
beginShape();
for (float theta =0; theta <= 2 * PI; theta += 0.01) {
float rad = r(theta,
3, //mouseX / 100.0, //a
2, // mouseY / 100.0, //b
6, //m
1, //mouseX / 100.0, //n1
sin(t) * 1 + 1, //mouseX / 100.0, //n2
cos(t) * 1 + 1//mouseY / 100.0 //n3
);
float x = rad * cos(theta) * 50;
float y = rad * sin(theta) * 50;
vertex(x, y);
}
endShape();
//last
translate(-300, -height/2);
beginShape();
for (float theta =0; theta <= 2 * PI; theta += 0.01) {
float rad = r(theta,
3, //mouseX / 100.0, //a
2, // mouseY / 100.0, //b
6, //m
0.5, //mouseX / 100.0, //n1
sin(t) * 0.5 + 0.1, //mouseX / 100.0, //n2
cos(t) * 0.5 + 0.1//mouseY / 100.0 //n3
);
float x = rad * cos(theta) * 50;
float y = rad * sin(theta) * 50;
vertex(x, y);
}
endShape();
//add
t += 0.1;
}
//r
float r(float theta, float a, float b, float m, float n1, float n2, float n3) {
return pow(pow(abs(cos(m * theta / 4.0) / a), n2) +
pow(abs(sin(m * theta / 4.0) / b), n3), -1.0 / n1);
}