Skip to content

Instantly share code, notes, and snippets.

@acspike
Created December 18, 2012 04:49
Show Gist options
  • Save acspike/4325102 to your computer and use it in GitHub Desktop.
Save acspike/4325102 to your computer and use it in GitHub Desktop.
Simple hands-free (with arduino-powered, foot-actuated, usb spacebar) workflow for stop motion animators.
from VideoCapture import Device
import pygame
import datetime
import glob
cam = Device()
pic_dir = './'
pic_ext = '.jpg'
pics = glob.glob(pic_dir+'*'+pic_ext)
background_color = (255,255,255)
(width, height) = (640,480)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Stills')
screen.fill(background_color)
pygame.display.flip()
index = -1
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
stamp = datetime.datetime.strftime(datetime.datetime.now(),'%Y%m%d%H%M%S%f')
path = pic_dir + stamp + pic_ext
cam.saveSnapshot(path)
img = pygame.image.load(path)
pics.append(path)
index = -1
screen.blit(img, (0,0))
pygame.display.flip()
elif event.key == pygame.K_LEFT:
index -= 1
try:
path = pics[index]
except IndexError:
index = -1
path = pics[index]
img = pygame.image.load(path)
screen.blit(img, (0,0))
pygame.display.flip()
elif event.key == pygame.K_RIGHT:
index += 1
try:
path = pics[index]
except IndexError:
index = 0
path = pics[index]
img = pygame.image.load(path)
screen.blit(img, (0,0))
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment