In this page I will explain how to draw a simple face with p5.js (using simple geometric figures) and which interactions we will do with the face.
To draw a face, first we have to know some basic things, if you don't know how to program in p5.js, you can learn at this webstie (p5.js official tutorial).
Once we know this basic things we can start drawing the face. We will draw it by using ellipses (to draw the eyes and the outline of the face), triangles(to draw the nose) and arcs (to draw the mouth).
createCanvas()
, were we will draw the face( we will create it in the function setup()
) ellipse()
.ellipse()
triangle()
.arc()
.fill()
just before declaring the zone that we want to color.
var d = 100; //ball diameter
function setup(){
createCanvas(windowWidth, 400);
}
function draw(){
background(0,0,0,0); //transparent
//draw face
fill('#FCD0B4');
ellipse(windowWidth/2,200,d,d);
//draw eyes
fill(0,0,255);
ellipse(windowWidth/2-d/6,200-d/7,d/5,d/5);
ellipse(windowWidth/2+d/6,200-d/7,d/5,d/5);
fill(255,0,0,100);
triangle(windowWidth/2, 200-d/20, windowWidth/2+d/12, 200+d/7, windowWidth/2-d/12, 200+d/7);
//draw mouth
fill(255,0,0);
arc(windowWidth/2,200+d/4,d/2.5,d/4.5,0,PI,CHORD);
}