xxxxxxxxxx
let vines = [];
let ysteps = 25;
let xsteps = 10;
let xvar = 10;
let minDist = 100;
function setup() {
new Canvas(500, 500);
world.gravity.y = 6;
vines.push(new vine(25));
vines.push(new vine(50));
vines.push(new vine(75));
vines.push(new vine(100));
vines.push(new vine(125));
vines.push(new vine(150));
vines.push(new vine(175));
vines.push(new vine(200));
vines.push(new vine(225));
vines.push(new vine(250));
vines.push(new vine(275));
vines.push(new vine(300));
vines.push(new vine(350));
vines.push(new vine(400));
vines.push(new vine(450));
}
function draw() {
background(255);
for(var vine of vines){
vine.update();
}
}
class vine{
constructor(x){
this.points = [];
this.jump = windowHeight/ysteps;
var y= this.jump;
this.points.push(new Sprite(x,y,2,'s'))
this.points[0].mass=100;
for(var i = 1; i < ysteps; i++){
this.points.push(new Sprite(x, y, 2));
this.points[i].mass=1;
var j = new DistanceJoint(this.points[i-1],this.points[i]);
j.springiness = 0.0001; // try changing this!
//j.damping = 1;
y+=this.jump;
}
}
update(){
for(var i =1; i< this.points.length; i++){
var d = dist(mouseX, mouseY, this.points[i].x, this.points[i].y);
if(d < minDist ){
var mPos = createVector(mouseX,mouseY)
var pPos = createVector(this.points[i].x,this.points[i].y)
let diff = p5.Vector.sub(pPos, mPos);
diff.normalize();
diff.div(d);
diff.mult(500);
diff.limit(7);
this.points[i].attractTo(mouse, -diff.mag());
}
}
}
}