Just a simple little demo I made instead of doing my math
Code:
The code gets progressively slower as it runs. Does anyone have any idea why?
Code:
#!/usr/bin/python2
import math, colorsys, time, gc, array
from graphics import *
def mapto(x, in_min, in_max, out_min, out_max):
return float((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
gc.enable()
pal = "Rasta"
scr = GraphWin("Plasma",75,75, autoflush=False)
#let's make a nice palette
palette = []
if pal == "Rainbow":
for h in range(256):
r,g,b = colorsys.hsv_to_rgb(mapto(h,0.0,255.0,0.0,1.0), 1.0, 1.0)
palette.append("#%02x%02x%02x" % (r*255,g*255,b*255))
if pal == "Rasta":
for i in range(256):
r = int(128.0 + 128 * math.sin(3.1415 * i / 16.0))
g = int(128.0 + 128 * math.sin(3.1415 * i / 128.0))
palette.append("#%02x%02x00" % (r,g))
print palette[0]
plasma = [[]]
for x in range(75):
plasma.append([])
for y in range(75):
color = int(128.0 + (128.0 * math.sin(x / 16.0)) + 128.0 + (128.0 * math.sin(y / 8.0)) + 128.0 + (128.0 * math.sin((x+y)) / 16.0) + 128.0 + (128.0 * math.sin(math.sqrt(x * x + y * y) / 8.0))) / 4
plasma[x].append(color)
for mod in range(100):
for x in range(75):
for y in range(75):
scr.plotPixel(x,y,palette[int((plasma[x][y] + mod) % 256)])
scr.update()
The code gets progressively slower as it runs. Does anyone have any idea why?