Download presentation
Presentation is loading. Please wait.
1
Or just artificialworlds.net/blog
More info: Or just artificialworlds.net/blog Funniest Photo Game Take the funniest photo Take a photo using our photo booth, and we will choose the funniest one at the end of the Jam! Instructions Choose a costume by pressing ←and → Take a photo by pressing SPACE or clicking the mouse Press G to see the gallery Click the Camera icon at the top to start again Making new costumes Make a new costume in The Gimp. The images MUST be 1280x720 pixels in size, and saved as .png format. Note: you MUST choose “Image” → “Mode” → “Indexed Color” or it won't work. Keeping photos If you want to keep your photos, ask us – we can upload them to our blog, or put them on a USB disk if you have one. We will update our blog at artificialworlds.net/blog after the Jam. Program See the other sheet for our code!
2
Funniest Photo Game – the Program
import io import picamera from PIL import Image import time import pygame import subprocess import os class PhotoBooth: def __init__( self, camera ): self.camera = camera self.costumes = os.listdir( 'costumes' ) self.current_overlay = None self.cos_num= 0 self.current_costume = None self.set_up_camera() self.change_costume(0) def set_up_camera(self): self.camera.resolution = ( 1280, 720 ) self.camera.framerate = 24 self.camera.start_preview() def change_costume(self, change): self.cos_num += change self.cos_num = self.cos_num%len(self.costumes) self.current_costume = Image.open( 'costumes/'+self.costumes[self.cos_num]) self.overlay(self.current_costume, 128) def overlay(self, image, alpha): pad = Image.new('RGB', (((image.size[0] + 31) // 32) * 32, ((image.size[1] + 15) // 16) * 16)) pad.paste(image, (0, 0)) if self.current_overlay is not None: self.camera.remove_overlay(self.current_overlay) self.current_overlay = camera.add_overlay(pad.tostring(), size=image.size) self.current_overlay.alpha = alpha self.current_overlay.layer = 3 def take_photo(self): stream = io.BytesIO() camera.capture( stream, format='jpeg' ) stream.seek( 0 ) captimg = Image.open( stream ) imgrgba = self.current_costume.convert("RGBA") captimg.paste( imgrgba, ( 0, -100 ), imgrgba ) self.overlay(captimg, 255) captimg.save( 'gallery/photo%d.png' % time.time().real ) def run(self): while True: for event in pygame.event.get(): if event.type == pygame.QUIT: return if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.change_costume(1) if event.key == pygame.K_RIGHT: self.change_costume(-1) if event.key == pygame.K_SPACE: self.take_photo() if event.key == pygame.K_ESCAPE: return if event.key == pygame.K_g: subprocess.call('ls gallery/*.png | head -1 | xargs xdg-open', shell = True) if event.type == pygame.MOUSEBUTTONDOWN: self.take_photo() pygame.init() pygame.display.set_mode() with picamera.PiCamera() as camera: booth = PhotoBooth( camera ) booth.run()
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.