box.py 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/local/bin/python3
  2. from time import sleep
  3. import curses
  4. import random
  5. screen = curses.initscr()
  6. curses.noecho()
  7. curses.cbreak()
  8. screen.keypad(True)
  9. curses.curs_set(False)
  10. try:
  11. screen.border(0)
  12. height = random.randint(5, 20)
  13. width = height * 2
  14. maxy = curses.LINES - 1 - height
  15. maxx = curses.COLS - 1 - width
  16. x = random.randint(1, maxx)
  17. y = random.randint(1, maxy)
  18. xstep = 1; ystep = 1
  19. while 1:
  20. box1 = curses.newwin(height, width, y, x)
  21. box1.box()
  22. location = "x,y: %d, %d" % (x, y)
  23. box1.addstr(height // 2, width // 2 - len(location) // 2, location)
  24. screen.refresh()
  25. box1.refresh()
  26. if x > maxx or x < 1:
  27. xstep *= -1
  28. if y > maxy or y < 1:
  29. ystep *= -1
  30. x += xstep
  31. y += ystep
  32. screen.clear()
  33. sleep(0.1)
  34. finally:
  35. curses.nocbreak()
  36. screen.keypad(False)
  37. curses.echo()
  38. curses.endwin()