I’m On My Way

Yue Dong
Data Mining the City
2 min readSep 19, 2018

Date: Sept 19, 2018

Description: As planners, we use the shortest path to measure the accessibility of public transportation. However as lived, people may not always take the shortest route.

The following animation created by processing shows the neighborhood I live. My apartment which is marked in red is four blocks away from Columbus circle. And sometimes I would like to take a detour and stop by a cafe or bakery instead of going directly to the subway station.

Interactivity: Users can press arrow keys to control the sprite and when the sprite arrives Columbus circle, it goes back to the starting point.

Here is the original code:

def setup():
size(1500,800)
background(255)
global blockWidth, blockHeight, avWidth, stWidth, myspeed
avWidth = 40
stWidth = 20
blockWidth = 300
blockHeight = 75
myspeed = 5

global imax, jmax,fth, coffee, bagel
imax = width/(blockWidth+avWidth)
jmax = height/(blockHeight+stWidth)-1
fth = loadImage("data/FTH.gif")
coffee = loadImage("data/coffee.gif")
bagel = loadImage("data/bagel.gif")


def markmyhome(x,y):
fill(113,38,61)
noStroke()
ellipse(x,y,30,30)
myx = 50
myy = 540
def draw():
x = 50
y = 100
# create the city grid
for i in range(0, imax):
for j in range(0, jmax):
noStroke()
fill(200)
if i==3 and j==2:
rect(x+i*(blockWidth+avWidth), y+j*(blockHeight+stWidth),
blockWidth, stWidth+blockHeight*2)
fill(255)
ellipse(x+i*(blockWidth+avWidth)+blockWidth,
y+j*(blockHeight+stWidth)+blockHeight+stWidth/2,
stWidth+blockHeight*2,
stWidth+blockHeight*2)
fill(120,163,146)
ellipse(x+i*(blockWidth+avWidth)+blockWidth,
y+j*(blockHeight+stWidth)+blockHeight+stWidth/2,
blockHeight,
blockHeight)
elif i==3 and j==3:
continue
elif i==0 and j==5:
rect(x+i*(blockWidth+avWidth), y+j*(blockHeight+stWidth),
blockWidth, blockHeight)
markmyhome(x+i*(blockWidth+avWidth)+blockWidth/4,
y+j*(blockHeight+stWidth)+blockHeight/4)
else:
rect(x+i*(blockWidth+avWidth), y+j*(blockHeight+stWidth),
blockWidth, blockHeight)

# print road names
m = 0
while m < jmax:
fill(0)
textSize(20)
textAlign(CENTER)
streetNum = str(61-m)
text(streetNum + ' Street', 600,
y+m*(blockHeight+stWidth)+blockHeight+stWidth/2)
m += 1
# print avenue names
n = 0
while n < imax:
avNum = str(11-n)
fill(0)
textSize(20)
textAlign(CENTER)
pushMatrix()
translate(x+n*(blockWidth+avWidth)+blockWidth+avWidth/2,500)
rotate(-PI/2)
text(avNum + 'Ave',0,0)
rotate(PI/2)
popMatrix()
n += 1

image (coffee, 400, 500,width/30,height/15)
image (bagel, 780, 380,width/30,height/15)
# print my route to the subway station
global myx,myy
image(fth, myx, myy, width/30,height/15)
# define my movement

if myx <= 4* (blockWidth + avWidth) and myy > 300 :
if (keyPressed):
if key == CODED:
if keyCode == UP:
myy -= myspeed
elif keyCode == DOWN:
myy += myspeed
elif keyCode == LEFT:
myx -= myspeed
elif keyCode == RIGHT:
myx += myspeed
if myx > 4* (blockWidth + avWidth) or myy <= 300 :
myx = 50
myy = 540

--

--