import pygame
from PIL import Image
import numpy as np
def sepcolors(a,b,c, imgname):
img = Image.open(imgname)
ary = np.array(img)
for x in ary:
for v in x:
pov = (np.sum(v))//3
v[c] = pov
v[a] = 0
v[b] = 0
return ary
red = sepcolors(1,2,0,'image0.jpg')
green = sepcolors(0,2,1,'image1.jpg')
im = Image.fromarray(np.add(red,green))
im.save("image3D.bmp")
pygame.init()
black = (0,0,0)
X = 480
Y = 640
locationX = 0
locationY = 0
update = False
display_surface = pygame.display.set_mode((X, Y ))
pygame.display.set_caption('Image')
image = pygame.image.load('image3D.bmp')
while True :
if update == True:
red = np.roll(red, locationX, axis=1) # x
red = np.roll(red, locationY, axis=0) # y
im = Image.fromarray(np.add(red,green))
im.save("image3D.bmp")
image = pygame.image.load('image3D.bmp')
display_surface.fill(black)
display_surface.blit(image, (20, 20))
for event in pygame.event.get() :
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
locationX = -1
if event.key == pygame.K_RIGHT:
locationX = 1
if event.key == pygame.K_UP:
locationY = -1
if event.key == pygame.K_DOWN:
locationY = 1
update = True
else:
update = False
locationY = 0
locationX = 0
if event.type == pygame.QUIT :
pygame.quit()
quit()
pygame.display.update()
Comments