Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import math, pygame, pygame.locals, sys
- scr_x = 600
- scr_y = 600
- max_x = 30
- max_y = 30
- color = (255, 255, 255)
- def f(x, y):
- global scr_x, scr_y, max_x, max_y
- return scr_x / 2 + ((scr_x / 2) * x) / max_x, scr_y / 2 + ((scr_y / 2) * -y) / max_y
- def left(x, y):
- if x * y > 0: return -x, y
- return x, -y
- def right(x, y):
- if x * y > 0: return x, -y
- return -x, y
- def main(argv):
- global scr_x, scr_y, color
- pygame.init()
- screen = pygame.display.set_mode((scr_x, scr_y))
- seq = []
- for i in range(int(argv[0])):
- out = []
- v = 0
- for x in seq:
- out.append(v)
- v = (v + 1) % 2
- out.append(x)
- out.append(v)
- seq = out
- dict_x, dict_y = 1, 1
- pos_x, pos_y = 1, 1
- pygame.draw.line(screen, color, f(0, 0), f(1, 1));
- for x in seq:
- if x == 0: dict_x, dict_y = left(dict_x, dict_y)
- else: dict_x, dict_y = right(dict_x, dict_y)
- pygame.draw.line(screen, color, f(pos_x, pos_y), f(pos_x + dict_x, pos_y + dict_y))
- pos_x += dict_x
- pos_y += dict_y
- pygame.display.flip()
- while True:
- event = pygame.event.wait()
- if event.type == pygame.locals.QUIT or event.type == pygame.KEYDOWN:
- break
- if __name__ == '__main__':
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement