예제 #1
0
from pytermfx import Terminal, Color
from pytermfx.tools import TerminalApp
from random import random, randint, choice
from time import sleep

MAX_STEPS = 800
N = 5
TURN_CHANCE = 0.08
CHARS = list("║═╚╝╔╗")
# CHARS = list("│─╰╯╭╮")

t = Terminal()
t.cursor_set_visible(False)
t.add_resize_handler(lambda: t.clear().flush())
i = MAX_STEPS
pipes = []


# choose a connector to use for a given direction
def connector(vx0, vy0, vx1, vy1):
    if vx0 < vx1:
        if vy0 < vy1:
            return CHARS[4]
        return CHARS[2]
    elif vy0 < vy1:
        return CHARS[5]
    return CHARS[3]


class Pipe:
    def __init__(self, x, y, color):
예제 #2
0
radius = 5 
flow = 0.5
buffer = None
damage = None
mouse = None

def clip(x, lo, hi):
    return max(lo, min(hi, x))

def resize():
	global buffer, damage, t
	buffer = [0 for i in range(t.w * t.h)]
	damage = [True for i in range(t.w * t.h)]
	t.style(Color.hex(0).bg()).clear_box(0, 0, t.w, t.h)
	t.flush()
t.add_resize_handler(resize)
resize()

def spray(cur_x, cur_y, intensity):
	global buffer, damage
	for x in range(cur_x - radius, cur_x + radius + 1):
		for y in range(cur_y - radius // 2, cur_y + radius//2 + 1):
			i = clip(y, 0, t.h-1) * t.w + clip(x, 0, t.w-1)
			dx = x - cur_x
			dy = y - cur_y
			dist = max(0, 1 - sqrt(dx ** 2 + dy ** 2) / radius)
			buffer[i] = min(1, max(0, buffer[i] + dist * intensity * random()))
			damage[i] = True

def draw_buffer():
	global buffer, damage, t