Created
February 10, 2020 17:13
-
-
Save mpj/a62cb7805039339f07594d860232eb9a to your computer and use it in GitHub Desktop.
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
<script | |
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.10.2/p5.min.js"></script> | |
<script> | |
class Particle { | |
constructor() { | |
this.position = createVector(20, 20) | |
this.radius = 15 | |
this.velocity = createVector(1, 1) | |
this.acceleration = createVector(0.0, 0.0) | |
} | |
render () { | |
const diameter = this.radius * 2 | |
ellipse( | |
this.position.x, | |
this.position.y, | |
diameter | |
) | |
} | |
update() { | |
this.position.add(this.velocity) | |
this.velocity.add(this.acceleration) | |
this.acceleration = | |
createVector(mouseX, mouseY) | |
.sub(this.position) | |
.mult(0.001) | |
this.velocity.limit(5) | |
} | |
} | |
let particle | |
function setup() { | |
createCanvas(400, 400) | |
background('#99ccff') | |
particle = new Particle() | |
} | |
function draw() { | |
background('#99ccff') | |
particle.render() | |
particle.update() | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment