Created
July 27, 2018 22:56
-
-
Save isaac-ped/35e9bffafed4722ab414da2d701c9e21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import logging | |
import re | |
import random | |
import curses | |
import time | |
import locale | |
import codecs | |
import sys | |
SIZE = [] | |
#(curses.LINES - 1, curses.COLS - 1) | |
seeds = {} | |
logging.basicConfig(filename='trip.log',level=logging.DEBUG) | |
def log(*args, **kwargs): | |
logging.info(*args, **kwargs) | |
def new_seed(stdscr): | |
x = random.randint(SIZE[0] * 1 / 4, SIZE[0] * 3 / 4) | |
y = random.randint(SIZE[1] * 1 / 4, SIZE[1] * 3 / 4) | |
seeds[(x, y)] = [0, curses.color_pair(random.randint(0, curses.COLORS * 2))] | |
def get_pts(x, y, r): | |
pts = [] | |
#for r in range(rr): | |
for i in range(r+1): | |
pts.append((x + i, y + r - i)) | |
pts.append((x - i, y + r - i)) | |
pts.append((x - r + i, y - i)) | |
pts.append((x + r - i, y - i)) | |
return pts | |
def draw_pts(stdscr, pts, c): | |
x_max, y_max = stdscr.getmaxyx() | |
for pt in pts: | |
if pt[0] < SIZE[0] and pt[1] < SIZE[1] \ | |
and pt[0] > 0 and pt[1] > 0: | |
log("%d, %d : %d", pt[0], pt[1], c) | |
stdscr.addstr(pt[1], pt[0], '*', c) | |
def increase_radius(): | |
for k in seeds: | |
seeds[k][0] += 1 | |
def run(stdscr): | |
curses.start_color() | |
curses.use_default_colors() | |
for i in range(0, curses.COLORS): | |
curses.init_pair(i + 1, i, -1) | |
y, x =stdscr.getmaxyx() | |
SIZE.extend([x, y]) | |
new_seed(stdscr) | |
while 1: | |
for (x, y), (r, c) in seeds.items()[:]: | |
pts = get_pts(x, y, r) | |
if random.random() < .15: | |
new_seed(stdscr) | |
if (random.random() < .05 and len(seeds) > 1) \ | |
or len(seeds) > 10: | |
k = random.choice(seeds.keys()) | |
del seeds[k] | |
draw_pts(stdscr, pts, c) | |
stdscr.refresh() | |
increase_radius() | |
time.sleep(.1) | |
#stdscr.clear() | |
if __name__ == '__main__': | |
curses.wrapper(run) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment