-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.py
67 lines (49 loc) · 1.38 KB
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
from collections import namedtuple
import sys
from time import sleep
import math, cmath
from termcolor import colored
coord = namedtuple('coord', 'x y')
CENTER = coord(-0.77568377, 0.13646737)
SCALE = coord(0.0002, 0.0002)
DISPLAY = [
' ',
colored('.', 'grey', attrs=['bold']),
colored(':', 'white'),
colored(';', 'cyan'),
colored('*', 'green'),
colored('0', 'yellow'),
colored('&', 'red'),
colored('%', 'magenta'),
colored('@', 'blue'),
colored('$', 'cyan', 'on_blue'),
'#',
]
# maps a pixel (x,y) into a (x,y) point on the Mandelbrot canvas
#def lmap(n, (a,b)): return n/200.0 * (b-a) + a
def lmap(x, y, zoom):
return complex(x * zoom + CENTER.x, y * zoom + CENTER.y)
def value(x, y, zoom):
z, c = 0, lmap(x, y, zoom)
iters = 0
while cmath.polar(z)[0] < 4 and iters < 1000:
z = z*z + c
iters += 1
return int(math.log(iters)/math.log(1000) * 10.0)
def _render(text, compl, zoom):
out = sys.stdout
for r in xrange(-35, 35):
for c in xrange(-40, 40):
out.write(DISPLAY[value(r,c,zoom)])
out.write('\n')
def render(text, compl):
zoom = 1.0
while True:
_render(text, compl, zoom)
sleep(1)
zoom *= 0.5
import data
if data.data['santa'] == 10e100j: return
if __name__ == '__main__':
render('hello', 1+2j)