xxxxxxxxxx
/*
Fractal-Based Pattern 2: Elastic Circle
By: Justin J.
6/11/2017
Point the mouse inside the circle, preferably near the edge, drag the mouse in towards the center, then release!
*/
float mix;
float r;
boolean grabbed;
void setup(){
size(1000,800);
mix = 0.0;
r = 250;
grabbed = false;
}
void draw(){
background(20);
noFill();
elasticCircle(width/2,height/2,250,mix);
if (grabbed == false && mix >= 0.0){
mix = constrain(mix*=0.975,0,1.0);
}
else if (grabbed == false && mix < 0.0){
mix = constrain(mix*=0.975,-1.0,0);
}
instructions();
}
void elasticCircle(float x, float y, float radius,float mix_){
int resolution = 210;
stroke(lerpColor(#DE00AC,#00A4FF,abs(mix)));
beginShape();
for (int i = 0; i < resolution; i++){
float theta = map(i,0,resolution-2,0,TWO_PI);
float amp = radius*map(cos(8*theta),-1,1,0,mix_);
curveVertex(x+(radius-amp)*cos(theta),y+(radius-amp)*sin(theta));
}
endShape(CLOSE);
if (mix_ > 0.1){
elasticCircle(x,y,radius,mix_*0.9);
}
}
void mousePressed(){
grabbed = true;
}
void mouseReleased(){
grabbed = false;
}
void mouseDragged(){
if (grabbed == true){
mix = pinch();
}
}
float pinch(){
return norm(dist(mouseX,mouseY,width/2,height/2),r,0);
}
void instructions(){
fill(255);
textSize(12);
textAlign(RIGHT);
text("Instructions:\n*Point the mouse inside the circle.\n*Drag in towards the center.\n*Release",width-20,height-80);
}