Interactive Face and Earthquake Data

This is the interactive face for the panda~~

face_color=120
def setup():
size(500,500)
background(124,130,200)
def draw():
if mousePressed:
background(124,130,200)
fill(140,200,0)
rect(mouseX, 420, 200, 50,25)
line(mouseX+40, 420, mouseX+40, 470)
line(mouseX+80, 420, mouseX+80, 470)
line(mouseX+120, 420, mouseX+120, 470)
line(mouseX+160, 420, mouseX+160, 470)
#define locations and measures for the face
dict = {}
dict['centers'] = {'centerofFace':250, 'centerofLeftEar':150, 'centerofRightEar':350, 'centerofLeftEye':200, 'centerofRightEye':300, 'centerofMouth':250, 'centerofNose':250}
dict['radius']={'radiusFace':300, 'radiusEar':120, 'radiusEar2':60, 'radiusEye1':80, 'radiusEye2':40, 'radiusEye3':20, 'radiusEye4':10, 'radiusMouth':100, 'radiusNose':40}
#this is the left ear
fill(0)
ellipse(dict['centers']['centerofLeftEar'], dict['centers']['centerofLeftEar'], dict['radius']['radiusEar'], dict['radius']['radiusEar'])
fill(255)
ellipse(dict['centers']['centerofLeftEar'], dict['centers']['centerofLeftEar'], dict['radius']['radiusEar2'], dict['radius']['radiusEar2'])

#this is the right ear
fill(0)
ellipse(dict['centers']['centerofRightEar'], dict['centers']['centerofLeftEar'], dict['radius']['radiusEar'], dict['radius']['radiusEar'])
fill(255)
ellipse(dict['centers']['centerofRightEar'], dict['centers']['centerofLeftEar'], dict['radius']['radiusEar2'], dict['radius']['radiusEar2'])

#this is the face
fill(255)
strokeWeight(5)
ellipse(dict['centers']['centerofFace'], dict['centers']['centerofFace'], dict['radius']['radiusFace'], dict['radius']['radiusFace'])
fill(face_color,0,0)
noStroke
ellipse(150,300,40,40)
fill(face_color,0,0)
noStroke
ellipse(350,300,40,40)
#this is the left eye
i = PI * mouseX/400
y = cos(i)*(-10)
fill(0)
noStroke
ellipse(dict['centers']['centerofLeftEye'],dict['centers']['centerofLeftEye']+20, dict['radius']['radiusEye1'], dict['radius']['radiusEye1'])
fill(255)
ellipse(dict['centers']['centerofLeftEye'],dict['centers']['centerofLeftEye']+20, dict['radius']['radiusEye2'], dict['radius']['radiusEye2'])
fill(0)
ellipse(dict['centers']['centerofLeftEye']+y,dict['centers']['centerofLeftEye']+25, dict['radius']['radiusEye3'], dict['radius']['radiusEye3'])
fill(255)
ellipse(dict['centers']['centerofLeftEye']+y,dict['centers']['centerofLeftEye']+25, dict['radius']['radiusEye4'], dict['radius']['radiusEye4'])

#this is the right eye
i = PI * mouseX/400
z = cos(i)*(-10)
fill(0)
ellipse(dict['centers']['centerofRightEye'],dict['centers']['centerofLeftEye']+20, dict['radius']['radiusEye1'], dict['radius']['radiusEye1'])
fill(255)
ellipse(dict['centers']['centerofRightEye'],dict['centers']['centerofLeftEye']+20, dict['radius']['radiusEye2'], dict['radius']['radiusEye2'])
fill(0)
ellipse(dict['centers']['centerofRightEye']+z,dict['centers']['centerofLeftEye']+25, dict['radius']['radiusEye3'], dict['radius']['radiusEye3'])
fill(255)
ellipse(dict['centers']['centerofRightEye']+z,dict['centers']['centerofLeftEye']+25, dict['radius']['radiusEye4'], dict['radius']['radiusEye4'])

#this is the mouse
fill(255)
strokeWeight(4)
ellipse(dict['centers']['centerofMouth'], dict['centers']['centerofMouth']+40, dict['radius']['radiusMouth'], dict['radius']['radiusMouth'])
noFill()
curve(dict['centers']['centerofMouth']-100, dict['centers']['centerofMouth'], dict['centers']['centerofMouth'], dict['centers']['centerofMouth']+40, dict['centers']['centerofMouth']-30, dict['centers']['centerofMouth']+60,dict['centers']['centerofMouth']-80, dict['centers']['centerofMouth']-40)
noFill()
curve(dict['centers']['centerofMouth']+100, dict['centers']['centerofMouth'], dict['centers']['centerofMouth'], dict['centers']['centerofMouth']+40, dict['centers']['centerofMouth']+30, dict['centers']['centerofMouth']+60,dict['centers']['centerofMouth']+80, dict['centers']['centerofMouth']-40)
if mousePressed:
fill(200,0,0)
arc(dict['centers']['centerofNose'], dict['centers']['centerofNose']+60, 30, 30, 0.1*PI,PI-0.1*PI,PIE)
#this is the nose
fill(0)
noStroke
ellipse(dict['centers']['centerofNose'], dict['centers']['centerofNose']+30, dict['radius']['radiusNose'], dict['radius']['radiusNose'])
def mouseWheel(event):
global face_color
e = event.getCount()
face_color += event.getCount()*2
#keep value in range
face_color = face_color % 255

This is the visualization for the earthquake data~~

import csv
def setup():
size(2000, 1000)

with open("quakes.csv") as f:
reader = csv.reader(f)
header = reader.next() # Skip the header row.

global magnitudes
magnitudes = []

for row in reader:
magnitude = float(row[4])
magnitudes.append(magnitude)

with open("quakes.csv") as f:
reader = csv.reader(f)
header = reader.next() # Skip the header row.

global depths
depths = []

for row in reader:
depth = float(row[3])
depths.append(depth)

def draw():
background(110,120,0)
x = 0
strokeWeight(2)
text("Magnitude",width/2-250,700)

for magnitude in magnitudes:
leftEdge = x - (magnitude * 10) / 2
rightEdge = x + (magnitude * 10) / 2
if leftEdge < mouseX and mouseX < rightEdge:
fill(255)
textSize(100)
text(magnitude,width/2-180,800)
fill(255,0,0)
else:
fill(255,255,255)

rect(x, height / 2, 10 ,magnitude*(-30))
x += 20
Like what you read? Give Demin Hu a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.