[ Launch: verlet-js cloth ] 5468778 by garyjbowles
[ Launch: verlet-js cloth ] 5431628 by enjalot
[ Launch: verlet-js ] 5431559 by enjalot
-
-
Save giles-cholmondley-durston/5468778 to your computer and use it in GitHub Desktop.
verlet-js cloth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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