Math Adventures with Python: An Illustrated Guide to Exploring Math with Code by Peter Farrell

Math Adventures with Python: An Illustrated Guide to Exploring Math with Code by Peter Farrell

Author:Peter Farrell
Language: eng
Format: mobi, pdf, epub
ISBN: 9781593278687
Publisher: No Starch Press, Inc.
Published: 2019-04-15T00:00:00+00:00


You can see that it diverges after four iterations because it gets bigger than two units away from the origin. Figure 7-7 graphs each step so you can visualize them.

Figure 7-7: Running the complex number 0.25 + 0.75 i through the mandelbrot() function until it diverges

The red circle has a radius of two units and represents the limit we put on the complex number diverging. When squaring and adding in the original value of z, we cause the locations of the numbers to rotate and translate and eventually to get further away from the origin than our rule allows.

Let’s use some of the graphing tricks we learned in Chapter 4 to graph points and functions in the Processing display. Copy and paste all the complex number functions from complex.py (cAdd, cMult, and magnitude) to the bottom of mandelbrot.pyde. We’ll use Processing’s println() function to print to the console the number of steps it takes a point to diverge. Add the code in Listing 7-4 before the mandelbrot() code you wrote in Listing 7-3.

mandelbrot.pyde

#range of x-values

xmin = -2

xmax = 2



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.