xxxxxxxxxx
64
class Turtle {
constructor(x,y){
this.pos = createVector(x,y);
this.color = 0;
this.heading = 0;
this.pen = true;
this.weight = 0;
}
setColor(c){
this.color = c;
}
setAngleMode(type){
angleMode(type);
}
setWeight(w){
this.weight = w;
}
penDown(){
this.pen = true;
}
penUp(){
this.pen = false;
}
rotate(a){
this.heading += a;
//this.draw();
}
moveForward(d){
var futureX = d * sin(this.heading) + this.pos.x;
var futureY = -d * cos(this.heading) + this.pos.y;
if(this.pen){
stroke(this.color);
strokeWeight(this.weight);
line(this.pos.x,this.pos.y,futureX,futureY);
}
this.pos.x = futureX;
this.pos.y = futureY;
//this.draw();
}
draw(){
var theta = this.heading;
push();
translate(this.pos.x,this.pos.y);
rotate(theta);
strokeWeight(1);
beginShape();
vertex(0, -5 * 2);
vertex(-5, 5 * 2);
vertex(5, 5 * 2);
endShape(CLOSE);
pop();
}
}