Advertisement
Guest User

clockwise_90

a guest
Nov 26th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. """This is a small program to turn a picture 90 degrees clockwise.
  2. 这是一个将一副图片按顺时针方向转90度的程序,请帮忙修改一下。错误是如下的内容。
  3. Please help me to find out where I was wrong. Thank you!
  4. """
  5. import media
  6. room = media.load_picture("room.jpg") #room.jpg is a 470*400 pixels pic(any else the same)
  7. width = media.get_width(room)
  8. height = media.get_height(room)
  9. new = media.create_picture(height, width, media.white) #to create a new picture, width=>former height,height=>width
  10. for y in range(0,height):   #load height of room
  11.     for x in range(0,width):    #load width of room
  12.         from_p = media.get_pixel(room,x,y) #get pixel of room,but not in (room, x, y)
  13.         to_p = media.get_pixel(new,(height-y), x )    #get pixel of new, in (new, x, y) row
  14.         media.set_color(to_p, media.get_color(from_p)) #set color of the new one
  15. media.show(new)    
  16.  
  17. """
  18. Error Info:
  19.  
  20. Python 2.7.3 (default, Aug  1 2012, 05:14:39)
  21. [GCC 4.6.3]
  22. Type "help", "copyright", "credits" or "license" for more information.
  23. [evaluate turn90.py]
  24. Traceback (most recent call last):
  25.  File "/usr/lib/wingide-101-4.1/src/debug/tserver/_sandbox.py", line 9, in <module>
  26.  File "/usr/local/lib/python2.7/dist-packages/pygraphics/media.py", line 49, in get_pixel
  27.    return pic.get_pixel(x, y)
  28.  File "/usr/local/lib/python2.7/dist-packages/pygraphics/picture.py", line 203, in get_pixel
  29.    return pixel.Pixel(self.pixels, x, y)
  30.  File "/usr/local/lib/python2.7/dist-packages/pygraphics/pixel.py", line 20, in __init__
  31.    self.pixels[x, y]
  32. IndexError: image index out of range
  33.  
  34. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement