functionsetup() {
//create a drawing area
createCanvas(400, 400);
}
functiondraw() {
//set background color
background(220);
//set color and weight of lines
stroke(0);
strokeWeight(10);
//set fill color
fill(255,255,0);
//draw the outline
circle(200,200,200);
//draw the eyes
line(170,150,170,220);
line(230,150,230,220);
//draw the mouth
arc(200,230,100,100,0,PI);
//draw a text
fill(0);
textSize(50);
text("YAY!!!",130,350);
}
H01: Challenges
the position and size of each part of the face is specified directly.
Define variables for these so that they can be moved freely.
Once the variables are defined, let's try to create faces that represent other emotions by adjusting the values of the variables.
Create functions that draw faces representing different emotions, such as sadFace().
Referring back to the MicroBits exercise, define a new variable, the hunger value, and create a conditional that changes the emotion depending on its value.
H02: micro:Tamagotchi p5*js version
Next, let's try loading images instead of the drawing with graphic functions.
To do so, we need to follow the steps below.
Upload image(s) to p5.editor.
Specify the image path and load the image into the variable.
Read the image drawing function and display the image.