Uniform initialization Uniform initialization: you could use it to simplify some parts by not writing explicit types. In
getColor
, prefer:sf::Color getColor(int iterations) { int r, g, b; // ... return {r, g, b}; }
Uniform initialization: you could use it to simplify some parts by not writing explicit types. In
getColor
, prefer:sf::Color getColor(int iterations) { int r, g, b; // ... return {r, g, b}; }
Uniform initialization: you could use it to simplify some parts by not writing explicit types. In
getColor
, prefer:sf::Color getColor(int iterations) { int r, g, b; // ... return {r, g, b}; }
- Globals should generally be avoided;
- The
maximum
mandelbrot
could default toMAX
i.e.
int mandelbrot(double startReal, double startImag, int maximum = ::MAX)
zoom
should have a maximum level and therefore you should ensure it's not broken (double
-s aresigned
).
- Globals should generally be avoided;
- The
maximum
mandelbrot
could default toMAX
i.e.
int mandelbrot(double startReal, double startImag, int maximum = ::MAX)
- Globals should generally be avoided;
- The
maximum
mandelbrot
could default toMAX
i.e.
int mandelbrot(double startReal, double startImag, int maximum = ::MAX)
zoom
should have a maximum level and therefore you should ensure it's not broken (double
-s aresigned
).
Performance
A minor optimization for getColor
would try to reduce conditional assignments by giving r, g, b
default values and so changing them only if necessary:
sf::Color getColor(int iterations) {
int r = g = b = 0;
if (iterations == -1) {
// nothing to do
} else if (iterations == 0) {
r = 255;
// g = 0;
// b = 0;
} else {
// colour gradient: Red -> Blue -> Green -> Red -> Black
// corresponding values: 0 -> 16 -> 32 -> 64 -> 127 (or -1)
if (iterations < 16) {
r = 16 * (16 - iterations);
// g = 0;
b = 16 * iterations - 1;
} else if (iterations < 32) {
// r = 0;
g = 16 * (iterations - 16);
b = 16 * (32 - iterations) - 1;
} else if (iterations < 64) {
r = 8 * (iterations - 32);
g = 8 * (64 - iterations) - 1;
// b = 0;
} else { // range is 64 - 127
r = 255 - (iterations - 64) * 4;
// g = 0;
// b = 0;
}
}
Other Details
- Globals should generally be avoidedavoided;
- The
maximum
mandelbrot
could default toMAX
i.e.
int mandelbrot(double startReal, double startImag, int maximum = ::MAX)
Other Details
- Globals should generally be avoided
- The
maximum
mandelbrot
could default toMAX
i.e.
int mandelbrot(double startReal, double startImag, int maximum = ::MAX)
Performance
A minor optimization for getColor
would try to reduce conditional assignments by giving r, g, b
default values and so changing them only if necessary:
sf::Color getColor(int iterations) {
int r = g = b = 0;
if (iterations == -1) {
// nothing to do
} else if (iterations == 0) {
r = 255;
// g = 0;
// b = 0;
} else {
// colour gradient: Red -> Blue -> Green -> Red -> Black
// corresponding values: 0 -> 16 -> 32 -> 64 -> 127 (or -1)
if (iterations < 16) {
r = 16 * (16 - iterations);
// g = 0;
b = 16 * iterations - 1;
} else if (iterations < 32) {
// r = 0;
g = 16 * (iterations - 16);
b = 16 * (32 - iterations) - 1;
} else if (iterations < 64) {
r = 8 * (iterations - 32);
g = 8 * (64 - iterations) - 1;
// b = 0;
} else { // range is 64 - 127
r = 255 - (iterations - 64) * 4;
// g = 0;
// b = 0;
}
}
Other Details
- Globals should generally be avoided;
- The
maximum
mandelbrot
could default toMAX
i.e.
int mandelbrot(double startReal, double startImag, int maximum = ::MAX)