xxxxxxxxxx
91
let x, y;
let speedx =2;
let speedy =3;
function setup() {
createCanvas(windowWidth, windowHeight);
x = 0;
y = 200;
}
function draw() {
//noCursor();
background(230, 230, 230);
moveDavid(speedx, speedy);
bounceDavid();
drawDavid(x , y );
}
function bounceDavid() {
if (x >= width || x <= 0) {
speedx = speedx * -1;
console.log("speed x: " + speedx);
}
if (y >= height || y <= 0) {
speedy = speedy * -1;
console.log("speed y: " + speedy);
}
}
function moveDavid(spX, spY) {
x = x + spX;
y = y + spY;
}
function drawDavid( davidx, davidy) {
fill(168, 109, 60);
noStroke();
//head
ellipse(davidx, davidy, 50, 60);
//eyes
fill(0);
ellipse(davidx - 12, davidy - 5, 7, 5);
ellipse(davidx + 12, davidy - 5, 7, 5);
//nose
stroke(0);
line(davidx - 3, davidy + 4, davidx + 3, davidy + 4);
// brows
arc(davidx - 10, davidy - 12, 8, 4, PI, 0, PIE);
arc(davidx + 10, davidy - 12, 8, 4, PI, 0, PIE);
//beard
arc(davidx, davidy + 10, 50, 55, -0.15, PI, PIE);
//mouth
fill(168, 109, 50);
ellipse(davidx, davidy + 15, 30, 8);
fill(0);
ellipse(davidx, davidy + 15, 10, 1);
//hat
fill(70, 70, 60);
arc(
davidx,
davidy - 16,
45,
30,
PI - QUARTER_PI / 10,
0 + QUARTER_PI / 10,
PIE
);
fill(50, 50, 10);
arc(
davidx,
davidy - 12,
50,
15,
PI - QUARTER_PI / 10,
0 + QUARTER_PI / 10,
PIE
);
}
function mousePressed(){
x= mouseX;
y= mouseY;
}