HW 3

Lu Hao
Data Mining the City
2 min readSep 26, 2018
  1. Short Description of Semester Project

The semester project may try to simulate the public life in a public space in the city. For instance, the plaza or a city park being used by the amount of people at the particular time period.

2. The simulation for hw 3 is showing the pedestrian movement among groups with different age. It aims to compare the walking speed between the elderly pedestrians, which are in red, and the pedestrians in general age which are marked as green.

import random
#starting points
# and incremental move distance
class Ped1(object): #the general pedestrian on the street, upper
def __init__(self):
self.location = PVector(random.randint(0,900), random.randint(200, 210))
self.velocity = PVector(random.randint(5,10),random.randint(-5,40))
self.maxspeed = 1.5
self.acceleration = PVector(random.randint(0,900), 0)
def update(self):
self.location.add(self.velocity)
self.velocity.add(self.acceleration)
self.velocity.limit(self.maxspeed)
#bounce off edges.
if self.location.x > width or self.location.x < 0:
self.location.x = random.randint(0,10)
def display(self):
ellipse(self.location.x, self.location.y, 10, 10)


class Ped2(object): #the general pedestrian on the street, lower side
def __init__(self):
self.location = PVector(random.randint(0,900), random.randint(390, 400))
self.velocity = PVector(0, random.randint(5,40))
self.maxspeed = 1.5
self.acceleration = PVector(random.randint(20, 30), 0)

def update(self):
self.location.add(self.velocity)
self.velocity.add(self.acceleration)
self.velocity.limit(self.maxspeed)
#bounce off edges.
if self.location.x > width or self.location.x < 0:
self.location.x = random.randint(0,10)
def display(self):
ellipse(self.location.x, self.location.y, 10, 10)

class Elder1(object):#the elderly pedestrians.
def __init__(self):
self.location = PVector(random.randint(0,900), random.randint(200, 210))
self.velocity = PVector(0, random.randint(5,40))
self.maxspeed = 0.3
self.acceleration = PVector(random.randint(20,30),0)

def update(self):
self.location.add(self.velocity)
self.velocity.add(self.acceleration)
self.velocity.limit(self.maxspeed)

if self.location.x > width or self.location.x <0:
self.location.x = random.randint(0,10)
def display(self):

ellipse(self.location.x, self.location.y, 10, 10)
class Elder2(object):#the elderly pedestrians.
def __init__(self):
self.location = PVector(random.randint(0,900), random.randint(390, 400))
self.velocity = PVector(0, random.randint(5,40))
self.maxspeed = 0.3
self.acceleration = PVector(random.randint(20,30),0)

def update(self):
self.location.add(self.velocity)
self.velocity.add(self.acceleration)
self.velocity.limit(self.maxspeed)

if self.location.x > width or self.location.x <0:
self.location.x = random.randint(0,10)
def display(self):

ellipse(self.location.x, self.location.y, 10, 10)
def setup():
size(900, 600)
smooth()
global img, car, ped_up, ped_down, people, elder_up, elder_down
img = loadImage("street.jpg")
car = loadImage("car.png")
#people = loadImage("people.png")
ped_up = []
ped_down = []
elder_up = []
elder_down =[]

for i in xrange(60):
ped_up.append(Ped1())
for j in xrange(70):
ped_down.append(Ped2())
for z in xrange(8):
elder_up.append(Elder1())
for x in xrange(12):
elder_down.append(Elder2())

def draw():
background(0)
image(img,0, 0, width*1.1, height*1.1)
image(car, 200,260, width/10, height/8)
for i in xrange(60):
fill(0,255,0)
ped1 = ped_up[i]
ped1.update()
ped1.display()

for j in xrange(70):
fill(0,255,0)
ped2 = ped_down[j]
ped2.update()
ped2.display()

for z in xrange(8):
fill(255,0,0)
elder1 = elder_up[z]
elder1.update()
elder1.display()
for x in xrange(12):
fill(255,0,0)
elder2 = elder_down[x]
elder2.update()
elder2.display()

--

--