Advertisement
CodeCrusader

Python program that generates an infinite stream of colorful, swirling shapes on the terminal

Jan 2nd, 2023
108
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | Source Code | 1 0
  1. import curses
  2. import time
  3. import random
  4.  
  5. def main(stdscr):
  6.     curses.use_default_colors()
  7.     for i in range(0, curses.COLORS):
  8.         curses.init_pair(i + 1, i, -1)
  9.  
  10.     stdscr.clear()
  11.  
  12.     while True:
  13.         x = random.randint(1, curses.COLS - 2)
  14.         y = random.randint(1, curses.LINES - 2)
  15.         c = random.randint(1, curses.COLORS)
  16.         stdscr.addch(y, x, '#', curses.color_pair(c))
  17.         stdscr.refresh()
  18.         time.sleep(0.1)
  19.  
  20. curses = curses.wrapper(main)
  21.  
  22. # To try this out, you will need to run it in a terminal that supports ANSI escape codes. Simply copy and paste the code into a file and run it with Python.
  23.  
  24. # Let me know if you have any questions or if you'd like to see anything else in the comments.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement