xxxxxxxxxx
53
const { VerletPhysics2D, VerletParticle2D, VerletSpring2D } = toxi.physics2d;
const { GravityBehavior } = toxi.physics2d.behaviors;
const { Vec2D, Rect } = toxi.geom;
let physics;
let particles = [];
let springs = [];
let pannasan =[];
let balltype = false;
function setup() {
createCanvas(620, 364);
physics = new VerletPhysics2D();
let bounds = new Rect(0, 0, width, height);
physics.setWorldBounds(bounds);
pannasan.push(new Panna(width/2,height/2,25));
}
function mousePressed(){
clear();
pannasan = [];
particles = [];
springs = [];
if(balltype){
balltype = false; //Ring
pannasan.push(new Panna(width/2,height/2,25));
}
else{
balltype = true; //Spring
pannasan.push(new Panna(width/2,height/2,10));
}
}
function draw() {
background(0);
physics.update();
pannasan[0].show();
if (mouseIsPressed) {
particles[0].lock();
particles[0].x = mouseX;
particles[0].y = mouseY;
particles[0].unlock();
}
}