Esempio n. 1
0
File: runes.py Progetto: 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")
Esempio n. 2
0
    def painter(vp, frame):
        def ana_out_loop(port, count):
            inverse_transform = inverse_transform_posn(frame)
            tgtpixels = graphics.get_pixels(port)
            size = graphics.get_image_size(port)
            MAX_X = size[0]
            MAX_Y = size[1]
            tgtpixels = graphics.get_pixels(port)
            for y in range(MAX_Y):
                for x in range(MAX_X):
                    posn = inverse_transform(Posn(x, y))
                    col = get_depth(posn.x, posn.y, count, frame)
                    if (col > 1):
                        col = 1
                    col = round(col * 255)
                    if (col < 255):
                        #tgtpixels[x,y] = (col, col, col)
                        tgtpixels[x, y] = (min(col, tgtpixels[x, y][0]),
                                           min(col, tgtpixels[x, y][1]),
                                           min(col, tgtpixels[x, y][2]))
            graphics.pixels_to_canvas(port)

        if (is_list(vp[0])):
            for count, port in enumerate(vp):
                ana_out_loop(port, ((2 * count) / (len(vp) - 1) - 1))
        else:
            inverse_transform = inverse_transform_posn(frame)
            tgtpixels = graphics.get_pixels(vp)
            size = graphics.get_image_size(vp)
            MAX_X = size[0]
            MAX_Y = size[1]
            for y in range(MAX_Y):
                for x in range(MAX_X):
                    posn = inverse_transform(Posn(x, y))
                    color = depth_fun(posn.x, posn.y)
                    if (color != 1):
                        color = frame.z1 + ((frame.z2 - frame.z1) * color)
                    if (color > 1):
                        color = 1
                    color = round(color * 255)
                    if (color < 255
                        ):  #assuming that white is the transparency color
                        #tgtpixels[x,y] = (color, color, color)
                        tgtpixels[x, y] = (min(color, tgtpixels[x, y][0]),
                                           min(color, tgtpixels[x, y][1]),
                                           min(color, tgtpixels[x, y][2]))
            graphics.pixels_to_canvas(vp)
Esempio n. 3
0
File: runes.py Progetto: gluonn/etc
		def ana_out_loop(port, count):
			inverse_transform = inverse_transform_posn(frame)
			tgtpixels = graphics.get_pixels(port)
			size = graphics.get_image_size(port)
			MAX_X = size[0]
			MAX_Y = size[1]
			tgtpixels = graphics.get_pixels(port)
			for y in range(MAX_Y):
				for x in range(MAX_X):
					posn = inverse_transform(Posn(x,y))
					col = get_depth(posn.x, posn.y, count, frame)
					if (col>1):
						col = 1
					col = round(col*255)
					if(col<255):
						#tgtpixels[x,y] = (col, col, col)
						tgtpixels[x,y] = (min(col, tgtpixels[x,y][0]), min(col, tgtpixels[x,y][1]), min(col, tgtpixels[x,y][2]))
			graphics.pixels_to_canvas(port)
Esempio n. 4
0
 def ana_out_loop(port, count):
     nonlocal img
     size = graphics.get_image_size(img)
     MAX_X = size[0]
     MAX_Y = size[1]
     tsize = graphics.get_image_size(port)
     TMAX_X = tsize[0]
     TMAX_Y = tsize[1]
     tgtpixels = graphics.get_pixels(port)
     inv_transform = inverse_transform_posn(frame)
     # for y in range(MAX_Y):
     # for x in range(MAX_X):
     # col = get_depth(x,y,count)
     # if(col>255*limit):
     # col = 999
     # else:
     # col = frame.z1 + (frame.z2 - frame.z1) * col
     # if col<=255:
     # transposn = transform(Posn(x,y))
     # if(transposn.x>=0 and transposn.y>=0 and transposn.x<TMAX_X and transposn.y<TMAX_Y):
     # tgtpixels[transposn.x, transposn.y] = (col,col,col)
     #sorry, no supersampling. Takes long enough as it is.
     for y in range(TMAX_Y):
         for x in range(TMAX_X):
             orig = inv_transform(Posn(x, y))
             rx = round(orig.x)
             ry = round(orig.y)
             if (rx >= 0 and ry >= 0 and rx < MAX_X
                     and ry < MAX_Y):  #within bounds
                 col = get_depth(rx, ry, count)
                 if (col > 255 * limit):
                     col = 999
                 else:
                     col = round(frame.z1 * 255 +
                                 (frame.z2 - frame.z1) * col)
                 if (col <= 255):
                     #tgtpixels[x,y] = (col, col, col)
                     tgtpixels[x,
                               y] = (min(col, tgtpixels[x, y][0]),
                                     min(col, tgtpixels[x, y][1]),
                                     min(col, tgtpixels[x, y][2]))
     graphics.pixels_to_canvas(port)
Esempio n. 5
0
	def painter(vp, frame):
		def ana_out_loop(port, count):
			inverse_transform = inverse_transform_posn(frame)
			tgtpixels = graphics.get_pixels(port)
			size = graphics.get_image_size(port)
			MAX_X = size[0]
			MAX_Y = size[1]
			tgtpixels = graphics.get_pixels(port)
			for y in range(MAX_Y):
				for x in range(MAX_X):
					posn = inverse_transform(Posn(x,y))
					col = get_depth(posn.x, posn.y, count, frame)
					if (col>1):
						col = 1
					col = round(col*255)
					if(col<255):
						#tgtpixels[x,y] = (col, col, col)
						tgtpixels[x,y] = (min(col, tgtpixels[x,y][0]), min(col, tgtpixels[x,y][1]), min(col, tgtpixels[x,y][2]))
			graphics.pixels_to_canvas(port)
		if(is_list(vp[0])):
			for count, port in enumerate(vp):
				ana_out_loop(port, ((2*count)/(len(vp)-1) - 1))
		else:
			inverse_transform = inverse_transform_posn(frame)
			tgtpixels = graphics.get_pixels(vp)
			size = graphics.get_image_size(vp)
			MAX_X = size[0]
			MAX_Y = size[1]
			for y in range(MAX_Y):
				for x in range(MAX_X):
					posn = inverse_transform(Posn(x,y))
					color = depth_fun(posn.x, posn.y)
					if(color != 1):
						color = frame.z1 + ((frame.z2 - frame.z1) * color)
					if (color>1):
						color = 1
					color = round(color*255)
					if(color<255): #assuming that white is the transparency color
						#tgtpixels[x,y] = (color, color, color)
						tgtpixels[x,y] = (min(color, tgtpixels[x,y][0]), min(color, tgtpixels[x,y][1]), min(color, tgtpixels[x,y][2]))
			graphics.pixels_to_canvas(vp)
Esempio n. 6
0
			def ana_out_loop(port, count):
				nonlocal img
				size = graphics.get_image_size(img)
				MAX_X = size[0]
				MAX_Y = size[1]
				tsize = graphics.get_image_size(port)
				TMAX_X = tsize[0]
				TMAX_Y = tsize[1]
				tgtpixels = graphics.get_pixels(port)
				inv_transform = inverse_transform_posn(frame)
				# for y in range(MAX_Y):
					# for x in range(MAX_X):
						# col = get_depth(x,y,count)
						# if(col>255*limit):
							# col = 999
						# else:
							# col = frame.z1 + (frame.z2 - frame.z1) * col
						# if col<=255:
							# transposn = transform(Posn(x,y))
							# if(transposn.x>=0 and transposn.y>=0 and transposn.x<TMAX_X and transposn.y<TMAX_Y):
								# tgtpixels[transposn.x, transposn.y] = (col,col,col)
				#sorry, no supersampling. Takes long enough as it is.
				for y in range(TMAX_Y):
					for x in range(TMAX_X):
						orig = inv_transform(Posn(x,y))
						rx = round(orig.x)
						ry = round(orig.y)
						if (rx>=0 and ry>=0 and rx<MAX_X and ry<MAX_Y): #within bounds
							col = get_depth(rx, ry, count)
							if(col>255*limit):
								col = 999
							else:
								col = round(frame.z1*255 + (frame.z2 - frame.z1) * col)
							if(col<=255):
								#tgtpixels[x,y] = (col, col, col)
								tgtpixels[x,y] = (min(col, tgtpixels[x,y][0]),min(col, tgtpixels[x,y][1]),min(col, tgtpixels[x,y][2]))
				graphics.pixels_to_canvas(port)
Esempio n. 7
0
File: runes.py Progetto: 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)