Skip to content

Instantly share code, notes, and snippets.

@bryan-lunt
Created February 2, 2015 19:03
Show Gist options
  • Save bryan-lunt/46534a459b80d9dfbdc9 to your computer and use it in GitHub Desktop.
Save bryan-lunt/46534a459b80d9dfbdc9 to your computer and use it in GitHub Desktop.
Mandelbrot Set generators in Python
from scipy import arange,power
pinf = float("inf")
ninf = float("-inf")
def isBad(x):
return x != x or x == pinf or x == ninf
def inMend(c):
z = c**2 + c
for i in range(0,75):
try:
z = z**2 + c
except:
return False
if isBad(z.real) or isBad(z.imag):
return False
return True
#main
output = ""
for y in arange(-1,1,.02):
for x in arange(-2,1,.015):
z = complex(x,y)
if inMend(z):
output+= "#"
else:
output +="."
output+="\n"
print output
import scipy as S
#main
ystep = 0.02
xstep = 0.015
c = S.array([[complex(x,y) for x in S.arange(-2,1,xstep)] for y in S.arange(-1,1,ystep)])
z = S.power(c,2) + c
for i in range(50):
z = S.power(z,2) + c
output = ""
for y in z:
for x in y:
output += "#" if S.isfinite(x) else "."
output +="\n"
print output
window = (500,500)
mwindow = ((-1,1),(-1,1))
size(window[0],window[1])
pinf = float("inf")
ninf = float("-inf")
def isBad(x):
return x != x or x == pinf or x == ninf
def inMend(z,c):
for i in range(0,100):
try:
z = z**2 + c
except:
return i
if isBad(z.real) or isBad(z.imag):
return i
return 0
#main
colormode(HSB)
translate(250,250)
background(0,0,0)
for y_i in range(-250,250):
for x_i in range(-250,250):
y= y_i/250.0
x= x_i/250.0
z = complex(x,y)
divTime = inMend(z,z)
if divTime == 0:
continue
#rect(x_i,y_i,1,1)
else:
fill(divTime/50.0,1,1)
rect(x_i,y_i,1,1)
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
..............................................................................................................................#.........................................................................
.............................................................................................................................##.........................................................................
.............................................................................................................................###........................................................................
.............................................................................................................................###........................................................................
.............................................................................................................................###........................................................................
.............................................................................................................................##.........................................................................
..........................................................................................................................######........................................................................
.........................................................................................................................#########......................................................................
.......................................................................................................................############.....................................................................
.......................................................................................................................#############....................................................................
........................................................................................................................############....................................................................
......................................................................................................................#.###########.....................................................................
.......................................................................................................................#############....................................................................
.......................................................................................................................#############....................................................................
......................................................................................................................##############....................................................................
.......................................................................................................................##############...................................................................
.......................................................................................................................#############....................................................................
......................................................................................................................##############....................................................................
.......................................................................................................................#############....................................................................
.......................................................................................................................############.....................................................................
........................................................................................................................############....................................................................
.........................................................................................................................##########.....................................................................
.........................................................................................................................#########......................................................................
..........................................................................................................................#######.....#.................................................................
.................................................................................................................#....#...#.###.###......#..............................................................
.............................................................................................................#....#.###################..#..............................................................
.............................................................................................................##.##########################....#.........................................................
............................................................................................................###.############################.##.........................................................
.................................................................................................##.........################################.###........................................................
.................................................................................................#####....#.###################################.........................................................
..................................................................................................#####...#####################################..#......................................................
..................................................................................................#####...######################################.#......#...............................................
.................................................................................................######..#########################################....####.#............................................
................................................................................................#######.##########################################...#######............................................
..................................................................................................#################################################...#####.............................................
..................................................................................................##################################################..######............................................
..................................................................................................###################################################.######............................................
.....................................................................................................################################################.#####.............................................
....................................................................................................#########################################################...........................................
.................................................................................................##########################################################.............................................
.................................................................................................#########################################################.#............................................
................................................................................................########################################################................................................
...............................................................................................##########################################################...............................................
................................................................................................##########################################################..............................................
..........................................................................................#.#.###########################################################...............................................
..........................................................................................#################################################################.............................................
...........................................................................................################################################################.............................................
...........................................................................................#################################################################.#..........................................
...........................................................................................##################################################################...........................................
.............................................................................................################################################################...........................................
............................................................................................################################################################............................................
..........................................................................................#.#################################################################...........................................
..........................................................................................###################################################################...........................................
...........................................................................................##################################################################..#........................................
........................................................................................#####################################################################.###.......................................
........................................................................................#####################################################################.####......................................
.......................................................................................##########################################################################.......................................
.........................................................................................#######################################################################........................................
......................................................................................#..#####################################################################.#........................................
........................................................................................#######################################################################.........................................
...................................................................#................#.#.######################################################################..........................................
...................................................................#..................##########################################################################........................................
........................................................##........##..................#.#######################################################################.........................................
.........................................................##.......##..#................########################################################################.........................................
........................................................####...########.##...........#.########################################################################.........................................
........................................................####..###########............##########################################################################.........................................
........................................................##################.#..........###########################################################################.......................................
........................................................####################..........###########################################################################.......................................
..........................................................##################........#############################################################################.......................................
........................................................######################........##########################################################################........................................
........................................................#######################......##########################################################################.........................................
.......................................................########################......##########################################################################.........................................
......................................................##########################....###########################################################################.........................................
....................................................############################.....##########################################################################.........................................
....................................................#############################...############################################################################........................................
.....................................................############################....###########################################################################........................................
.....................................................#############################..##########################################################################..........................................
...................................................###############################..##########################################################################..........................................
...................................................################################.##########################################################################..........................................
...................................................################################.###########################################################################.........................................
....................................................###############################.#########################################################################.#.........................................
...................................................################################.#########################################################################...........................................
..................................................#################################.#########################################################################...........................................
............................................#####.#################################.########################################################################............................................
............................................#####..#########################################################################################################............................................
...........................................#######.########################################################################################################.............................................
...........................................#######.########################################################################################################.............................................
..........................................################################################################################################################..............................................
................#........................#.#############################################################################################################................................................
..............###....#..##.#.#.########################################################################################################################.................................................
................#........................#.#############################################################################################################................................................
..........................................################################################################################################################..............................................
...........................................#######.########################################################################################################.............................................
...........................................#######.########################################################################################################.............................................
............................................#####..#########################################################################################################............................................
............................................#####.#################################.########################################################################............................................
..................................................#################################.#########################################################################...........................................
...................................................################################.#########################################################################...........................................
....................................................###############################.#########################################################################.#.........................................
...................................................################################.###########################################################################.........................................
...................................................################################.##########################################################################..........................................
...................................................###############################..##########################################################################..........................................
.....................................................#############################..##########################################################################..........................................
.....................................................############################....###########################################################################........................................
....................................................#############################...############################################################################........................................
....................................................############################.....##########################################################################.........................................
......................................................##########################....###########################################################################.........................................
.......................................................########################......##########################################################################.........................................
........................................................#######################......##########################################################################.........................................
........................................................######################........##########################################################################........................................
..........................................................##################........#############################################################################.......................................
........................................................####################..........###########################################################################.......................................
........................................................##################.#..........###########################################################################.......................................
........................................................####..###########............##########################################################################.........................................
........................................................####...########.##...........#.########################################################################.........................................
.........................................................##.......##..#................########################################################################.........................................
........................................................##........##..................#.#######################################################################.........................................
...................................................................#..................##########################################################################........................................
...................................................................#................#.#.######################################################################..........................................
........................................................................................#######################################################################.........................................
......................................................................................#..#####################################################################.#........................................
.........................................................................................#######################################################################........................................
.......................................................................................##########################################################################.......................................
........................................................................................#####################################################################.####......................................
........................................................................................#####################################################################.###.......................................
...........................................................................................##################################################################..#........................................
..........................................................................................###################################################################...........................................
..........................................................................................#.#################################################################...........................................
............................................................................................################################################################............................................
.............................................................................................################################################################...........................................
...........................................................................................##################################################################...........................................
...........................................................................................#################################################################.#..........................................
...........................................................................................################################################################.............................................
..........................................................................................#################################################################.............................................
..........................................................................................#.#.###########################################################...............................................
................................................................................................##########################################################..............................................
...............................................................................................##########################################################...............................................
................................................................................................########################################################................................................
.................................................................................................#########################################################.#............................................
.................................................................................................##########################################################.............................................
....................................................................................................#########################################################...........................................
.....................................................................................................################################################.#####.............................................
..................................................................................................###################################################.######............................................
..................................................................................................##################################################..######............................................
..................................................................................................#################################################...#####.............................................
................................................................................................#######.##########################################...#######............................................
.................................................................................................######..#########################################....####.#............................................
..................................................................................................#####...######################################.#......#...............................................
..................................................................................................#####...#####################################..#......................................................
.................................................................................................#####....#.###################################.........................................................
.................................................................................................##.........################################.###........................................................
............................................................................................................###.############################.##.........................................................
.............................................................................................................##.##########################....#.........................................................
.............................................................................................................#....#.###################..#..............................................................
.................................................................................................................#....#...#.###.###......#..............................................................
..........................................................................................................................#######.....#.................................................................
.........................................................................................................................#########......................................................................
.........................................................................................................................##########.....................................................................
........................................................................................................................############....................................................................
.......................................................................................................................############.....................................................................
.......................................................................................................................#############....................................................................
......................................................................................................................##############....................................................................
.......................................................................................................................#############....................................................................
.......................................................................................................................##############...................................................................
......................................................................................................................##############....................................................................
.......................................................................................................................#############....................................................................
.......................................................................................................................#############....................................................................
......................................................................................................................#.###########.....................................................................
........................................................................................................................############....................................................................
.......................................................................................................................#############....................................................................
.......................................................................................................................############.....................................................................
.........................................................................................................................#########......................................................................
..........................................................................................................................######........................................................................
.............................................................................................................................##.........................................................................
.............................................................................................................................###........................................................................
.............................................................................................................................###........................................................................
.............................................................................................................................###........................................................................
.............................................................................................................................##.........................................................................
..............................................................................................................................#.........................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment