week 4

Yichen Ouyang
Data Mining the City
1 min readOct 25, 2017

class:

class Car(object):
def __init__(self,x,y, carLenth, carWidth, speed, time,colors):
self.x = x
self.y = y
self.carLenth = carLenth
self.carWidth = carWidth
self.colors = colors
self.speed = speed
self.time = time
def distance(self):
return self.time * self.speed
def draw(self):
fill(self.colors)
if self.x < mouseX and mouseX < self.x + self.carLenth:
fill(0)
#drawing the face
fill(63,92,75)
rect(self.x-10, self.y-80, 40,10)
fill(63,92,75)
rect(self.x+10, self.y-80, 20,50)
fill(63,92,75)
ellipse(self.x + 20,self.y + 15,80,100)
stroke(255, 255, 255)
fill(255, 0, 0)
noFill()
if mousePressed:
fill(255,50,0)
textSize(60)
text("Boom!", mouseX ,mouseY )
else:
fill(self.colors)
fill(171,115,80)
rect(self.x, self.y+10, 10 + self.carLenth, 10 + self.carWidth/3)
rect(self.x, self.y, 10 + self.carLenth, self.carWidth)

draw:

from car import *
def setup():
size(500,500)
global car_1
car_1 = Car(10,10,12,30,30,5, color(255,255,255))

print car_1.distance()
global runningcars
runningcars = []
for w in xrange(5, 150, 5): #start of range, end of range, step
car = Car(w*10, 100,w,90,color(255,255,255))
runningcars.append(car)
def draw():
background(186,186,186)
for car in runningcars:
car.draw()

--

--