Skip to content

Instantly share code, notes, and snippets.

@kmaher9
Created September 9, 2018 00:04
Show Gist options
  • Save kmaher9/cdb5665de768ffe947aee48b5dd67c94 to your computer and use it in GitHub Desktop.
Save kmaher9/cdb5665de768ffe947aee48b5dd67c94 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 it's movement from it's 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 allign 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