Polina Kondratieva - Fakultät für Informatik

Transcription

Polina Kondratieva - Fakultät für Informatik
Kai Bürger,
Polina Kondratieva
Technische Universität München
Institut für Informatik
Lehrstuhl für Computergrafik & Visualisierung
SS 07
Assignment 1
Deadline 24.04.2006
Page 1 of 2
Praktikum Global Illumination Effects
Assignment 1
Exercise 1: Windows-Forms
a) Main Window
Using the Visual Studio Project Wizard create a new Windows-Application for C#. Add the
following Control elements to the MainWindow:
•
Two Panel components,
•
One PictureBox,
•
Six TextBoxes,
•
Four Buttons,
•
Two CheckBoxes.
Your result should look similar to the image depicted to the right of the text. Now add the
functionality to the Close-Button. By double-click on the Button component (in the Form-Design
mode) the empty function associated with this Button will be created. Insert into this function the
following method:
Close();
b) Fractal functionality
As the next step, add the functionality to the Compute-Button. For this purpose double-click on the
Compute-Button. In the created new function insert the code for reading the values from six
TextBoxes and conversion of these values into doubles.
To avoid the problems with decimal delimiter while reading the values from the TexBoxes (could
be “,” or “.”), you can use the following code:
string tmp = inputBox.Text;
tmp = tmp.Replace(".",
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator);
tmp = tmp.Replace(",",
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator);
Afterwards use static Parse method of the double class to transform those string values into
six double variables. Those double variables contain all the information you need in order to
compute two fractals: Julia and Mandelbrot.
Since the both fractals use complex numbers, create the new class Complex with the
following members:
Properties:
private double Real;
private double Imag;
Praktikum Global Illumination Effects
Lehrstuhl für Computergrafik und Visualisierung, Prof. Dr. Westermann
Kai Bürger,
Polina Kondratieva
Methods:
Technische Universität München
Institut für Informatik
Lehrstuhl für Computergrafik & Visualisierung
public
public
public
public
SS 07
Assignment 1
Deadline 24.04.2006
Page 2 of 2
Complex(Complex other);
Complex(double real, double imag);
static Complex operator +(Complex a, Complex b);
static Complex operator -(Complex a, Complex b);
// raise the complex number in power of 2
public void Sqr();
// raise the complex number in power of 2 and return the
// real part of the result
public double SqrRet();
Use the newly created class Complex to compute the color of the pixel according to the
following expression:
(1)
Z(n+1) = Z(n)2 + C,
where Z and C are complex numbers, and n is the number of iterations. Set up the value
for Z(0) to the constant from the input field “C”(TextBox). For this fractal parameter C is
associated with the pixel position in the complex plain.
In order to compute Julia fractal, exchange the starting values for Z(0) and parameter C
(now C is set to the constant from the input field “C” and Z(0) is associated with the pixel
position).
For further computations (for both fractals) repeat computation of expression (1) chosen
number of iterations (e.g. 255) or until |Z(n)| will reach the certain threshold (e.g. 2). The
color of the current pixel will be the resulting number of iterations performed until the cycle
broke (when any of two conditions stated above occurred).
To set the pixels of the PixtureBox, you should lock (and afterwards unlock) the bytes of
its member Image (type Bitmap):
Bitmap b = new Bitmap((int)w, (int)h);
. . .
// Lock, Fill up the Bitmap bytes, Unlock
pictureBox1.Image = b;
pictureBox1.Refresh();
Hint: to understand how to lock and unlock the Bitmap and setup its pixels, see example to
BitmapData.Scan0 property in Microsoft Help for Visual Studio.
Praktikum Global Illumination Effects
Lehrstuhl für Computergrafik und Visualisierung, Prof. Dr. Westermann

Documents pareils