Skip to content

Instantly share code, notes, and snippets.

@mpj mpj/noc.html
Created Feb 10, 2020

Embed
What would you like to do?
<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
You can’t perform that action at this time.