Assignment 3 Documentation - by Emmanuel Piuze
ID 206187447
Built December 2006
Introduction
This is the documentation for the assignment 3 in COMP 206. The program
was programmed, built and debugged on the 3rd floor in the Trottier building. Reading documentation,
programming, testing, debugging and building the page for this assignment took me about 8
hours. The program is not protected for wrong user input. For instance, all the parameter fields are not
validated when used. If the user enters proper values in the fields, i.e. non-negative float values for colors,
shape, precision, and float values for OffsetX and OffsetY, the fractal should be generated without a problem.
In this assignment, we had to design a Python-code interface to be used as a
front-end for a fractal generator written in C-code. From Wikipedia: "a fractal is "a
rough or fragmented geometric shape that can be subdivided in parts, each of which is (at least approximately) a reduced/size copy of the whole". The term was
coined by Benoît Mandelbrot in 1975 and was derived from the Latin
fractus meaning broken or fractured."
My program is able to generate 5 types
of fractals: Julia, Mandelbrot, Sin, Tan and SinCos. There is infinitely many
possible fractals algorithms that can be implemented by playing with math functions. These are some examples that I
found looked nice. They show how the different parameters work. By playing
with the "Red%", "Green%",
"Blue%, "precision" and "shape" parameters, it is possible to get infinitely many other interesting
colored geometric
forms. The colors adjustments are given in %, with the possibility to set them to more than 100%. By setting
values bigger than 100%, the
fractal get "glowing" edges, which looks really nice.
Python programming part (pyfract.py)
The Python programming involved building the interface for the fractal generator. The interface was built using the Tkinter library. The imaging library was used to directly generate the image on the Python interface and to save it to a file.
First, we import the C module "cpython" that allows us to generate the fractal. This module is explained in the following section. Then, we build the constructor for the interface. We set up default variables for the entry fields and then build the rest of the objects (labels, entries, buttons). The buttons include 5 fractal "generators" and 1 quit button. The code behind the "generate" button is the same up to a parameter change for the 5 fractals. When the click event is sent, we get the values in the entry boxes. We then use the size parameters of the fractal to be drawn to create a proto-image using the Image.new() method and define a method "putpixel((x,y), color)" to activate a colored pixel at a position (x,y) on the image. We then loop through all X and Y pixels of the image. For each of these (X, Y) coordinates, we get the corresponding color from the C module by calling it with the parameters (x - offsetx, y - offsety, scale, red, green, blue, precision, shape). These parameters correspond respectively to: (a) the position (x,y) translated by an offset, the RGB color percentage, the precision (number of iteration) to be used when drawing the fractal and the shape, an intrinsic parameter of the algorithm used to generate the fractal.
The image is then drawned to the image object and a "Copyright" is printed in the top left corner. Finally, the image is saved to the filename indicated by the user.
C programming part (cpython.c)
The C programming involved building an algorithm that generates a fractal using specified parameters. In this program, when C is called with the parameters mentioned in the Python programming part, it returns to Python the right color to be drawn at the pos(X, Y). The Mandelbrot fractal is computed using a different algorithm than for the 4 others. For Julia, Sin, Tan and SinCos, only the initial parameters used and the mapping function are different. In all cases, the algorithm loops until it reaches a condition set by the (x,y) position being computed. It then determines a color corresponding to how far in the "for loop" the algorithm could go.
Examples (click on them for full size)
Fractals using Julia algorithm
The fractal was generated using default parameters, and with the "Generate Julia Set".
|
|
The fractal was generated using color default parameters except for Red=190%, Green = 300% and Blue = 100%, and with the "Generate Julia Set".
|
The fractal was generated using color default parameters except for Shape = 3, Red=0%, Green = 140% and Blue = 300%, and with the "Generate Julia Set".
|
Fractals using Mandelbrot algorithm
The fractal was generated using default parameters, and with the "Generate Mandelbrot Set".
|
The fractal was generated using default parameters except for Precision = 100, Red=90%, Green = 190% and Blue = 0%, and with the "Generate Mandelbrot Set".
|
The fractal was generated using default parameters except for Scale = 200, Red=0%, Green = 140% and Blue = 300%, and with the "Generate Mandelbrot Set".
|
The fractal was generated using default parameters except for Shape = 2.5, Red=190%, Green = 300% and Blue = 70%, and with the "Generate Mandelbrot Set".
|
The fractal was generated using default parameters except for Red=100%, Green = 100% and Blue = 100%, and with the "Generate Mandelbrot Set".
|
Fractals using Sin algorithm
The fractal was generated using default parameters, and with the "Generate Sin Set".
|
The fractal was generated using default parameters except for Red=0%, Green = 140% and Blue = 300%, and with the "Generate Sin Set".
|
The fractal was generated using default parameters except for Offsetx = 100, Red=0%, Green = 140% and Blue = 300%, and with the "Generate Sin Set".
|
Fractal using Tan algorithm
The fractal was generated using default parameters except for Red=0%, Green = 140% and Blue = 300%, and with the "Generate Tan Set".
|
Fractal using SinCos algorithm
The fractal was generated using default parameters, and with the "Generate SinCos Set".
|