Jianqi Li
Data Mining the City
2 min readSep 26, 2018

--

Homework 3

Semester Project

For the project, I want to simulate the birds migration. How the urban green areas can help the migration of birds. And how the urban affect their migration. I think it is quite easy to get the data like which places are suitable for the birds to rest through their trip. We can looking into a particular species and find how far they can fly and what place they want to take a rest. For example, it is a place with lake or forest. After we finish this simulation, I think we will give urban planner valuable information in green space planning.

Simulation

Rules

  1. Each person has their own random route.
  2. Each person has different acceleration at different time.
  3. when they touch the boundaries they will go to the opposite side.
from slow import people_slow
from fast import people_fast
persons = []
personsf = []
NUM_totalpeople = 150
Num_slow= NUM_totalpeople/2
Num_fast= NUM_totalpeople/2
def setup():
global personsf, persons,i,a
size(1000, 1000, P3D)

for a in range(Num_fast):
personsf.append(people_slow(random(width), random(height),
5, a, personsf))

for i in range(Num_slow):
persons.append(people_fast(random(width), random(height),
5, i, persons))



noStroke()
ellipseMode(RADIUS)
fill(0,0,0)

slow:

class people_fast(object):
# Class variables. These are shared amongst all instances of Ball.
def __init__(self, x, y, radius, index, others):

self.radius = radius
self.index = index
self.others = others
self.location = PVector(width / 2, height / 2)
self.velocity = PVector(0, 0)
self.location.x = x
self.location.y = y
self.topspeed = 0.8
def move(self):
for other in self.others[self.index:]:
self.acceleration = PVector.random2D()
self.acceleration.mult(random(2))
self.velocity.add(self.acceleration)
self.velocity.limit(self.topspeed)
self.location.add(self.velocity)
def checkEdges(self):
for other in self.others[self.index:]:
if self.location.x > 1000:
self.location.x = 0
elif self.location.x < 0:
self.location.x = 1000
if self.location.y > 1000:
self.location.y = 0
elif self.location.y < 0:
self.location.y = 1000
def display(self):
img = loadImage("top.png")
image(img,self.location.x, self.location.y,img.height/7,img.width/3)
#ellipse(self.location.x, self.location.y, self.radius, self.radius)

fast:

class people_slow(object):
# Class variables. These are shared amongst all instances of Ball.
def __init__(self, x, y, radius, index, others):

self.radius = radius
self.index = index
self.others = others
self.location = PVector(width / 2, height / 2)
self.velocity = PVector(0, 0)
self.location.x = x
self.location.y = y
self.topspeed = 0.3
def move(self):
for other in self.others[self.index:]:
self.acceleration = PVector.random2D()
self.acceleration.mult(random(2))
self.velocity.add(self.acceleration)
self.velocity.limit(self.topspeed)
self.location.add(self.velocity)
def checkEdges(self):
for other in self.others[self.index:]:
if self.location.x > 1000:
self.location.x = 0
elif self.location.x < 0:
self.location.x = 1000
if self.location.y > 1000:
self.location.y = 0
elif self.location.y < 0:
self.location.y = 1000
def display(self):
img = loadImage("top2.png")
image(img,self.location.x, self.location.y,img.height/3,img.width/7)

--

--