now sporting multiple runs (currently 3) and blending

This commit is contained in:
Bill Currie 2003-08-12 22:18:51 +00:00
parent 515dbaccc0
commit c9346e806c

View file

@ -8,94 +8,124 @@ red = (255, 0, 0)
magenta = (255, 0,255) magenta = (255, 0,255)
yellow = (255,255, 0) yellow = (255,255, 0)
white = (255,255,255) white = (255,255,255)
grey = (128,128,128)
def plot (x, y, color): def div10 (x):
return x / 5
def plot (x, y, color, blend = 0):
def lim (x):
if x > 255:
x = 255
return x
y = height - 1 - y y = height - 1 - y
p = (y * width + x) * 3 p = (y * width + x) * 3
a[p + 0], a[p + 1], a[p + 2] = color r, g, b = color
if blend:
r += a[p + 0]
g += a[p + 1]
b += a[p + 2]
a[p + 0], a[p + 1], a[p + 2] = lim (r), lim (g), lim (b)
def vline (x, y1, y2, color): def vline (x, y1, y2, color, blend = 0):
if y1 == y2: if y1 == y2:
plot (x, y1, color) plot (x, y1, color, blend)
elif y1 < y2: elif y1 < y2:
for y in range (y1, y2 + 1): for y in range (y1, y2 + 1):
plot (x, y, color) plot (x, y, color, blend)
else: else:
for y in range (y2, y1 + 1): for y in range (y2, y1 + 1):
plot (x, y, color) plot (x, y, color, blend)
def hline (x1, x2, y, color): def hline (x1, x2, y, color, blend = 0):
if x1 == x2: if x1 == x2:
plot (x1, y, color) plot (x1, y, color, blend)
elif x1 < x2: elif x1 < x2:
for x in range (x1, x2 + 1): for x in range (x1, x2 + 1):
plot (x, y, color) plot (x, y, color, blend)
else: else:
for x in range (x2, x1 + 1): for x in range (x2, x1 + 1):
plot (x, y, color) plot (x, y, color, blend)
f = open ("timeframes.txt", "rt") class Frames:
lines = f.readlines () class iterator:
f.close def __init__ (self, obj):
self.obj = obj
times = map (lambda x: (int(x) + 5)/100, lines) self.cur = 0
self.max = len (obj)
sum = 0 def __iter__ (self):
min=max=times[0] return self
for t in times: def next (self):
if min > t: if self.cur == self.max:
min = t raise StopIteration
if max < t: obj = self.obj.times[self.cur]
max = t self.cur += 1
sum = sum + t return obj
def __init__ (self, data):
print min/10.0, max/10.0, sum/10.0 / len(times) self.times = map (lambda x: (int(x) + 5)/100, data)
average = sum / len(times) min = max = self.times[0]
sum = 0
group = 1 for t in self.times:
width = (len (times) + group - 1) / group
height = max + 1
a = array.array ('B', '\0' * height * width * 3)
hline (0, width - 1, 0, white)
vline (0, 0, height - 1, white)
for y in range (0, height - 1, 10):
hline (0, 3, y, white)
for y in range (0, height - 1, 100):
hline (0, 6, y, white)
for x in range (0, width - 1, 100):
vline (x, 0, 3, white)
ravg = 0.0
ravg_span = 20
for x in range (width):
if group > 1:
tset = times[x * group: x * group + group]
sum = 0;
min = max = tset[0]
for t in tset:
if min > t: if min > t:
min = t min = t
if max < t: if max < t:
max = t max = t
sum = sum + t sum = sum + t
if x: self.min = min
oldavg = avg self.max = max
avg = sum / len (tset) self.avg = sum / float (len (self.times))
vline (x, min, max, green) def __len__ (self):
if x: return len (self.times)
vline (x, oldavg, avg, yellow) def __getitem__ (self, key):
if type (key) == type (1):
return self.times[key]
else: else:
plot (x, avg, yellow) if key.step:
else: return self.times[key.start:key.stop:key.step]
if x < width - 1: else:
vline (x, times[x], times[x + 1], yellow) return self.times[key.start:key.stop]
plot (x, times[x], red) def __iter__ (self):
plot (x, int (ravg + 0.5), cyan) return Frames.iterator (self)
frames = []
for i in range (1, 4):
f = open ("timeframes.txt."+ `i`, "rt")
lines = f.readlines ()
f.close ()
frames.append (Frames (lines))
print frames[-1].min/10.0, frames[-1].max/10.0, frames[-1].avg/10.0
width = len (frames[0])
height = frames[0].max
for f in frames:
if width < len (f):
width = len (f)
if height < f.max + 1:
height = f.max + 1
a = array.array ('B', '\0' * height * width * 3)
hline (0, width - 1, 0, grey)
vline (0, 0, height - 1, grey)
for y in range (0, height - 1, 10):
hline (0, 5, y, grey)
for y in range (0, height - 1, 100):
hline (0, 10, y, grey)
for x in range (0, width - 1, 10):
vline (x, 0, 5, grey)
for f in frames:
ravg = 0.0
ravg_span = 20
for x in range (len (f)):
if x < len (f) - 1:
vline (x, f[x], f[x + 1], map (div10, yellow), 1)
plot (x, f[x], red)
plot (x, int (ravg + 0.5), map (div10, cyan), 1)
if (x >= ravg_span): if (x >= ravg_span):
ravg -= times[x - ravg_span]/float(ravg_span) ravg -= f[x - ravg_span]/float(ravg_span)
ravg += times[x]/float(ravg_span) ravg += f[x]/float(ravg_span)
hline (0, width - 1, average, blue) hline (0, len (f) - 1, int (f.avg + 0.5), map (div10, blue), 1)
f = open ("timeframes.ppm", "wb") f = open ("timeframes.ppm", "wb")
f.write ("P6\n") f.write ("P6\n")