Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created August 17, 2015 20:11
Show Gist options
  • Save kylemcdonald/68e3a903d7e9afac3cd0 to your computer and use it in GitHub Desktop.
Save kylemcdonald/68e3a903d7e9afac3cd0 to your computer and use it in GitHub Desktop.
Exhausting a Crowd path visualization, by Charlotte Stiles.
import csv
import os
import string
from path import*
def setup():
global finalList
global move
colorMode(HSB)
size(1280, 720)
#background(0)
frame.setResizable(True)
move = 0
finalList = []
listOfPath = []
num = ""
filePath = "notes-all-paths.csv"
with open(filePath, "rt") as data: # open files
for row in csv.DictReader(data):
tempList = []
path = row["path"]
temp2 = path.replace("}", '')
temp3 = temp2.split("{")
for elem in temp3:
if elem != '':
e = elem.strip(",") # gets rid of trailing commas
lst = e.split(",") # sep by comma
tempList.append(lst)
finalList.append(Path(tempList)) # it got to be a list of obj
# finalList = finalList[0:10]
def draw():
global move
xpos=False
ypos=False
lgstNum = 41000000 # largest time
brightS = 0 # brightness start
brightF = 255 # brightness finish
colS = 150 # where color starts
colS2 = 0
colF = 500 # makes it brighter than normal
a = 100 # alpha
#strokeWeight(1)
listnum = len(finalList)-1
fill(0,0,0,100)
noStroke()
rect(-10,-10,width+100,height+100)
noFill()
background(0)
move = move+(11000*6)
# print move
frm = int(map(move,0,width,0,listnum))
#text("From index: "+str(frm)+" to index: "+str(to),10,20)
# finalList1 = finalList[frm:to]
for path in finalList:
if path.startTime < move:
path.draw()
# for path in finalList[0:int(move)]:
# if path.done == False:
# path.drawUntil(move)
saveFrame("#####.tga")
def keyPressed():
global move
if key == " ":
saveFrame("#####.tga")
if key == "m":
move+=1
if key == "n":
move-=1
class Path:
def __init__(self,lst):
self.lst = lst
self.sx = float(lst[0][0])* width
self.sy = float(lst[0][1])* height
self.x = self.sx
self.y = self.sy
self.fx = float(lst[len(lst)-1][0])* width
self.fy = float(lst[len(lst)-1][1])* height
self.xd = self.sx-self.fx
self.yd = self.sy-self.fy
self.done = False
self.a = 100
self.count = 0
self.theta = atan2(self.yd, self.xd)
self.col = map(degrees(self.theta), -180, 180, 0, 255)
self.startTime = float(self.lst[0][2])
self.endTime = float (self.lst[len(lst)-1][2])
self.ms = 0
def draw(self):
ms = self.ms
firstTime = self.startTime
lastTime = self.endTime
if ms > (lastTime - firstTime):
if self.a > 0: self.a -= (20)
else:
return
stroke(self.col,255,255,self.a)
strokeWeight(2)
noFill()
beginShape()
prevX = float(self.lst[0][0])*width
prevY = float(self.lst[0][1])*height
prevTime = firstTime
for pt in self.lst:
self.count+=1
time = float(pt[2])
x = float(pt[0])*width
y = float(pt[1])*height
timeDiff = time - firstTime
if timeDiff < ms:
vertex(x, y)
prevX = x
prevY = y
prevTime = time
else:
t = map(ms+firstTime,prevTime,time,0,1)
lrpX = lerp(prevX,x,t)
lrpY = lerp(prevY,y,t)
vertex(lrpX, lrpY)
vertex(lrpX, lrpY)
break
# vertex(lrpX, lrpY)
endShape()
if self.count == len(self.lst):
self.done = True
self.count = 0
self.ms += 33.33*6 # ms per frame of video
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment