Skip to content

Instantly share code, notes, and snippets.

@x-or
Last active December 13, 2015 19:59
Show Gist options
  • Save x-or/4966749 to your computer and use it in GitHub Desktop.
Save x-or/4966749 to your computer and use it in GitHub Desktop.
XOR RGB Sliding
power = 9
size = 2**power
scenario = [
# scene 0
(size, lambda i, x, y: ((x+i)%size, x, (x-i)%size),
lambda i, x, y: (y, (y+i)%size, (y-i)%size)),
# scene 1
(size, lambda i, x, y: ((x-i)%size, (x-i)%size, x),
lambda i, x, y: (y, (y+i)%size, (y+i)%size)),
# scene 2
(size, lambda i, x, y: ((x+i)%size, (x+i)%size, x),
lambda i, x, y: ((y-i)%size, y, (y-i)%size)),
# scene 3
(size, lambda i, x, y: ((x+i)%size, x, (x+i)%size),
lambda i, x, y: (y, (y+i)%size, (y-i)%size)),
# scene 4
(size, lambda i, x, y: ((x-i)%size, (x+i)%size, x),
lambda i, x, y: (y, (y+i)%size, (y-i)%size)),
# scene 5
(size, lambda i, x, y: ((x+i)%size, (x-i)%size, x),
lambda i, x, y: ((y+i)%size, y, (y-i)%size)),
]
colors = 256
if power <= 7:
norm_coef = colors // size
norm = lambda x: (x[0]*norm_coef, x[1]*norm_coef, x[2]*norm_coef)
elif power == 8:
norm = lambda x: x
elif power >= 9:
norm_coef = size // colors
norm = lambda x: (x[0]/norm_coef, x[1]/norm_coef, x[2]/norm_coef)
def xor3(x, y):
return (x[0]^y[0], x[1]^y[1], x[2]^y[2])
from PIL import Image
image = Image.new("RGB", (size, size), 0)
pix = image.load()
frameno = 0
for sceneno, scene in enumerate(scenario):
frames, getx, gety = scene
for i in xrange(frames):
print "scene #", sceneno, "frame #", i
for x in xrange(size):
for y in xrange(size):
pix[x, y] = norm(xor3(getx(i, x, y), gety(i, x, y)))
image.save("xor-play-%d-%04d.png"%(power, frameno), "png")
frameno += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment