Ejemplo n.º 1
0
Archivo: runes.py Proyecto: gluonn/etc
def anaglyph(painter):
	if graphics.PIL_available:
		MAX_X = round(4/3*viewport_size)
		MAX_Y = viewport_size
		stereo = vp
		depth = graphics.open_pixmap("Depthmap Viewport", viewport_size, viewport_size)

		def get_depth(x,y, pix):
			return pix[x,y][0]

		painter([lp, rp], unit_frame)
		#really! if you use getdata(), you need to calculate the offset in the array
		#load() returns a "2d pixel array" or rather, whatever it returns acts like one for all intents and purposes
		lp_pix = graphics.get_pixels(lp)
		rp_pix = graphics.get_pixels(rp)
		pixels = graphics.get_pixels(stereo)
		for y in range(MAX_Y):
			for x in range(MAX_X):
				l = get_depth(x,y,lp_pix)
				r = get_depth(x,y,rp_pix)
				pixels[x,y] = (r,l,l)

		graphics.pixels_to_canvas(stereo)

	else:
		print("PIL does not appear to be available")
Ejemplo n.º 2
0
def hollusion(painter, ports=None):
    global active_hollusion
    frequency = 2
    MAX_X = round(4 / 3 * viewport_size)
    MAX_Y = round(viewport_size)
    num = ports
    if ports == None or ports <= 2:
        num = 9  #because python is faster than scheme. Used to be 3
    buffers = list(
        map(
            lambda p: graphics.open_pixmap("buffer", 4 / 3 * viewport_size,
                                           viewport_size), range(num)))
    stereo = vp

    def animation(cmd=None):
        ports = buffers
        kill = False
        curr = -1
        dir = 1

        def Self(msg):
            nonlocal kill
            nonlocal curr
            nonlocal Self
            nonlocal dir
            if msg == "next":
                curr = (curr + dir)
                if (curr == num or curr < 0):
                    dir = -dir
                    curr += 2 * dir
                graphics.show_viewport(buffers[curr])
                if (
                        kill != True
                ):  #moved it here so you can happily next if the hollusion is dead.
                    vp[0].after(round(1000 / (frequency * len(ports))),
                                lambda: Self("next"))
                    #Timer(1/(frequency * len(ports)), Self, args=["next"]).start() #doesn't work because not thread safe
            elif msg == "kill":
                kill = True
            elif msg == "buffer":
                return ports
            else:
                return

        return Self

    painter(buffers, unit_frame)
    if (active_hollusion != None):
        active_hollusion("kill")
    active_hollusion = animation()
    active_hollusion("next")
    return active_hollusion
Ejemplo n.º 3
0
def hollusion(painter, ports=None):
	global active_hollusion
	frequency = 2
	MAX_X = round(4/3*viewport_size)
	MAX_Y = round(viewport_size)
	num = ports
	if ports == None or ports <= 2:
		num = 9 #because python is faster than scheme. Used to be 3
	buffers = list(map(lambda p: graphics.open_pixmap("buffer", 4/3*viewport_size,viewport_size), range(num)))
	stereo = vp

	def animation(cmd=None):
		ports = buffers
		kill = False
		curr = -1
		dir = 1
		def Self(msg):
			nonlocal kill
			nonlocal curr
			nonlocal Self
			nonlocal dir
			if msg == "next":
				curr = (curr+dir)
				if (curr == num or curr<0):
					dir = -dir
					curr += 2*dir
				graphics.show_viewport(buffers[curr])
				if(kill != True): #moved it here so you can happily next if the hollusion is dead.
					vp[0].after(round(1000/(frequency * len(ports))), lambda: Self("next"))
					#Timer(1/(frequency * len(ports)), Self, args=["next"]).start() #doesn't work because not thread safe
			elif msg == "kill":
				kill = True
			elif msg == "buffer":
				return ports
			else:
				return
		return Self
	painter(buffers, unit_frame)
	if(active_hollusion != None):
		active_hollusion("kill")
	active_hollusion = animation()
	active_hollusion("next")
	return active_hollusion
Ejemplo n.º 4
0
Archivo: runes.py Proyecto: gluonn/etc
def stereogram(painter):
	E = 300 #distance between eyes in pixels
	D = 600 #distance between eyes and image plane in pixels
	delta = 40 #stereo separation
	MAX_X = round(4/3*viewport_size)
	MAX_Y = viewport_size
	MAX_Z = 0
	CENTRE = round(MAX_X/2)
	stereo = vp
	pixels = graphics.get_pixels(stereo)
	depthmap = graphics.open_pixmap("temp", 4/3*viewport_size, viewport_size)
	depth_pix = graphics.get_pixels(depthmap)
	painter(depthmap, unit_frame)
	Infinity = float("inf")

	depth_pix = graphics.get_pixels(depthmap)
	def get_depth(x,y):
		if((x>=(1/6*viewport_size)) and (x<(MAX_X-(1/6*viewport_size)))):
			return -100*depth_pix[x,y][0]/255 - 400
		else:
			return -500
	for y in range(MAX_Y):
		link_left = {}
		link_right = {}
		colours = {}
		for x in range(MAX_X):
			z = get_depth(x,y)
			s = delta + z*(E/(z-D)) #Determine distance between intersection of lines of sight on image
			left = x - round(s/2) #x is integer, left is integer
			right = left + round(s) #right is integer
			if (left>0 and right<MAX_X):
				if(( not(left in link_right) or s<link_right[left]) and (not(right in link_left) or s<link_left[right])):
					link_right[left] = round(s)
					link_left[right] = round(s)

		#constraint resolution
		for x in range(MAX_X):
			try:
				s = link_left[x]
			except KeyError:
				s = Infinity
			if(s != Infinity):
				s = x
			d = None
			if(x-s>0):
				d = link_right[x-s]
			else:
				d = Infinity
			if(s == Infinity or (s>d)):
				link_left[x] = 0

		#drawing step
		for x in range(MAX_X):
			s = link_left[x] #should be valid for [0, MAX_X-1]
			try:
				colour = colours[x-s]
			except KeyError:
				colour = (round(random()*10/9*255),round(random()*10/9*255),round(random()*10/9*255))
			pixels[x,y] = colour
			colours[x] = colour
	graphics.pixels_to_canvas(stereo)
Ejemplo n.º 5
0
Archivo: runes.py Proyecto: gluonn/etc
spread = 20 #used to be 20, but i like at 80
active_hollusion = None
lastframe = None
#Setup
import graphics
import math
import time
import PyGif

Posn = graphics.Posn
Rgb = graphics.Rgb
draw_solid_polygon = graphics.draw_solid_polygon

graphics.init(viewport_size)
vp = graphics.open_viewport("ViewPort", 4/3*viewport_size, viewport_size)
lp = graphics.open_pixmap("LeftPort", 4/3*viewport_size, viewport_size)
rp = graphics.open_pixmap("RightPort", 4/3*viewport_size, viewport_size)

def clear_all():
	global active_hollusion
	global vp, lp, rp
	if(active_hollusion != None):
		active_hollusion("kill")
		active_hollusion = None
	graphics.clear_viewport(vp)
	graphics.clear_viewport(lp)
	graphics.clear_viewport(rp)

class Frame:
	def __init__(self, p0, p1, p2, z1, z2):
		self.orig = p0