Skip to content

Instantly share code, notes, and snippets.

@2bt
Created October 20, 2012 20:05
Show Gist options
  • Select an option

  • Save 2bt/3924596 to your computer and use it in GitHub Desktop.

Select an option

Save 2bt/3924596 to your computer and use it in GitHub Desktop.

Revisions

  1. twobit created this gist Oct 20, 2012.
    36 changes: 36 additions & 0 deletions blob.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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)