xxxxxxxxxx
36
function setup() {
createCanvas(400, 400);
ship = new Ship()
;}
function draw() {
background(0);
ship.render();
// keyPressed();
}
function keyPressed(){
if (keyCode == 68){
ship.turn(0.1);
} else if (keyCode == 65){
ship.turn(-0.1)
}
}
function Ship(){
this.pos = createVector(width/2, height/2);
this.r=10;
this.heading = PI/2;
this.render = function(){
translate(this.pos.x, this.pos.y)
rotate(this.heading)
noFill();
stroke(255);
triangle(-this.r, this.r, this.r, this.r, 0, -this.r)
}
this.turn = function(angle){
this.heading += angle;
}
}