Browse Source

First commit

Pat Lathem 1 year ago
commit
341c7949e8
1 changed files with 44 additions and 0 deletions
  1. 44 0
      box.py

+ 44 - 0
box.py

@@ -0,0 +1,44 @@
+#!/usr/local/bin/python3
+from time import sleep
+import curses
+import random
+
+screen = curses.initscr()
+curses.noecho()
+curses.cbreak()
+screen.keypad(True)
+curses.curs_set(False)
+
+try:
+    screen.border(0)
+    height = random.randint(5, 20)
+    width = height * 2
+    maxy = curses.LINES - 1 - height
+    maxx = curses.COLS - 1 - width
+    x = random.randint(1, maxx)
+    y = random.randint(1, maxy)
+    xstep = 1; ystep = 1
+
+    while 1:
+        box1 = curses.newwin(height, width, y, x)
+        box1.box()
+        location = "x,y: %d, %d" % (x, y)
+        box1.addstr(height // 2, width // 2 - len(location) // 2, location)
+        screen.refresh()
+        box1.refresh()
+
+        if x > maxx or  x < 1:
+            xstep *= -1
+        if y > maxy or y < 1:
+            ystep *= -1
+
+        x += xstep
+        y += ystep
+        screen.clear()
+        sleep(0.1)
+
+finally:
+    curses.nocbreak()
+    screen.keypad(False)
+    curses.echo()
+    curses.endwin()