glerminal/examples/towers.cpp

83 lines
1.4 KiB
C++
Raw Normal View History

#include <glerminal.h>
#include <cstdlib>
#include <cmath>
namespace
{
void init()
{
for (int i = 1; i < 256; i++)
{
constexpr unsigned char c = 0;
const unsigned char v = (255 - c) * powf((i - 1) / 256.0f, 4.0f) + c;
glerminal_update_palette(i, (v << 24) | (v << 16) | (v << 8) | 0xE0);
}
for (int i = 1; i < 256; i++)
{
const unsigned char j = i;
glerminal_update_sprite(i,
{
0,j,0,0,0,0,j,0,
j,j,j,j,j,j,j,j,
0,j,0,0,0,0,j,0,
0,j,0,0,0,0,j,0,
0,j,0,0,0,0,j,0,
0,j,0,0,0,0,j,0,
j,j,j,j,j,j,j,j,
0,j,0,0,0,0,j,0,
});
}
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 25; j++)
{
for (int k = 0; k < 256; k++)
{
glerminal_set(i, j, k, k);
}
}
}
}
void mainloop(float dt)
{
static float time = 1;
time += dt;
if (time < 1.0f)
{
return;
}
else
{
time = 0;
}
const int cx = rand() % 40;
const int cy = rand() % 25;
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 25; j++)
{
for (int k = 0; k < 256; k++)
{
const float ox = 0.05f * powf(k, 0.55f) * copysignf(sqrtf((i - cx) * (i - cx)), i - cx);
const float oy = 0.05f * powf(k, 0.55f) * copysignf(sqrtf((j - cy) * (j - cy)), j - cy);
glerminal_offset(i, j, k, ox, oy);
}
}
}
glerminal_flush();
}
}
int main(int argc, char** argv)
{
glerminal_run(init, mainloop);
}