Created
July 20, 2012 16:22
-
-
Save tarnacious/3151666 to your computer and use it in GitHub Desktop.
Mandelbrot
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
| *** | |
| *** | |
| * ********* | |
| ************** | |
| *************** | |
| ****************** | |
| ***** ****************** | |
| *************************** | |
| ************************************** | |
| *************************** | |
| ***** ****************** | |
| ****************** | |
| *************** | |
| ************** | |
| * ********* | |
| *** | |
| *** | |
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 sys | |
| def plot_function(z, c): | |
| return (z * z) + c | |
| def has_escaped(z): | |
| mag = (z.real * z.real) + (z.imag * z.imag) | |
| return (mag > 10000) | |
| def plot_point(x, y): | |
| c = complex(x,y) | |
| z = complex(0,0) | |
| for i in range(200): | |
| if has_escaped(z): | |
| return False | |
| z = plot_function(z, c) | |
| return True | |
| def draw(width, height, x1, y1, x2, y2): | |
| step_x = abs(x1 - x2) / width | |
| step_y = abs(y1 - y2) / height | |
| for y in range(height): | |
| for x in range(width): | |
| point_x = x1 + (x * step_x) | |
| point_y = y1 - (y * step_y) | |
| character = '*' if plot_point(point_x, point_y) else ' ' | |
| sys.stdout.write(character) | |
| print("") | |
| if __name__ == '__main__': | |
| draw(50, 20, -2.0, 1.0, 1.0, -1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment