Skip to content

Instantly share code, notes, and snippets.

@enjalot
Last active October 23, 2016 02:23
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 enjalot/7ef9d8458bbf82a7327597dfe72bcbfa to your computer and use it in GitHub Desktop.
Save enjalot/7ef9d8458bbf82a7327597dfe72bcbfa to your computer and use it in GitHub Desktop.
p5: force multiplier
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.4/p5.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
var width = 960;
var height = 500;
var radius = 50;
var dt = 0.03
var particles = [];
function setup() {
console.log("size")
createCanvas(960, 500);
}
function draw() {
background(0,0,0,205)
ellipse(mouseX, mouseY, 80, 80);
var p;
for(var i = 0; i < particles.length; i++) {
p = particles[i]
ellipse(p.x, p.y, 50, 50);
p.x += p.vx * dt
p.y += p.vy * dt
}
}
// generate stuff over time
var period = 850
function loop() {
particles.push({
x: 100,
y: 200,
vx: 40 + Math.random() * 40,
vy: -50 + Math.random() * 100
})
//if(Math.random() < 0.4) particles.splice(0,1)
setInterval(loop, period);
}
setInterval(loop, period);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment