I want to rotate my snowflake with mouseX, here is the full code;
float angle = 0;
float cx;
float cy;
void setup() {
size(640, 480);
cx = 50;
cy = height/2;
noLoop();
}
void draw() {
background(255);
stroke(0);
//kochCurve(243,4);
translate(100,-100);
kochSnowflake(360,4);
}
void kochCurve(float lngth, int level) {
float newlngth;
if (level == 0){
forward(lngth);
return;
}
else {
newlngth = lngth/3.0;
kochCurve(newlngth,level-1);
rotation(-60);
kochCurve(newlngth,level-1);
rotation(120);
kochCurve(newlngth,level-1);
rotation(-60);
kochCurve(newlngth,level-1);
}
}
void forward(float amount) {
float newX = cx + cos(radians(angle)) * amount;
float newY = cy + sin(radians(angle)) * amount;
line(cx, cy, newX, newY);
fill(0);
cx = newX;
cy = newY;
}
void rotation(float degree) {
angle = (angle + degree);
}
void kochSnowflake(float lngth, int level) {
kochCurve(lngth,level);
rotation(120);
kochCurve(lngth,level);
rotation(120);
kochCurve(lngth,level);
}