field trip #33 creating and saving fractals. julia set we consider a complex function, f(z) for each...

14
Field Trip #33 Creating and Saving Fractals

Upload: francis-page

Post on 03-Jan-2016

216 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 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,

Field Trip #33

Creating and Saving Fractals

Page 2: 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,

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

Page 3: 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,

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

Page 4: 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,

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

Page 5: 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,

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

Page 6: 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,

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

Page 7: 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,

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]

Page 8: 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,

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

Page 9: 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,

Quadratic Family, f(z) = z^2 + 0.5

Page 10: 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,

Exponential Family, f(z) = (1+i)e^z

Page 11: 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,

Sine Family, f(z) = csin(z)

Page 12: 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,

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.

Page 13: 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,

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

Page 14: 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,

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