File: mandelbrot.py

package info (click to toggle)
gambas3 3.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,984 kB
  • sloc: ansic: 197,178; cpp: 124,076; sh: 18,999; javascript: 7,761; sql: 5,399; makefile: 2,354; perl: 1,397; xml: 490; python: 335
file content (54 lines) | stat: -rwxr-xr-x 857 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python

import sys

MAXITER = 50
LIMIT = 4
out = sys.stdout;

def mandelbrot(w, h) :

	xmin = -1.5
	ymin = -1
	invN = 2.0 / w

	checknext = True

	for y in range(h) :
		Ci = y * invN + ymin

		for x in range(w) :
			Zr = 0.0
			Zi = 0.0
			Tr = 0.0
			Ti = 0.0
			Cr = x * invN + xmin
			if (checknext) :
				for k in range(MAXITER) :
					Zi = 2 * Zr * Zi + Ci
					Zr = Tr - Ti + Cr
					Ti = Zi * Zi
					Tr = Zr * Zr
					if (Tr + Ti) > LIMIT :
						break
				if k == MAXITER :
					out.write("1")
				else :
					out.write("0")
					checknext = False
			else :
				for k in range(MAXITER) :
					Zi = 2 * Zr * Zi + Ci
					Zr = Tr - Ti + Cr
					Ti = Zi * Zi
					Tr = Zr * Zr
				if (Tr + Ti) < LIMIT :
					out.write("1")
				else :
					out.write("0")
					checknext = True

		out.write("\n")

for i in range(20) :
	mandelbrot(200, 200)