From Lupyan Lab
Jump to: navigation, search

Make a square and play with it

import time
import sys
from psychopy import visual,event,core
win = visual.Window([400,400],color="black", units='pix')
square = visual.Rect(win,lineColor="black",fillColor="blue",size=[100,100])
core.wait(.5) #pause for 500 ms (half a second)

Go through each line and understand what it does. Now,

  1. Make the square appear for 1.5 secs, then for 30 ms
  2. Make it red
  3. Show a red square for 1 s, then switch it to blue and show it for 1 s
  4. Show the following sequence: blue, red, blue, red, blue, red
  5. Show a red square for 1 s then change its orientation by 45-deg
  6. Now make a square rotate continuously, one full revolution (360 degrees) per second
  7. Make a rotating square stop rotating when you press the 's' key
  8. Make a square stop rotating when you press 's' and then start rotating again when you press 'r'
  9. Display a blue square and increase its width by 10 pixels whenever the user presses the left-arrow key. Decrease the width by 10 pixels when the user presses the right-arrow key
  10. Now make the shape decrease/increase width by 10% with each keypress instead of 10 pixels
  11. Show two rotating squares simultaneously, one left of center rotating clockwise, the other right of center, rotating counterclockwise
  12. Do something that's not listed here (e.g., make it a pentagon instead of a square, make the color track the current price of Apple stock, etc.)

Solutions to exercise 1

Personal tools
Download and Install
Notes for each class - will be updated ~week before each class.
Programming Exercises
Quick reference