-
-
Save jsoref/b49dfb4d3b84da783b26d8ee14163e8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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