Skip to content

Instantly share code, notes, and snippets.

@giles-cholmondley-durston
Created April 26, 2013 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giles-cholmondley-durston/5468778 to your computer and use it in GitHub Desktop.
Save giles-cholmondley-durston/5468778 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}
//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: 2.2,
fill: "rgba(16,141,122,0.5455872)",
stroke: 0
}
var pinMod = 5;
var stiffness = 0.9856;
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.62;
var segments = 11;
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(120);
sim.draw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment