I have a home work assignment to make a photo gallery using the cImage module.

It is supposed to have a forward and a backward button, and display images named picture0, picture1, picture2... so that after you click the forward button on the last picture it will go back to the first picture.
The program should have an input parameter n, where n+1 is the number of pictures displayed in the gallery.

I don't know how to get started. So, if anyone has any hints or tips on how to get started that would be great.
More specifically, I am looking for suggestions on the general steps necessary, or how to break down the problem into functions.

You would want some kind of input for detecting whether the user wants to go left or right. Consider using a loop to load the images into an array. For example, if you have the following file structure.

-main.py
-Pictures:
     -pic0.png
     -pic1.png
     -pic2.png
     -pic3.png

You could load the images like so:

import pygame
from pygame.locals import *

pygame.init()

print 'ENTER HOW MANY IMAGES IN GALLERY'
n=int(raw_input())


Pics=[]
BasePath="./Pictures/pic"
for i in range(0, n):
	print i
	Pics.append(pygame.image.load(BasePath+str(i)+".png"))
	print Pics[i]

I've attatched a Zip with the stuff in it so you can take a look if you want. I used pygame just for the image loading. The actual part of the program that loads images into the list is very short.

I even included asking the user how many images there were. However, you will need to be able to check for an error if the user puts in a value of n that is greater than the amount of images in the pictures folder or wherever.

You should have a variable which determines which number image you are on. This number should obviously change with user input (left or right adding or subtracting one), but making sure that when you hit zero, going down will make you go up to the top number, and when you get to the top, going round to zero again.

With regards to entering how many pictures are in the gallery, you can easily relate this to the range in my for loop.

Write out a code that works, then check back through and make it shorter. "Ooooh I could use a for loop there"..."I don't need that bit"...etc.

That should be plenty enough to get you started. Check back if you need more help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.