People in Central Park

Jiacheng Zhou
Data Mining the City
2 min readSep 26, 2018

--

Title: Simulation of Crime Changes in Manhattan
Group Member: Zheyu Liu, Jiacheng Zhou

Description: Crime incidents happen in Central Park from time to time. Decomposing it may be a good idea (but not that realistic) to decrease the crime rate in Manhattan. We hold the view that the number of and different geometry characteristics of the minor parks may have different contributions to the crime reduction. We will simulate and visualize the change of crime rate in Manhattan after decomposing the Central Park into smaller parks.```

HW3 — Jogging or walking the dog in Central Park?

Various people do various activities in Central Park every day. Now I simply classify them into two kinds:those who are jogging and those who are walking the dog.

The rule is that both joggers and dog walkers are only allowed to do activities inside the central park randomly.

import random as rmdef setup():
size(1200,600)
background(255)
global CP_img, dog_shp
global jog, wander
jog=[]
wander=[]
CP_img=loadImage("CP.png")
dog_shp=loadShape("Dog.svg")

for i in xrange(75):
jog.append(Jog())

for i in xrange(75):
wander.append(Wander())
class Jog(object):
def _init_(self, location, velocity, maxSpeed, minSpeed):
self.location = PVector(rm.randint(45,1105),rm.randint(130,440))
self.velocity= PVector(20,5)
self.maxSpeed=80
self.minSpeed=20

def randomWalk(self):
self.update()
self.display()
self.edgeControl()

def display(self):
fill(150)
ellipse(self.location.x,self.location.y, 20,20)

def update(self):
self.location.add(self.velocity)

def edgeControl(self):
if self.location.x > 1105:
self.velocity.x = -(self.velocity.x)
elif self.location.x < 45:
self.velocity.x = -(self.velocity.x)
elif self.location.y < 130:
self.location.y = -(self.velocity.y)
elif self.location.y > 440:
self.velocity.y = -(self.velocity.y)

class Wander(object):
def _init_(self):
self.location=PVector(rm.randint(45,1105),rm.randint(130,440))
self.velocity=PVector(45,130)
self.maxSpeed=80
self.minSpeed=20

def randomWalk(self):
self.update()
self.display()
self.edgeControl()

def update(self):
for i in range(1):
if i>0.5:
self.location.x=self.location.x+i*20
self.location.y=self.location.y+i*20
else:
self.location.x=self.location.x-i*20
self.location.y=self.location.y-i*20

def display(self):
fill(250)
shape(dog_shp, self.location.x, self.location.y, 10, 10)


def edgeControl(self):
if self.location.x > 1105:
self.velocity.x = -(self.velocity.x)
elif self.location.x < 45:
self.velocity.x = -(self.velocity.x)
elif self.location.y < 130:
self.location.y = -(self.velocity.y)
elif self.location.y > 440:
self.velocity.y = -(self.velocity.y)
def draw():
image(CP_img,0,0,1200,600)
# rect(45,130,1060,310) #Pinpoint the position of Central Park

# jogging display
noStroke()
for i in xrange(75):
# jog.append(Jog())
m=jog[i]
m.randomWalk()
m.display()

#wandering display
for i in xrange(75):
# wander.append(Wander())
n=wander[i]
n.randomWalk()
n.display()

--

--