Skip to content

Instantly share code, notes, and snippets.

@ybakos
Created May 2, 2019 20:51
Show Gist options
  • Select an option

  • Save ybakos/f8a88da3cf382ba707c20277aa38ef71 to your computer and use it in GitHub Desktop.

Select an option

Save ybakos/f8a88da3cf382ba707c20277aa38ef71 to your computer and use it in GitHub Desktop.
class Rocket {
PVector position;
PVector velocity;
PVector acceleration;
float size;
Rocket(PVector location) {
acceleration = new PVector();
velocity = new PVector();
position = location.get();
size = 4;
}
void applyForce(PVector f) {
acceleration.add(f);
}
void update() {
velocity.add(acceleration);
position.add(velocity);
acceleration.mult(0);
}
void display() {
float theta = velocity.heading2D() + PI/2;
fill(200, 100);
stroke(0);
pushMatrix();
translate(position.x, position.y);
rotate(theta);
// Thrusters
rectMode(CENTER);
fill(0);
rect(-size/2, size*2, size/2, size);
rect(size/2, size*2, size/2, size);
// Fuselage
fill(175);
beginShape(TRIANGLES);
vertex(0, -size*2);
vertex(-size, size*2);
vertex(size, size*2);
endShape();
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment