This repository was archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfractal.cpp
More file actions
107 lines (90 loc) · 2.76 KB
/
Copy pathfractal.cpp
File metadata and controls
107 lines (90 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// fractal.cpp
// Mandelbrot
//
// Created by Benjamin Mayes on 10/13/11.
// Copyright 2011 RIT. All rights reserved.
//
#include "fractal.h"
fractal::fractal() : _window_width(800), _window_height(600), _iters(1000), _center_x(0.0), _center_y(0.0), _res(0.005), _g(2.5), _redraw(1) {}
fractal::fractal( int window_width, int window_height ) : _window_width(window_width), _window_height(window_height), _iters(1000), _center_x(0.0), _center_y(0.0), _res(0.005), _g(2.5), _redraw(1) {
_pixels = new double*[_window_height];
for( int i = 0; i < _window_height; ++i ) {
_pixels[i] = new double[_window_width];
}
}
fractal::fractal( const fractal& f ) : _window_width(f._window_width), _window_height(f._window_height), _iters(f._iters), _center_x(f._center_x), _center_y(f._center_y), _res(f._res), _g(f._g){
_pixels = new double*[_window_height];
for( int i = 0; i < _window_height; ++i ) {
_pixels[i] = new double[_window_width];
for( int j = 0; j < _window_width; ++j ) {
_pixels[i][j] = f._pixels[i][j];
}
}
}
fractal::~fractal() {
for( int i = 0; i < _window_height; ++i ) {
delete _pixels[i];
}
delete _pixels;
}
void fractal::center( int x, int y ) {
y = _window_height - 1 - y;
_center_x = (x - _window_width/2)*_res + _center_x;
_center_y = (y - _window_height/2)*_res + _center_y;
_redraw = 1;
}
void fractal::center( const double& x, const double& y ) {
_center_x = x;
_center_y = y;
_redraw = 1;
}
void fractal::zoom_in( const double& amt ) {
_res /= amt;
_redraw = 1;
}
void fractal::zoom_out( const double& amt ) {
_res *= amt;
_redraw = 1;
}
double fractal::gamma() const {
return _g;
}
void fractal::set_gamma( const double& g ) {
_g = g;
_redraw = 1;
}
int fractal::iters() const {
return _iters;
}
void fractal::set_iters( int i ) {
_iters = i;
_redraw = 1;
}
void fractal::resize( int width, int height ) {
for( int i = 0; i < _window_height; ++i ) {
delete[] _pixels[i];
}
delete[] _pixels;
_window_width = width;
_window_height = height;
_pixels = new double*[_window_height];
for( int i = 0; i < _window_height; ++i ) {
_pixels[i] = new double[_window_width];
}
_redraw = 1;
}
const double ** fractal::get_fractal() {
if( _redraw ) {
draw_fractal();
_redraw = 0;
}
return (const double**)_pixels;
}
std::ostream& operator<<( std::ostream& out, const fractal& f ) {
out << "Center: (" << f._center_x << "," << f._center_y << ")" << std::endl;
out << "Res: " << f._res << std::endl;
out << f._iters << " " << f._g << std::endl;
out << "Window Size: " << f._window_width << "*" << f._window_height << std::endl;
return out;
}