view include/Fractal.h @ 5:d691ce98f406

OK. This is the first release. Honest.
author Eris Caffee <discordia@eldalin.com>
date Fri, 12 Nov 2010 23:58:48 -0600
parents df02a7de7fe2
children
line source
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Fracter - A simple Mandelbrot Set viewer.
4 //
5 // Copyright (C) 2010 Sarah Eris Horsley Caffee
6 //
7 // This file is part of Fracter.
8 //
9 // Fracter is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 //
23 //
24 // Fractal.h
25 // Fractal calculator virtual class definition. Actual fractals should
26 // implement this.
27 //
28 ////////////////////////////////////////////////////////////////////////////////
30 #ifndef FRACTAL_H
31 #define FRACTAL_H
33 #include <map>
34 #include <string>
35 #include <typeinfo>
37 #include "SDL.h"
39 ////////////////////////////////////////////////////////////////////////////////
40 class View
41 {
42 public:
43 View(std::string t,
44 double re, double im, double s,
45 unsigned int max);
46 virtual ~View();
48 std::string const & get_type() const;
51 private:
52 friend class Fractal;
54 View();
55 View & operator=(const View &);
57 std::string type;
58 double re_min, im_max, size;
59 unsigned int max_iter;
60 };
63 ////////////////////////////////////////////////////////////////////////////////
64 class Fractal
65 {
66 public:
67 Fractal();
68 virtual ~Fractal();
70 virtual bool calc_set() = 0;
71 virtual bool init(SDL_Surface * surf);
73 double get_re_min() const;
74 double set_re_min(const double r_min);
76 double get_im_max() const;
77 double set_im_max(const double i_max);
79 double get_size() const;
80 double set_size(const double s);
82 unsigned int get_max_iter() const;
83 unsigned int set_max_iter(const unsigned int iter);
84 unsigned int inc_max_iter();
85 unsigned int dec_max_iter();
87 void set_calc_needed();
89 virtual std::string const & get_display_name() const;
90 virtual std::string const & get_fractal_name() const;
93 virtual bool get_option(std::string option, void * value) const;
94 virtual bool set_option(std::string option, void * value);
96 virtual View * save_view();
97 virtual void restore_view(View * v);
99 protected:
101 virtual void draw_pixel(int x, int y, Uint32 * color);
103 // fractal_name is the basic name of ths fractal, such as "Mandelbrot set"
104 // or "Julia set"
105 // display_name is probably the same, but might have a bit of extra info,
106 // such as "Julia set K=(1,2)
107 std::string display_name;
108 std::string fractal_name;
111 // The dimensions in the complex plane of the calculated image.
112 // Square image only with die of length "size".
113 // Upper left corner of the region is (re_min, im_max)
114 double re_min;
115 double im_max;
116 double size;
118 // Number of iterations to perform when calculating.
119 unsigned int max_iter;
121 // Set to true if the image needs to be recalculated.
122 bool calc_needed;
124 // Our drawing surface.
125 SDL_Surface * surface;
127 private:
128 // Disallow copy constructor and operator=
129 Fractal(const Fractal &);
130 Fractal & operator=(const Fractal &);
131 };
135 ////////////////////////////////////////////////////////////////////////////////
136 // Abstract Factory class.
137 // A singleton, but it's not thread safe.
138 class FractalFactory
139 {
140 public:
141 virtual ~FractalFactory();
142 virtual Fractal * create() const = 0;
143 };
145 std::map <std::string, FractalFactory *> & get_Fractal_map();
147 #endif