fix movement angle

This commit is contained in:
lee2sman 2021-01-29 13:38:58 -05:00
parent 4a9a70fc06
commit 08463c49b1
1 changed files with 69 additions and 63 deletions

View File

@ -1,77 +1,83 @@
let angle,x,y,drawing=true;
function setup(){
createCanvas(windowWidth,windowHeight); //canvas is size of window
resetDefaults();
turtle();
displayTurtle();
let angle,
x,
y,
drawing = true,
turtleC;
function setup() {
createCanvas(windowWidth, windowHeight); //canvas is size of window
resetDefaults();
turtle();
displayTurtle();
}
function resetDefaults(){
function resetDefaults() {
angleMode(DEGREES); //instead of p5.js's default RADIANS
angleMode(DEGREES); //instead of p5.js's default RADIANS
angle = 180; //facing up
x = width / 2; //start turtle in center
y = height / 2;
}
function forward(d, startx = x, starty = y, _angle = 360 - angle) {
let newX = startx + d * sin(_angle);
let newY = starty + d * cos(_angle);
angle=0; //facing up
x = width/2; //start turtle in center
y = height/2;
if (drawing) {
line(startx, starty, newX, newY);
}
x = newX;
y = newY;
}
function back(d, startx = x, starty = y, _angle = 180 - angle) {
let newX = startx + d * sin(_angle);
let newY = starty + d * cos(_angle);
if (drawing) {
line(startx, starty, newX, newY);
}
x = newX;
y = newY;
print(x, y);
}
function left(_angle) {
angle -= _angle;
}
function right(_angle) {
angle += _angle;
}
function forward(d,startx=x, starty = y, _angle = angle){
let newX = startx+d*sin(_angle);
let newY = starty+d*cos(_angle);
if (drawing){
line(startx,starty,newX,newY);
}
x=newX
y=newY
function pendown() {
drawing = true;
}
function back(d,startx=x, starty = y, _angle =360- angle){
let newX = startx+d*sin(_angle);
let newY = starty+d*cos(_angle);
if (drawing){
line(startx,starty,newX,newY);
}
x=newX
y=newY
function penup() {
drawing = false;
}
function left(_angle){
angle=180+_angle;
function penSize(weight = 1) {
strokeWeight(weight);
}
function right(_angle){
angle=_angle;
function penColor(c) {
stroke(c);
}
function pendown(){
drawing=true;
function randint(max = 100) {
//default returns int between 0 and 100
return int(random(max));
}
function penup(){
drawing=false;
function displayTurtle() {
stroke(0, 255, 0);
strokeWeight(1);
fill(0, 255, 0);
push();
translate(x, y);
rotate(180 + angle);
triangle(-10, 10, 10, 10, 0, -10);
pop();
}
function penSize(weight=1){
strokeWeight(weight);
function windowResized() {
//resizes canvas if window is resized
resizeCanvas(windowWidth, windowHeight);
}
function penColor(c){
stroke(c);
}
function randint(max=100){
//default returns int between 0 and 100
return int(random(max))
}
function displayTurtle(){
stroke(0,255,0);
strokeWeight(1);
fill(0,255,0);
push()
translate(x,y)
rotate(angle)
triangle(-10,10,10,10,0,-10);
pop()
}
function windowResized(){ //resizes canvas if window is resized
resizeCanvas(windowWidth, windowHeight);
function draw() {}
function mousePressed() {
print(mouseY);
}