[Tutor] Help with photo wall

Luke Paireepinart rabidpoobear at gmail.com
Wed Jun 24 14:51:27 CEST 2009


bob gailer wrote:
> Please start a new thread with a relevant topic rather than adding to 
> an existing thread.
seconded
>
> hello all,
>  I am currently making a birthday prezzie for someone (deadline is 
> Thursday night). the basic idea is a wall of photos that you can move 
> about to view different ones using a joystick and press the joystick 
> button to hear a roughly five second commentary that is individual for 
> each photo. I currently have a wall of photos that you can navigate 
> using the wasd keys. all help in creating the final product in time 
> would be appreciated and you would be mentioned in the credits by a 
> nickname (IE. cyberjacob). I am currently using the pygame library. 
> any more detail can be supplied including full source code,
> thanks everyone, i need all the help I can get to finish this in time
> please reply ASAP
> thanks once again
> cyberjacob
>
> Personally I kinda doubt that anyone would tackle this for free.
Why can't you do it yourself?  This shouldn't be a very big stretch if 
you've already got it working for WASD.
Just use the joystick module of Pygame, and get the X axis movement, if 
it's positive and larger than a certain threshold, move to the right, 
and if it's negative and larger than the threshold, move left.  As for 
playing the sound, just use pygame.music() to stream it from disk, make 
a new folder called "commentary" where each item has the same name as 
the picture it's associated with.
So
root dir
    images
       foobar.jpg
       foobaz.bmp
    sounds
       foobar.mp3
       foobaz.mp3

then it's simple to just go "ok i'm currently at image "foobar.jpg".  I 
want to load a sound to play for it:
import os
soundfile = os.path.join("sounds", os.path.splitext(current_img)[0]+".mp3")
pygame.music.load(soundfile) # may not be correct function names
pygame.music.play()

So your main program will look like this (pseudocode warning!)

import os, pygame

init screen
#render wall

motion = 0 # how fast (in pixels) we shift the wall each frame.
speed = 2 # a multiplier for motion (i think joysticks report axis 
position as float from 0 to 1, this allows you to scroll faster.)
thresh = 0.5
while 1:
    pygame.clock.tick(60) #lock your framerate 
    #shift wall "motion" pixels in the x axis.
    refresh screen.
   
    for event in pygame.event.get():
        if event.type == JOYSTICKDOWN and event.button == BUTTONIWANT:
           #obviously for this to work must know current image. should 
not be hard to do.
            soundfile = os.path.join("sounds", 
os.path.splitext(current_img)[0]+".mp3")
            pygame.music.stop()
            pygame.music.load(soundfile) # may not be correct function names
            pygame.music.play()

       elif event.type == JOYSTICKMOTION:
           x = get_x_axis_of_joystick()
           if abs(x) > thresh:
               motion = x * speed
               pygame.music.stop() # unless you want commentary to keep 
playing while they scroll.
 


More information about the Tutor mailing list