field trip #33 creating and saving fractals. julia set we consider a complex function, f(z) for each...
TRANSCRIPT
Field Trip #33
Creating and Saving Fractals
Julia Set
We consider a complex function, f(z) For each point on the complex plane (x,y),
where z = x + iy, we consider the sequence of points f(z), f(f(z)), f(f(f(z))), f(f(f(f(z)))), etc.
We define a point we call infinity For each point on the complex plane, we
determine how many points in the sequence it takes until the magnitude of a point in the sequence is greater than infinity
We then assign a different color based on how many points
Complex Numbers
Recall that there is no real number, i, such that i*i = -1.
We define the imaginary number i to be the square root of -1.
We consider a plane where the horizontal axis represents real numbers and the vertical axis represents imaginary numbers.
We define a complex number z to be x + iy
Iteration
The sequence of points we generate is called an iteration
An iteration involves taking the output of a function and putting that into the function to produce a result
We sometimes call this recursion A recursion cannot go on indefinitely We define a maximum number of times we will
perform the recursion
Loops
To fill in the Julia Set, we will need to consider many points on the complex plane
In order to do this, we will take advantage of the one of the pillars of structured programming: repeated execution or loops
One form of a loop is the for loop A for loop uses a controlling variable that steps
between two values and do something for each value of the controlling variable
Computing Color
We create initially an array of values This array of values will contain the values we
need to create colors The elements of the array determine what color
is assigned to the number of iterations needed to exceed infinity
If the iteration doesn't exceed infinity after the maximum number of iterations, then we assign the color black
Arrays
The array is a structure that contains elements of the same type
We use three parallel arrays The arrays contain the amount of red, green,
and blue in the color We create an array with the syntax int[] red =
new int[30]
Different Fractals
There are some well known functions that produce interesting Julia Sets
The quadratic function, f(z) = z^2 + c, where c is a complex number can produce different Julia Sets if we vary c
The exponential function f(z) = ce^z also produces interesting results
The sine function f(z) = csin(z) produces an interesting Julia Set
Quadratic Family, f(z) = z^2 + 0.5
Exponential Family, f(z) = (1+i)e^z
Sine Family, f(z) = csin(z)
BufferedImage
In the Java language, there is a package that deals with images
One of the classes in the package is the BufferedImage
After we create a BufferedImage, we can use the class javax.imageio.ImageIO to write the BufferedImage to a file where we specify the type of image file by using an appropriate setting: jpg, png, etc.
Creating the BufferedImage
To create the BufferedImage, we first create an array that contain the color information
For each Color, we specify how much red, green, and blue it contains. We specify this with integers between 0 and 255
The Color class contains a method called getRGB() that gives us a single integer
We use an array of these single integers to create the BufferedImage
Saving an Image
After the image has been created, we use the ImageIO class to write the BufferedImage to a file
We use the method write which expects the BufferedImage, the type of file (“jpg”,”png”, etc.), and the location
We specify the location to write the file by creating a new File object