cox_crc

Add method to existing class on the fly

Mar 8th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from psychopy import core,event,visual
  2. def rescale(self, width=0, height=0, operation='', units=None, log=True):
  3.     (old_width,old_height) = self.size
  4.     if all([height,width]):
  5.         pass
  6.     elif height:
  7.         ratio = height/old_height
  8.         width = old_width * ratio
  9.     elif width:
  10.         ratio = width/old_width
  11.         height = old_height * ratio
  12.     self.setSize([width,height],operation,units,log)
  13.  
  14. visual.ImageStim.rescale = rescale
  15.  
  16. win = visual.Window()
  17. img = visual.ImageStim(win,image='pic2.jpg') # point this to an image you have locally.
  18. img.draw()
  19. win.flip()
  20. core.wait(1)
  21.  
  22. img.rescale(width=.7)
  23. img.draw()
  24. win.flip()
  25. core.wait(1)
Advertisement
Add Comment
Please, Sign In to add comment