Skip to content

Instantly share code, notes, and snippets.

@jsoref
Forked from kmaher9/stick.js
Last active October 8, 2018 19:46
Show Gist options
  • Save jsoref/b49dfb4d3b84da783b26d8ee14163e8f to your computer and use it in GitHub Desktop.
Save jsoref/b49dfb4d3b84da783b26d8ee14163e8f to your computer and use it in GitHub Desktop.
function Stick() {
this.pos = createVector(width/2, height) // the position of the stick
this.vel = createVector() // the velocity of the stick
this.acc = createVector() // the acceleration rate of the stick
this.dna = new dna() // one strand of DNA to last the lifespan of the stick
this.applyForce = function(force) {
this.acc.add(force) // this allows for movement
}
this.update = function() {
this.applyForce(this.dna.genes[count]) // it takes its movement from its genes - ie fast, slow
this.vel.add(this.acc) // move in the given direction by the given amount
this.pos.add(this.vel) // update the position to align with the movement
this.acc.mult(0)
}
this.show = function() {
push()
noStroke()
fill(255, 150)
translate(this.pos.x, this.pos.y) // actually move
rotate(this.vel.heading())
rectMode(CENTER)
rect(0, 0, 25, 5)
pop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment