import org.cove.flade.*; var psystem:ParticleSystem = new ParticleSystem(); psystem.setKfr(0.1); //surface coeff of restitution psystem.setFriction(0.3); //surface friction psystem.setGravity(0, 0.5); var rows:Number = 4; var cols:Number = 20; var startX:Number = 235; var startY:Number = 20; var spacing:Number = 16; var currX:Number = startX; var currY:Number = startY; for (var n:Number = 0; n < rows; n++) { for (var j:Number = 0; j < cols; j++) { currY += Math.random(); currX += Math.random(); psystem.addParticle(currX, currY); currX += spacing; } currX = startX; currY += spacing; } // vertical constraints var lastPar = null; for (var n = 0; n < cols; n++) { for (var j = 0; j < rows; j++) { var i = cols * j + n; var par = psystem.particles[i]; if (lastPar != null) { psystem.addSpringConstraint(par, lastPar); } lastPar = par; } lastPar = null; } // horizontal constraints for (var i:Number = 0; i < psystem.particles.length; i++) { var par:Particle = psystem.particles[i]; if (lastPar != null && i % cols != 0) { psystem.addSpringConstraint(par, lastPar); } lastPar = par; } // surfaces var s0:LineSurface = new LineSurface(new Vector(100, 300), new Vector(400, 350)); psystem.addSurface(s0); var s1:LineSurface = new LineSurface(new Vector(400, 350), new Vector(700, 300)); psystem.addSurface(s1); for (var j:Number = 0; j < psystem.surfaces.length; j++) { psystem.surfaces[j].paint(); } this.onEnterFrame = function() { psystem.timeStep(); if (!isDrag) { psystem.particles[0].pin(); psystem.particles[19].pin(); } for (var k:Number = 0; k < psystem.constraints.length; k++) { psystem.constraints[k].paint(); } } var mouseListener:Object = new Object(); mouseListener.onMouseDown = function() { isDrag = true; } mouseListener.onMouseUp = function() { isDrag = false; } Mouse.addListener(mouseListener);