Skip to content

Instantly share code, notes, and snippets.

@mpj
Created February 10, 2020 17:13
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 mpj/a62cb7805039339f07594d860232eb9a to your computer and use it in GitHub Desktop.
Save mpj/a62cb7805039339f07594d860232eb9a to your computer and use it in GitHub Desktop.
<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