<processingjs>
String// All Examples Written by Casey Reas and Ben Fry // unless otherwise stated. // center point float centerX = 0, centerY = 0; float radius = 45, rotAngle = -90; float accelX, accelY; float springing = .0085, damping = .98; //corner nodes int nodes = 5; float nodeStartX[] = new float[nodes]; float nodeStartY[] = new float[nodes]; float[]nodeX = new float[nodes]; float[]nodeY = new float[nodes]; float[] fontList angle = PFont.list()new float[nodes]; float[]frequency = new float[nodes];println(fontList) // soft-body dynamics float organicConstant = 1; void setup(){{ size(200,200); //center shape in window centerX = width/2; centerY = height/2; // iniitalize frequencies for corner nodes for (int i=0; i<nodes; i++){ frequency[i] = random(5, 12); noLoop} noStroke();font = createFont smooth(); frameRate(30); } void draw() { //fade background fill("@font-face" 0, 32100);textFont rect(font0, 320,width, height); drawShape(); moveShape();
}
void drawdrawShape(){ // calculate node starting locations for (int i=0; i<nodes; i++){ background nodeStartX[i] = centerX+cos(radians(rotAngle))*radius; nodeStartY[i] = centerY+sin(radians(255rotAngle))*radius; String t rotAngle += "P360.js"0/nodes; float tw = textWidth} // draw polygon curveTightness(torganicConstant); fill(0255); beginShape(); textfor (int i=0; i<nodes; i++){ curveVertex(tnodeX[i], nodeY[i]); } for (widthint i=0; i<nodes-tw1; i++)/2{ curveVertex(nodeX[i], nodeY[i]); } endShape(height+32)/2CLOSE);
}
void moveShape() {
//move center point
float deltaX = mouseX-centerX;
float deltaY = mouseY-centerY;
// create springing effect
deltaX *= springing;
deltaY *= springing;
accelX += deltaX;
accelY += deltaY;
// move predator's center
centerX += accelX;
centerY += accelY;
// slow down springing
accelX *= damping;
accelY *= damping;
// change curve tightness
organicConstant = 1-((abs(accelX)+abs(accelY))*.1);
//move nodes
for (int i=0; i<nodes; i++){
nodeX[i] = nodeStartX[i]+sin(radians(angle[i]))*(accelX*2);
nodeY[i] = nodeStartY[i]+sin(radians(angle[i]))*(accelY*2);
angle[i]+=frequency[i];
}
</processingjs>