/** * Fuzzy philosophers clumped * Program by Raphael Rouvinov-Kats * * click to move the 'fuzz' (iron shavings)! * * Any following updates will make shavings lines not points and add magnetic fields * */ var startingFuzzAmount = 5000; var fuzzStrokeWeight = 1; var clickingCreatesFuzz = false; var shakeAmount = 15; var magnetDistance = 40; var drawPhilosopher = function() { noStroke(); // face skin fill(255, 239, 189); beginShape(); vertex(200,320); bezierVertex(200, 330, 280, 270, 300, 200); bezierVertex(300, 200, 315, 150, 310, 100); bezierVertex(310, 100, 315, 15, 200, 10); bezierVertex(200, 10, 140, 10, 100, 50); bezierVertex(100, 50, 50, 115, 100, 215); bezierVertex(120, 250, 88, 233, 178, 320); bezierVertex(178, 320, 198, 325, 200, 320); endShape(); // ear skin beginShape(); // left vertex(80, 140); bezierVertex(40, 110, 65, 250, 97, 209); endShape(); beginShape(); // right vertex(310, 135); bezierVertex(325, 120, 325, 200, 296, 210); endShape(); // eye whites fill(255, 255, 255); ellipse(150, 140, 40, 20); ellipse(250, 140, 40, 20); // eye color fill(12, 0, 179); ellipse(150, 140, 15, 15); ellipse(250, 140, 15, 15); // eyebrows noFill(); stroke(199, 160, 82); strokeWeight(5); bezier(130, 130, 140, 120, 140, 120, 170, 130); bezier(270, 130, 260, 120, 255, 120, 230, 130); // lips bezier(150, 250, 160, 250, 230, 249, 250, 250); // nose bezier(200, 150, 220, 190, 239, 190, 200, 200); }; var fuzz = []; for(var f = 0; f < startingFuzzAmount; f++) { fuzz[f] = [random(0, 400), random(0, 400), 0]; // [x, y, selected] } var draw = function() { background(255, 255, 255); // mouseheld actions if(mouseIsPressed) { // shake if(mouseX >= 350 && mouseX <= 390 && mouseY >= 10 && mouseY <= 30) { for(var f = 0; f < fuzz.length; f++) { fuzz[f][0] = min(399, max(0, fuzz[f][0] + random(-shakeAmount, shakeAmount))); fuzz[f][1] = min(399, max(0, fuzz[f][1] + random(-shakeAmount, shakeAmount))); } } // make fuzz else if(clickingCreatesFuzz) { fuzz.push([mouseX, mouseY]); } } drawPhilosopher(); // draw fuzz for(var f = 0; f < fuzz.length; f++) { stroke(0, 0, 0); strokeWeight(fuzzStrokeWeight); point(fuzz[f][0], fuzz[f][1]); } // draw shake button noStroke(); fill(255, 0, 0, 100); if(mouseX >= 350 && mouseX <= 390 && mouseY >= 10 && mouseY <= 30) { fill(255, 0, 0, 150); if(mouseIsPressed) { fill(255, 0, 0, 200); } } rect(350, 10, 40, 20); fill(0, 0, 0); text("shake!", 351, 25); // display fuzz amount text("fuzz: " + fuzz.length, 10, 380); }; var mousePressed = function() { for(var i = 0; i < fuzz.length; i++) { var f = fuzz[i]; if(dist(f[0], f[1], mouseX, mouseY) < magnetDistance) { f[2] = 1; } } }; var mouseReleased = function() { for(var i = 0; i < fuzz.length; i++) { var f = fuzz[i]; f[2] = 0; } }; var mouseOut = function() { mouseReleased(); }; var mouseDragged = function() { mousePressed(); var dx = mouseX - pmouseX; var dy = mouseY - pmouseY; for(var i = 0; i < fuzz.length; i++) { var f = fuzz[i]; if(f[2] === 1) { f[0] += dx; f[1] += dy; f[0] += 0.01 * (mouseX - f[0]); f[1] += 0.01 * (mouseY - f[1]); f[0] = max(0, min(399, f[0])); f[1] = max(0, min(399, f[1])); } if(random(0, 1) < 0.5) { f[2] = 0; } } };