Created
July 25, 2023 17:40
-
-
Save mgodf89/f2024d626dd149e0c6e5a17620ac6339 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
# michael.godfrey@digitalasset.com | |
# Apache 2.0 License | |
import time, math, random | |
from json import encoder | |
chars,x,y,_x,_y,idx,_i,theta,W,H = 'ABCDEF', 0,0,0,0,0,0,0,63,63 | |
loop, LINE_UP, LINE_CLEAR = range(1, len(chars) + 1), '\033[1A', '\x1b[2K' | |
grid = [[(0,-1) for y in range(H)] for x in range(W)] | |
def rotate(x,y,theta): | |
_cos, _sin, rx, ry = math.cos(math.radians(theta)), math.sin(math.radians(theta)), 0.5*W - x - 0.5, 0.5*W - y - 0.5 | |
return max(0,min(W - 1, math.floor((_cos * rx - _sin * ry) + 0.5*W))), max(0,min(W - 1, math.floor((_sin * rx + _cos * ry) + 0.5*W))) | |
def grid_fn(x,y,i, theta, idx): | |
x,y = rotate(x,y,theta) | |
if grid[x][y][1] >= i: return f' {[" ", "k", "G"][math.floor(i/idx)%3]}' | |
if grid[x][y][0] & (grid[x][y][1] - i >=-128): return f' {["*", "^", "$"][math.floor(i/idx)%3]}' | |
if grid[x][y][0] & (grid[x][y][1] - i >=-96): return ' x' | |
if grid[x][y][0] & (grid[x][y][1] - i >=-64): return ' O' | |
if grid[x][y][0] & (grid[x][y][1] - i >=-32): return ' 8' | |
if grid[x][y][0] & (grid[x][y][1] - i >=-16): return ' @' | |
if grid[x][y][0]: return f' {"#" if random.random() > 0.5 else " "}' | |
return ' .' | |
def idx_count(): | |
global idx | |
idx=idx+1 | |
return idx | |
def rt(): | |
global _x, _y | |
_x, _y = _x+1, _y | |
grid[_x][_y] = (1,idx_count()) | |
def lt(): | |
global _x,_y | |
_x, _y = _x-1, _y | |
grid[_x][_y] = (1,idx_count()) | |
def up(): | |
global _x,_y | |
_x,_y = _x, _y + 1 | |
grid[_x][_y] = (1,idx_count()) | |
def dn(): | |
global _x,_y | |
_x, _y = _x, _y-1 | |
grid[_x][_y] = (1,idx_count()) | |
def up2(): up();up() | |
def dn2(): dn();dn() | |
def rt2(): rt();rt() | |
def lt2(): lt();lt() | |
if __name__=="__main__": | |
ex = lambda ft:[fn() for fn in ft] | |
UP = lambda :ex([rt, rt, up, up, lt, lt, up, up, up, up, rt, rt, dn, dn, rt, rt, up, up, rt, rt, dn, dn, dn, dn, lt, lt, dn, dn, rt, rt]) | |
RT = lambda :ex([up, up, rt, rt, dn, dn, rt, rt, rt, rt, up, up, lt, lt, up, up, rt, rt, up, up, lt, lt, lt, lt, dn, dn, lt, lt, up, up]) | |
DN = lambda :ex([lt, lt, dn, dn, rt, rt, dn, dn, dn, dn, lt, lt, up, up, lt, lt, dn, dn, lt, lt, up, up, up, up, rt, rt, up, up, lt, lt]) | |
LT = lambda :ex([dn, dn, lt, lt, up, up, lt, lt, lt, lt, dn, dn, rt, rt, dn, dn, lt, lt, dn, dn, rt, rt, rt, rt, up, up, rt, rt, dn, dn]) | |
Right = lambda:ex([UP, rt2, RT, up2, RT, lt2, DN]) | |
Left = lambda:ex([DN, lt2, LT, dn2, LT, rt2, UP]) | |
Up = lambda:ex([RT, up2, UP, rt2, UP, dn2, LT]) | |
Down = lambda:ex([LT, dn2, DN, lt2, DN, up2, RT]) | |
ex([Right, up2, Up, rt2, Up, dn2, Left ]); rt2() | |
ex([Up, rt2, Right, up2, Right, lt2, Down ]); up2() | |
ex([Up, rt2, Right, up2, Right, lt2, Down ]); lt2() | |
ex([Left, dn2, Down, lt2, Down, up2, Right]) | |
with open("grid_export.json","w+") as f: f.write(encoder.JSONEncoder().encode(grid)) | |
while True: | |
_i= _i+15 | |
mode = math.floor(_i/idx)%3 | |
i = (idx if mode==0 else idx - _i if mode==1 else _i) % idx | |
theta = theta if mode!=0 else theta + (90/idx) * 30 | |
print(''.join(['|'+''.join([ f"{grid_fn(x,H-y-1,i,theta, idx)}" for x in range(W)]) + "|\n" for y in range(H)])); time.sleep(0.0001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment