Last active
August 29, 2015 14:23
-
-
Save ahihi/9cd0c4ea4ffbedf33c96 to your computer and use it in GitHub Desktop.
Rainbow Sierpinski triangles (plasmatik colorx)
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
SYMBOL = "✿" # change if your font lacks the flower :( | |
import itertools | |
import shutil | |
import sys | |
import time | |
import colorsys | |
from math import atan2, cos, pi, sin, sqrt | |
w = shutil.get_terminal_size()[0] | |
n1 = w//2 + 1 | |
n2 = w - n1 - 2 | |
x = n1*[0] + [1] + n2*[0] | |
get = lambda i: x[i] if 0 <= i < len(x) else 0 | |
ns = lambda i: get(i-1) + get(i+1) | |
xc = lambda r, g, b: int(16 + (r * 36) + (g * 6) + b) | |
hv = lambda h, v: xc(*[int(m*5) for m in colorsys.hsv_to_rgb(h % 1, 1, v)]) | |
rot = lambda t, x, y: (lambda a, r: (r * cos(a), r * sin(a)))(atan2(y, x) + t, sqrt(x*x + y*y)) | |
vs = lambda k, amp, phs, a: lambda x, y: amp * sin(k * rot(-a, x, y)[0] + phs) | |
c = lambda b: lambda x, y: (lambda *pss: round(hv(sum(vs(*ps)(x, y) for ps in pss), b)))( | |
(0.079, 0.5, 0.0, -pi/2), (0.088, 0.4, 2.0, pi/5), (0.17, 0.4, 1.2, pi/32), (0.09, 0.3, -0.4, -pi/7) | |
) | |
for l in itertools.count(): | |
for k in range(len(x)): | |
if x[k]: print("\033[38;5;" + str(c(1)(k, l)) + "m" + SYMBOL + "\033[0m", end="") | |
else: print(" ", end="") | |
print() | |
x = [int(ns(i) == 1) for i in range(len(x))] | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment