Advertisement
p2004a

Untitled

Mar 4th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import math, pygame, pygame.locals, sys
  4.  
  5. scr_x = 600
  6. scr_y = 600
  7. max_x = 30
  8. max_y = 30
  9. color = (255, 255, 255)
  10.  
  11. def f(x, y):
  12.   global scr_x, scr_y, max_x, max_y
  13.   return scr_x / 2 + ((scr_x / 2) * x) / max_x, scr_y / 2 + ((scr_y / 2) * -y) / max_y
  14.  
  15. def left(x, y):
  16.   if x * y > 0: return -x, y
  17.   return x, -y
  18.  
  19. def right(x, y):
  20.   if x * y > 0: return x, -y
  21.   return -x, y
  22.  
  23. def main(argv):
  24.   global scr_x, scr_y, color
  25.  
  26.   pygame.init()
  27.   screen = pygame.display.set_mode((scr_x, scr_y))
  28.  
  29.   seq = []
  30.   for i in range(int(argv[0])):
  31.     out = []
  32.     v = 0
  33.     for x in seq:
  34.       out.append(v)
  35.       v = (v + 1) % 2
  36.       out.append(x)
  37.     out.append(v)
  38.     seq = out
  39.  
  40.   dict_x, dict_y = 1, 1
  41.   pos_x, pos_y = 1, 1
  42.  
  43.   pygame.draw.line(screen, color, f(0, 0), f(1, 1));
  44.   for x in seq:
  45.     if x == 0: dict_x, dict_y = left(dict_x, dict_y)
  46.     else: dict_x, dict_y = right(dict_x, dict_y)
  47.     pygame.draw.line(screen, color, f(pos_x, pos_y), f(pos_x + dict_x, pos_y + dict_y))
  48.     pos_x += dict_x
  49.     pos_y += dict_y
  50.  
  51.   pygame.display.flip()
  52.  
  53.   while True:
  54.     event = pygame.event.wait()
  55.     if event.type == pygame.locals.QUIT or event.type == pygame.KEYDOWN:
  56.       break
  57.  
  58.  
  59. if __name__ == '__main__':
  60.   main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement