size(200, 200); //green fill(0, 255, 0); //draw the head ellipse(100, 100, 150, 150); //white fill(255); //draw the eyes ellipse(75, 85, 30, 20); ellipse(125, 85, 30, 20); //black fill(0); //draw the pupils ellipse(75, 85, 10, 10); ellipse(125, 85, 10, 10); //red fill(255, 0, 0); //draw the mouth arc(100, 125, 80, 50, 0, 3.14); line(60, 125, 140, 125);
This code calls a series of functions do draw a smiley face:
arc() function takes 6 parameters: the first 4 parameters define an ellipse, and the last 2 parameters specify a limit (in radians) that causes the computer to only draw part of the ellipse. In radians,
0 is the right-most point of the ellipse, and
pi (we’re using
3.14 which is close enough) is the left-most point of the ellipse. That lets us draw only half the ellipse for the mouth.
See the Pen by Happy Coding (@KevinWorkman) on CodePen.
Draw a smiley face.
Draw a flower.
Draw a heart. ❤
Add your own example to Happy Coding.
Happy Coding is a community of folks just like you learning about coding.
Do you have a comment or question? Post it here!
Comments are powered by the Happy Coding forum. This page has a corresponding forum post, and replies to that post show up as comments here. Click the button above to go to the forum to post a comment!