summaryrefslogtreecommitdiff
path: root/mandelgen2.py
blob: 26a3baa256793e3eec5e21d1238a2a265f682435 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/python
#written for py3.5.2
from drawille import Canvas
import cmath
import math
import curses
from PIL import Image
import argparse
def init () :
	global args
	parser = argparse.ArgumentParser()
	parser.add_argument("-xm", help="max x",
                    type=int)
	parser.add_argument("-ym", help="max y",
                    type=int)
	parser.add_argument("-xt", help="tran x",
                    type=float)
	parser.add_argument("-yt", help="tran y",
                    type=float)
	parser.add_argument("-s", help="scale",
                    type=float)
	parser.add_argument("-b", help="braile",
                    action="store_true")
	parser.add_argument("-t", help="threshhold of calcs",
                    type=int)
	args = parser.parse_args()
	global xt
	xt = args.xt
	global yt
	yt = args.yt
	global xs
	xs = args.s
	global ys
	ys = args.s
	global xm
	xm = args.xm
	global ym
	ym = args.ym
	global thr
	thr = args.t
	global vals
	vals = [[]]
	if (args.b) :
		global canvas
		canvas = Canvas()
	else :
		global img
		global pix
		img = Image.new('RGB', (xm, ym))
		pix = img.load()
def end () :
	if (args.b) :
		print(canvas.frame())
	else :
		img.save("mandel","PNG")
	return
print("initializing....")
init()
print("crunching....")
for xi in range(0, xm, 1) :
	for yi in range(0, ym, 1) :
		c = complex(xt + (xs * xi), yt - (ys * yi))
		n = complex(0, 0)	
		t = thr
		for i in range(0, thr, 1) :
			if (math.sqrt((n.real * n.real) + (n.imag * n.imag)) >= 2 ) :
				t = i
				break
			else :
				n = n * n + c
		if (args.b) :
			if (t != thr) :
				canvas.unset(xi, yi)
			else :
				canvas.set(xi, yi)
		else :
			color = int(255 - (255 * t / thr))
			pix[xi, yi] = (color, color, color)
	if (xi % 100 == 0) :
		print(xi)
		print(t)
print("saving....\b")
end()