Week 3 — Code Logic

Data visualization on all earth quake magnitude on the past day

Moving Magnitude Data
import csv
def setup():
size(900, 500)

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)

def draw():
background(33, 46, 68)
scalar = 10
x = 60
for magnitude in magnitudes:

leftEdge = x - (magnitude * scalar) / 2
rightEdge = x + (magnitude * scalar) / 2
if leftEdge < mouseX and mouseX < rightEdge:
fill (209, 192, 201)
else:
fill (147, 35, 99)
rect (x, height/1.2, -magnitude*scalar/2, -magnitude*scalar*5)
x +=3