Tutorial 03 — Interactive Funny Face

JIANWEI LI
Data Mining the City
1 min readSep 27, 2017
def setup():
size(180, 180)
stroke(204, 102, 0) #this is made with 3 rgb values
strokeWeight(10)

global moods
moods = [‘happy’, ‘meh’, ‘sad’, ‘sick’]
# mood = “happy”

def draw():
background(255, 204, 0)

eyeRadius = 35
eyeYPosition = (height/2) — 50
leftEyeXPosition = (width/2) — 30
rightEyeXPosition = (width/2) + 30
mouthWidth = 80
mouthHeight = -20
mouthX = (width/2) — mouthWidth/2
mouthY = (height/2) — mouthHeight/2
myFaceMood = ‘normal’
fill(0, 0, 0)
ellipse(leftEyeXPosition, eyeYPosition, eyeRadius, eyeRadius)
fill(0, 0, 0)
ellipse(rightEyeXPosition, eyeYPosition, eyeRadius, eyeRadius)
fill(0, 255, 0)


if mouseX <width/3:
myFaceMood = moods[0]
elif mouseX <width/2:
myFaceMood = moods[1]
else:
myFaceMood = moods[2]


if myFaceMood == ‘happy’:
fill(0,255,255)
ellipse(leftEyeXPosition, eyeYPosition, eyeRadius*1.5, eyeRadius*1.5)
fill(0,255,255)
ellipse(rightEyeXPosition, eyeYPosition, eyeRadius*1.5, eyeRadius*1.5)
fill(0,255,255)
triangle(mouthX,mouthY,mouthX + 80,mouthY,mouthX + 40,mouthY + 40)


elif myFaceMood == ‘meh’:
fill(255,0,0)
ellipse(mouthX+40, mouthY, mouthWidth*1.5, mouthHeight*1.5)
elif myFaceMood == ‘sad’:
ellipse(mouthX+40, mouthY, mouthWidth, mouthHeight)
else:
ellipse(mouthX+40, mouthY, mouthWidth, mouthHeight/3)

--

--