Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

COSC 231 Programming Project: Creating a GUI for Sierpinski Triangle and Mandelbrot Set - , Study Guides, Projects, Research of Computer Science

A programming project for creating a graphical user interface (gui) to display the sierpinski triangle and mandelbrot set with user-controlled parameters. The project involves writing code to generate these fractals using given algorithms and creating a gui with buttons for clearing the drawing surface, generating the fractals, adjusting the speed, and selecting colors. The document also includes explanations of the sierpinski triangle and mandelbrot set, their generation algorithms, and how to represent points in the complex plane.

Typology: Study Guides, Projects, Research

2009/2010

Uploaded on 02/24/2010

koofers-user-lj1-1
koofers-user-lj1-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COSC 231 Programming Project GUI for Two Fractals
Distributed: 24 November 2009
Due: 10 December 2009
Write a GUI that will display, with certain user-controlled parameters, the Sierpinski
gasket and a Mandelbrot set.
Sierpinski triangle (gasket)
The Sierpinski triangle generation algorithm is given in Savitch’s book (3rd edition) on pp
1061-2. That text is reproduced here.
Write a program that draws a Sierpinski gasket. A Sierpinski gasket or
triangle is a type of fractal. It is an example of how an orderly structure
can be created as a result of random, chaotic behavior.
The creation of a Sierpinski gasket is fairly simple. There are three points
that form the corners of a triangle. In the figure below, they are labeled as
A, B, and C.
To draw the Sierpinski gasket follow the algorithm:
1. Randomly pick one of the three corners. Call this the current point.
(Alternatively, you could also randomly select any point inside the
triangle).
2. Randomly pick one of the three corners. Call this the target point.
3. Calculate the midpoint between the current point and the target point.
4. Draw a single pixel at the midpoint.
5. Set the current point to the midpoint.
6. Go back to step 2 and repeat many times (e.g., 50,000 iterations).
It would seem like you should get a random mess of dots since the
algorithm randomly picks a target corner each time. Instead, if this process
is repeated many times, you will get a very orderly picture with a
A
B
C
pf3

Partial preview of the text

Download COSC 231 Programming Project: Creating a GUI for Sierpinski Triangle and Mandelbrot Set - and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

COSC 231 Programming Project GUI for Two Fractals Distributed : 24 November 2009 Due : 10 December 2009 Write a GUI that will display, with certain user-controlled parameters, the Sierpinski gasket and a Mandelbrot set. Sierpinski triangle (gasket) The Sierpinski triangle generation algorithm is given in Savitch’s book (3rd^ edition) on pp 1061 - 2. That text is reproduced here. Write a program that draws a Sierpinski gasket. A Sierpinski gasket or triangle is a type of fractal. It is an example of how an orderly structure can be created as a result of random, chaotic behavior. The creation of a Sierpinski gasket is fairly simple. There are three points that form the corners of a triangle. In the figure below, they are labeled as A, B, and C. To draw the Sierpinski gasket follow the algorithm:

  1. Randomly pick one of the three corners. Call this the current point. (Alternatively, you could also randomly select any point inside the triangle).
  2. Randomly pick one of the three corners. Call this the target point.
  3. Calculate the midpoint between the current point and the target point.
  4. Draw a single pixel at the midpoint.
  5. Set the current point to the midpoint.
  6. Go back to step 2 and repeat many times (e.g., 50,000 iterations). It would seem like you should get a random mess of dots since the algorithm randomly picks a target corner each time. Instead, if this process is repeated many times, you will get a very orderly picture with a

A

B

C

repeating structure: < picture from Savitch is not reproduced here. Look at http://en.wikipedia.org/wiki/Sierpinski_gasket > To draw a single pixel at coordinate (x, y) use the drawline method where the start and endpoints are both (x, y). To generate a random number x , where 0 < x < 1 , use x = Math.random();. For example, multiplying by 3 and converting to an integer results in an integer that is from 0 to 2. Mandolbrot set There are several explanations of the Mandelbrot set. A simple one, including the iterative algorithm for determining if a number is a member of the set, is given at

http://www.ddewey.net/mandelbrot/

Here is another simple explanation:

http://t16web.lanl.gov/Kawano/gnuplot/fractal/mandelbrot-e.html

Each point, C, in the complex plane is a member of the Mandelbrot set if after iterating (forever), the magnitude of Z is less than 2. Z iterates as follows: Z 0 = 0. Zn+1 = Zn * Zn + C Represent a point C = x + iy on the drawing surface as (x, y). The GUI Interface The GUI interface will have a drawing surface and the following buttons:

  1. Clear – to clear the drawing surface.
  2. Sierpinski – Draws the Sierpinski triangle at the current speed and color option and starting with the current target point and current point. Fractal generation will reset when the user hits this button.
  3. Mandelbrot - Draws the Mandelbrot set at current color option. Speed is not variable (and the Speed button should be disabled. Fractal generation will be reset when the user hits this button.
  4. Stop – Halts the current graphic generation. The current state of the fractal generation is saved so that if the user subsequently hits the Start button, the fractal generation continues from the current state.
  5. Speed – Lets the user choose the speed of the iteration (e.g., the length of the time to wait before returning to step 2. The speed can be changed during fractal generation. Fractal generation will not cease or reset.
  6. Color choice – A user can select a color for the fractal, or can choose Rainbow. If the user is drawing a Sierpinski triangle and the user chooses Rainbow, the colors will change every 500 pixels, moving through the colors of the rainbow (ROYGBV) with