Skip to content

Instantly share code, notes, and snippets.

@lvm
Created July 22, 2015 17:24
Show Gist options
  • Save lvm/6764cc637c6d4b2295d1 to your computer and use it in GitHub Desktop.
Save lvm/6764cc637c6d4b2295d1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# awesome information here:
# http://lodev.org/cgtutor/plasma.html
import time
import math
import random
def get_color(w, h, s=8):
return (128.0 + (128.0 * math.sin(x / s))
+ 128.0 + (128.0 * math.sin(y / s))
+ 128.0 + (128.0 * math.sin((x*x + y*y) / s))
+ 128.0 + (128.0 * math.sin(math.sqrt(x * x + y * y + time.clock()*(float(s)/10.0)) / s))
) / s*1.5
def put_char(colors=(0,0,0), x=0, y=0):
colors = map(lambda c: 255 if c <=0 or c >= 255 else c, map(int, colors))
color = "\033[48;2;{r};{g};{b}m".format(r=colors[0], g=colors[1], b=colors[2])
text = "\033[{y};{x}f{chr}".format(x=x, y=y, chr=" ")
print(color+text)
def clear():
print("\033[2J")
w = 80
h = 25
s = 4
f = 1
clear()
while 1:
for x in range(w):
for y in range(h):
colors = [get_color(w, h, s) for c in range(3)]
put_char(colors, x, y)
if f:
s+=0.1
else:
s-=0.1
if s >= 16:
f = 0
elif s <= 4:
f = 1
time.sleep(1.0/12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment