xxxxxxxxxx
// Modified for sableRaph's weekly creative challenge
// #WCCChallenge
// https://www.twitch.tv/sableraph
// more stuff at - art.rchu.cc
const mag2Vec = (unit, mag) => p5.Vector.mult(unit, mag);
const mousePos = () => createVector(mouseX - width/2, (mouseY - height/2))
const numSprings = 60;
let blob;
let closestLocked;
let rad;
function setup(){
createCanvas(windowWidth, windowHeight);
const start = createVector(0,0);
rad = min(width, height)/4;
blob = new Blob(start, rad, numSprings);
}
function draw(){
translate(width/2, height/2);
background(217, 231, 231);
blob.render();
const mouse = mousePos();
if (mouseIsPressed) {
const spring = closestLocked;
const springPos = closestLocked.position;
const proj = p5.Vector.dot(mouse, springPos) / springPos.mag();
const len = max(proj, rad/16);
spring.position = p5.Vector.mult(spring.unit, -len);
} else {
//Show closest point
const spring = blob.closestSpring(mouse);
const springPos = spring.position;
fill(169, 185, 202);
strokeWeight(1);
blob.update();
circle(springPos.x, springPos.y, 10);
}
}
function mousePressed(){
const mouse = mousePos();
closestLocked = blob.closestSpring(mouse);
}
function mouseReleased(){
closestLocked = null;
}