Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created April 21, 2013 23:56
Show Gist options
  • Save enjalot/5431628 to your computer and use it in GitHub Desktop.
Save enjalot/5431628 to your computer and use it in GitHub Desktop.
verlet-js cloth
{"description":"verlet-js cloth","endpoint":"","display":"canvas","public":true,"require":[{"name":"verlet-js","url":"http://enjalot.github.io/verlet-js/verlet.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/kruPbcy.gif"}
//verlet-js: http://subprotocol.com/2013/04/18/introducing-verlet-js.html
var width = tributary.sw;
var height = tributary.sh;
//particle style
var pstyle = {
r: 3,
fill: "rgba(16,141,122,0.5455872)",
stroke: 0
}
var pinMod = 3;
var stiffness = 0.9;
var sim, cloth;
tributary.init = function(ctx) {
// simulation
sim = new VerletJS(width, height, tributary.canvas);
sim.friction = 1;
// entities
var min = Math.min(width,height)*0.5;
var segments = 20;
cloth = sim.cloth(new Vec2(width/2,height/3), min, min, segments, pinMod, stiffness);
console.log("sim", sim)
}
tributary.run = function(ctx, t) {
cloth.drawParticles = function(ctx, composite) {
var particles = cloth.particles;
for(var i = 0; i < particles.length; i++) {
var p = particles[i];
ctx.beginPath();
ctx.arc(p.pos.x, p.pos.y, pstyle.r, 0, 2*Math.PI);
ctx.fillStyle = pstyle.fill;
ctx.fill();
}
}
if(sim) {
sim.frame(16);
sim.draw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment