Skip to content

Instantly share code, notes, and snippets.

@2bt
Created October 20, 2012 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2bt/3924596 to your computer and use it in GitHub Desktop.
Save 2bt/3924596 to your computer and use it in GitHub Desktop.
ASCII metaball silhouette
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