#!/usr/bin/python2.3

import SWF
import Image
import random

swf = SWF.create(version=6, bbox=(0,0,512,512), fps=50)

swf.tags += SWF.BackgroundColor(0,0,0)

baboon = Image.open("baboon.png");
baboon.load()
baboon = baboon.convert("RGBA")
width = baboon.size[0]
height = baboon.size[1]
baboon = baboon.im

stream = SWF.VideoStream(width=width, height=height, frames=65535)

startframe = stream.addFrame(baboon, quant=20)
swf.tags += startframe
swf.tags += SWF.PlaceObject(stream, depth=1, ratio=0)
swf.tags += SWF.ShowFrame()

line = [0]*stream.xblocks()
map = [line]*stream.yblocks()

# short pause to display the image
for i in xrange(1,10):
    swf.tags += SWF.ShowFrame()

width = stream.xblocks()
height = stream.yblocks()
for i in xrange(1,200):
    for y in xrange(0,height):
	line = [0]*stream.xblocks()
	for x in xrange(0,width):
	    mx = (x^y)+3
	    my = (x^y)+3
	    line[x] = (mx+my*1j)
	map[y] = line

    dist = stream.addDistortionFrame(map)
    swf.tags += dist
    swf.tags += SWF.MoveObject(stream, depth=1, ratio=i)

    swf.tags += SWF.ShowFrame()

swf.save("xor.swf")

