Parcourir la source

tutorial: continuous color in the Mandelbrot viewer.

legacy
Sam Hocevar gary il y a 13 ans
Parent
révision
5120d97be5
1 fichiers modifiés avec 31 ajouts et 4 suppressions
  1. +31
    -4
      test/tutorial/tut03.cpp

+ 31
- 4
test/tutorial/tut03.cpp Voir le fichier

@@ -27,6 +27,7 @@ using namespace lol;

#if defined _WIN32
# undef main /* FIXME: still needed? */
# include <direct.h>
#endif

class Fractal : public WorldEntity
@@ -114,18 +115,40 @@ public:
/* FIXME: this object never cleans up */
}

m_angle += deltams * 0.001f;
m_angle += deltams * 0.0001f;

cmplx r0(cosf(m_angle), 0.3f * sinf(m_angle));
cmplx r0(cosf(m_angle), 0.5f * sinf(m_angle));
for (int j = 0; j < m_size.y; j++)
for (int i = 0; i < m_size.x; i++)
{
cmplx x0(4.0f / m_size.x * i - 2.5f, 3.0f / m_size.y * j - 1.5f);
cmplx r = x0 * r0;
cmplx z;
int iter = 20;
for (cmplx z = r; iter && z.sqlen() < 4.0f; z = z * z + r)
for (z = r; iter && z.sqlen() < 4.0f; z = z * z + r)
--iter;
m_pixels[j * m_size.x + i] = u8vec4(0, iter * 12, iter * 12, 0);

float f = iter;
float n = z.sqlen();
if (n > 36.0f)
f += 2.0f;
if (n > 16.0f)
f += 1.0f + (n - 16.0f) / 20.0f;
else if (n > 4.0f)
f += (n - 4.0f) / 12.0f;

if (iter)
{
uint8_t red = 255 - f * 11;
uint8_t green = 255 - f * 11;
uint8_t blue = (f * 23 > 255) ? 511 - f * 23 : 255;
//uint8_t blue = f * 36 < 255 ? f * 36 : 255;
m_pixels[j * m_size.x + i] = u8vec4(red, green, blue, 0);
}
else
{
m_pixels[j * m_size.x + i] = u8vec4(0, 0, 0, 0);
}
}

glEnable(GL_TEXTURE_2D);
@@ -185,6 +208,10 @@ private:

int main()
{
#if defined _WIN32
_chdir("../..");
#endif

Application app("Tutorial 3: Fractal", ivec2(640, 480), 60.0f);

new DebugFps(5, 5);


Chargement…
Annuler
Enregistrer