Created
February 2, 2015 19:03
-
-
Save bryan-lunt/46534a459b80d9dfbdc9 to your computer and use it in GitHub Desktop.
Mandelbrot Set generators in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
..............................................................................................................................#......................................................................... | |
.............................................................................................................................##......................................................................... | |
.............................................................................................................................###........................................................................ | |
.............................................................................................................................###........................................................................ | |
.............................................................................................................................###........................................................................ | |
.............................................................................................................................##......................................................................... | |
..........................................................................................................................######........................................................................ | |
.........................................................................................................................#########...................................................................... | |
.......................................................................................................................############..................................................................... | |
.......................................................................................................................#############.................................................................... | |
........................................................................................................................############.................................................................... | |
......................................................................................................................#.###########..................................................................... | |
.......................................................................................................................#############.................................................................... | |
.......................................................................................................................#############.................................................................... | |
......................................................................................................................##############.................................................................... | |
.......................................................................................................................##############................................................................... | |
.......................................................................................................................#############.................................................................... | |
......................................................................................................................##############.................................................................... | |
.......................................................................................................................#############.................................................................... | |
.......................................................................................................................############..................................................................... | |
........................................................................................................................############.................................................................... | |
.........................................................................................................................##########..................................................................... | |
.........................................................................................................................#########...................................................................... | |
..........................................................................................................................#######.....#................................................................. | |
.................................................................................................................#....#...#.###.###......#.............................................................. | |
.............................................................................................................#....#.###################..#.............................................................. | |
.............................................................................................................##.##########################....#......................................................... | |
............................................................................................................###.############################.##......................................................... | |
.................................................................................................##.........################################.###........................................................ | |
.................................................................................................#####....#.###################################......................................................... | |
..................................................................................................#####...#####################################..#...................................................... | |
..................................................................................................#####...######################################.#......#............................................... | |
.................................................................................................######..#########################################....####.#............................................ | |
................................................................................................#######.##########################################...#######............................................ | |
..................................................................................................#################################################...#####............................................. | |
..................................................................................................##################################################..######............................................ | |
..................................................................................................###################################################.######............................................ | |
.....................................................................................................################################################.#####............................................. | |
....................................................................................................#########################################################........................................... | |
.................................................................................................##########################################################............................................. | |
.................................................................................................#########################################################.#............................................ | |
................................................................................................########################################################................................................ | |
...............................................................................................##########################################################............................................... | |
................................................................................................##########################################################.............................................. | |
..........................................................................................#.#.###########################################################............................................... | |
..........................................................................................#################################################################............................................. | |
...........................................................................................################################################################............................................. | |
...........................................................................................#################################################################.#.......................................... | |
...........................................................................................##################################################################........................................... | |
.............................................................................................################################################################........................................... | |
............................................................................................################################################################............................................ | |
..........................................................................................#.#################################################################........................................... | |
..........................................................................................###################################################################........................................... | |
...........................................................................................##################################################################..#........................................ | |
........................................................................................#####################################################################.###....................................... | |
........................................................................................#####################################################################.####...................................... | |
.......................................................................................##########################################################################....................................... | |
.........................................................................................#######################################################################........................................ | |
......................................................................................#..#####################################################################.#........................................ | |
........................................................................................#######################################################################......................................... | |
...................................................................#................#.#.######################################################################.......................................... | |
...................................................................#..................##########################################################################........................................ | |
........................................................##........##..................#.#######################################################################......................................... | |
.........................................................##.......##..#................########################################################################......................................... | |
........................................................####...########.##...........#.########################################################################......................................... | |
........................................................####..###########............##########################################################################......................................... | |
........................................................##################.#..........###########################################################################....................................... | |
........................................................####################..........###########################################################################....................................... | |
..........................................................##################........#############################################################################....................................... | |
........................................................######################........##########################################################################........................................ | |
........................................................#######################......##########################################################################......................................... | |
.......................................................########################......##########################################################################......................................... | |
......................................................##########################....###########################################################################......................................... | |
....................................................############################.....##########################################################################......................................... | |
....................................................#############################...############################################################################........................................ | |
.....................................................############################....###########################################################################........................................ | |
.....................................................#############################..##########################################################################.......................................... | |
...................................................###############################..##########################################################################.......................................... | |
...................................................################################.##########################################################################.......................................... | |
...................................................################################.###########################################################################......................................... | |
....................................................###############################.#########################################################################.#......................................... | |
...................................................################################.#########################################################################........................................... | |
..................................................#################################.#########################################################################........................................... | |
............................................#####.#################################.########################################################################............................................ | |
............................................#####..#########################################################################################################............................................ | |
...........................................#######.########################################################################################################............................................. | |
...........................................#######.########################################################################################################............................................. | |
..........................................################################################################################################################.............................................. | |
................#........................#.#############################################################################################################................................................ | |
..............###....#..##.#.#.########################################################################################################################................................................. | |
................#........................#.#############################################################################################################................................................ | |
..........................................################################################################################################################.............................................. | |
...........................................#######.########################################################################################################............................................. | |
...........................................#######.########################################################################################################............................................. | |
............................................#####..#########################################################################################################............................................ | |
............................................#####.#################################.########################################################################............................................ | |
..................................................#################################.#########################################################################........................................... | |
...................................................################################.#########################################################################........................................... | |
....................................................###############################.#########################################################################.#......................................... | |
...................................................################################.###########################################################################......................................... | |
...................................................################################.##########################################################################.......................................... | |
...................................................###############################..##########################################################################.......................................... | |
.....................................................#############################..##########################################################################.......................................... | |
.....................................................############################....###########################################################################........................................ | |
....................................................#############################...############################################################################........................................ | |
....................................................############################.....##########################################################################......................................... | |
......................................................##########################....###########################################################################......................................... | |
.......................................................########################......##########################################################################......................................... | |
........................................................#######################......##########################################################################......................................... | |
........................................................######################........##########################################################################........................................ | |
..........................................................##################........#############################################################################....................................... | |
........................................................####################..........###########################################################################....................................... | |
........................................................##################.#..........###########################################################################....................................... | |
........................................................####..###########............##########################################################################......................................... | |
........................................................####...########.##...........#.########################################################################......................................... | |
.........................................................##.......##..#................########################################################################......................................... | |
........................................................##........##..................#.#######################################################################......................................... | |
...................................................................#..................##########################################################################........................................ | |
...................................................................#................#.#.######################################################################.......................................... | |
........................................................................................#######################################################################......................................... | |
......................................................................................#..#####################################################################.#........................................ | |
.........................................................................................#######################################################################........................................ | |
.......................................................................................##########################################################################....................................... | |
........................................................................................#####################################################################.####...................................... | |
........................................................................................#####################################################################.###....................................... | |
...........................................................................................##################################################################..#........................................ | |
..........................................................................................###################################################################........................................... | |
..........................................................................................#.#################################################################........................................... | |
............................................................................................################################################################............................................ | |
.............................................................................................################################################################........................................... | |
...........................................................................................##################################################################........................................... | |
...........................................................................................#################################################################.#.......................................... | |
...........................................................................................################################################################............................................. | |
..........................................................................................#################################################################............................................. | |
..........................................................................................#.#.###########################################################............................................... | |
................................................................................................##########################################################.............................................. | |
...............................................................................................##########################################################............................................... | |
................................................................................................########################################################................................................ | |
.................................................................................................#########################################################.#............................................ | |
.................................................................................................##########################################################............................................. | |
....................................................................................................#########################################################........................................... | |
.....................................................................................................################################################.#####............................................. | |
..................................................................................................###################################################.######............................................ | |
..................................................................................................##################################################..######............................................ | |
..................................................................................................#################################################...#####............................................. | |
................................................................................................#######.##########################################...#######............................................ | |
.................................................................................................######..#########################################....####.#............................................ | |
..................................................................................................#####...######################################.#......#............................................... | |
..................................................................................................#####...#####################################..#...................................................... | |
.................................................................................................#####....#.###################################......................................................... | |
.................................................................................................##.........################################.###........................................................ | |
............................................................................................................###.############################.##......................................................... | |
.............................................................................................................##.##########################....#......................................................... | |
.............................................................................................................#....#.###################..#.............................................................. | |
.................................................................................................................#....#...#.###.###......#.............................................................. | |
..........................................................................................................................#######.....#................................................................. | |
.........................................................................................................................#########...................................................................... | |
.........................................................................................................................##########..................................................................... | |
........................................................................................................................############.................................................................... | |
.......................................................................................................................############..................................................................... | |
.......................................................................................................................#############.................................................................... | |
......................................................................................................................##############.................................................................... | |
.......................................................................................................................#############.................................................................... | |
.......................................................................................................................##############................................................................... | |
......................................................................................................................##############.................................................................... | |
.......................................................................................................................#############.................................................................... | |
.......................................................................................................................#############.................................................................... | |
......................................................................................................................#.###########..................................................................... | |
........................................................................................................................############.................................................................... | |
.......................................................................................................................#############.................................................................... | |
.......................................................................................................................############..................................................................... | |
.........................................................................................................................#########...................................................................... | |
..........................................................................................................................######........................................................................ | |
.............................................................................................................................##......................................................................... | |
.............................................................................................................................###........................................................................ | |
.............................................................................................................................###........................................................................ | |
.............................................................................................................................###........................................................................ | |
.............................................................................................................................##......................................................................... | |
..............................................................................................................................#......................................................................... | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ | |
........................................................................................................................................................................................................ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment