Files
sunny9898/task4/Q2a/index.js
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

31 lines
621 B
JavaScript

function setup() {
createCanvas(400, 400);
background(220);
// test with different parameters
head(200, 100, 100);
head(200, 200, 50);
head(200, 300, 10);
}
// x, y: the center of the head
// diam: the diameter of the head
function head(x, y, diam) {
// [Your Code Here]
fill("rgb(0,255,0)");
circle(x, y, diam);
// eyes
x_factor = diam * 0.15;
y_factor = diam * 0.1;
fill("rgb(0,0,0)");
circle(x - x_factor, y - y_factor, x_factor);
fill("rgb(0,0,0)");
circle(x + x_factor, y - y_factor, x_factor);
// mouth
noFill();
arc(x, y + y_factor, x_factor * 2, x_factor * 2, 0, PI);
}