xxxxxxxxxx
78
// here is a comment
/*
Adding x and y position variables.
by Carlos Brito
11/10/2024
Replace hard coded numbers with position variables
*/
function setup() {
createCanvas(400, 400);
}
// declare variables
let x = 23;
let y = 365;
function draw() {
background(220);
//movement varibles
if (keyIsDown(RIGHT_ARROW)) {
x = x + 5;
}
if (keyIsDown(LEFT_ARROW)) {
x = x - 5;
}
if (keyIsDown(UP_ARROW)) {
y = y- 5;
}
if (keyIsDown(DOWN_ARROW)) {
y = y+ 5;
}
colorMode(HSB);
fill(260, 70 , 100);
strokeWeight(3)
//Shapes:
//ears
triangle(
x - 20, y -30, // x1 , y1
x - 20, y, // x2, y2
x, y // x3, y3
);
triangle(
x + 20, y -30, // x1 , y1
x + 20, y, // x2, y2
x, y
);
rectMode(CENTER)
//square(200, 200, 40, 10);
square(x, y, 40 , 10)
//Eyes
fill("blue");
circle(x - 10, y - 10, 10);
circle(x +10, y - 10, 10);
//Mouth
line(x- 5, y + 10, x +5, y+ 5 );
line(x+ 5, y + 10, x -5, y+ 5 );
//feet
rect(x - 10 , y +30 , 12, 8, 4);
rect(x + 10 , y +30 , 12, 8, 4);
}