Created
October 20, 2012 20:05
-
-
Save 2bt/3924596 to your computer and use it in GitHub Desktop.
ASCII metaball silhouette
This file contains hidden or 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 sys, time, math, random | |
def get_foo(x, y): | |
d = 0 | |
for a, b, c in points: | |
d += c / (1 + (x - a)**2 + (y - b)**2) | |
return d | |
def march(a, b, c, d): | |
return " ^ |;/ ;|\\_\\/ "[a + b*2 + c*4 + d*8] | |
t = 10 | |
while 1: | |
t += 0.5 | |
points = [ | |
( 40 + 30 * math.sin(t * (0.07 + i*0.01)), | |
24 + 24 * math.cos(t * (0.041 + (i*0.1)**2 )), | |
1 + math.sin(t * (0.051 + i*0.013 )) | |
) for i in range(4) | |
] | |
s = "" | |
for y in range(0, 48, 2): | |
for x in range(80): | |
s += march( | |
0.1 > get_foo(x, y) > 0.01, | |
0.1 > get_foo(x+1, y) > 0.01, | |
0.1 > get_foo(x, y+2) > 0.01, | |
0.1 > get_foo(x+1, y+2) > 0.01 | |
) | |
s += "\n" | |
sys.stdout.write("\x1b[2J\x1b[1;1H" + s) | |
time.sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment