1

I'm currently trying to develop a psychology experiment which involves having 150 .tif images that need to be presented for 0.5sec per trial, full screen, after a noise has been heard. Each image needs to be presented at least once before being presented again. I am completing my experiment within pygame.

I've been thinking about saving all the images into a directory and then pulling them each out one by one. Does this seem like a good idea?

I'm very new to programming and would appreciate any help/links to similar questions. If I'm missing any relevant information please let me know.

Thank you!

Delly
  • 123
  • 1
  • 10
  • Welcome to Stack Overflow. Please ask only one specific question at a time and also try to solve your problem on your own first and then show us what's not working. Take a look at the [help center](https://stackoverflow.com/help/how-to-ask) and [this checklist](https://meta.stackoverflow.com/q/260648/6220679). – skrx Nov 11 '17 at 08:02

1 Answers1

0
  1. Use the glob module to get a list of your image filenames: https://pymotw.com/3/glob/index.html

  2. Loop over this list of filenames, load them with pygame.image.load and append the resulting images/pygame.Surfaces to a list.

  3. Shuffle the list, create an index variable (index = 0) and assign the image at the current index to another variable, e.g. current_image = image_list[index].

  4. Use a timer variable to increment the index and swap the image after the desired time interval check out the pygame.time.get_ticks, set_timer or delta time solutions here.

  5. If the index is >= the length of the list, reset it to 0 and shuffle the list again.

skrx
  • 19,980
  • 5
  • 34
  • 48
  • Hi I've been trying to follow your advice to the best of my ability but I'm stuck at step 2. This is my code: `import pygame, glob types= ('*.tif') artfile_names= [ ] for files in types: artfile_names.extend(glob.glob(files)) print(artfile_names) for artworks in artfile_names: pygame.image.load(str(artfile_names))` but it gives the error of not being able to open my files. Could you give a reason as to why? – Delly Nov 12 '17 at 00:03