xxxxxxxxxx
86
// here is a comment
/*
adding x and y position variables
by Mariam
11/04/24
*/
function setup() {
createCanvas(400, 400);
}
// this is an example function
// function declaration
function exampleFunction(num) {
// function scope
// define the steps of the function
// print a number to the console
console.log(num);
}
// use the fucntion (calling,invoking)
exampleFunction(7);
exampleFunction(777);
exampleFunction(100 + 100);
function draw() {
background(200);
//declare variables
let x = 200;
let y = 300;
if (keyIsDown(RIGHT_ARROW)) {
x = x + 10;
}
if (keyIsDown(LEFT_ARROW)) {
x = x - 5;
}
// add some color
colorMode(HSB);
fill(260, 60, 60);
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
);
//face
rectMode(CENTER);
circle(x, y, 40, 10);
//eyes
circle(x - 10, y - 10, 10);
circle(x + 10, y - 10, 10);
// mouth
line(x - 5, y + 5, x + 10, y + 10);
line(x - 5, y + 10, x + 5, y + 10);
// feet
rect(x - 10, y + 30, 12, 8, 2);
rect(x + 10, y + 30, 12, 8, 2);
}
// save an image of the canvas
function mousePressed() {
save("character.jpg");
}