glerminal/examples/towers.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

#include <glerminal.h>
#include <cstdlib>
#include <cmath>
namespace
{
void init()
{
2024-05-17 04:51:45 +00:00
glerminal_update_sprite(1,
{
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
});
2024-05-17 04:51:45 +00:00
for (int i = 0; i < 256; i++)
{
2024-05-17 04:51:45 +00:00
constexpr unsigned char c = 32;
const unsigned char v = (255 - c) * powf((i - 1) / 256.0f, 2.0f) + c;
const unsigned int j = (0xFF << 24) | (v << 16) | (v << 8) | v;
glerminal_layer_color(i, j);
glerminal_layer_scale(i, i / 256.0f + 1);
}
}
void mainloop(float dt)
{
static float time = 1;
time += dt;
2024-05-17 04:51:45 +00:00
if (time < 0.15f)
{
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++)
{
2024-05-17 04:51:45 +00:00
const int c = rand() % 224 + 32;
for (int k = 0; k < 256; k++)
{
2024-05-17 04:51:45 +00:00
if (k < c)
{
glerminal_set(i, j, k, 1);
const float ox = 0.01f * k * (i - cx);
const float oy = 0.01f * k * (j - cy);
glerminal_offset(i, j, k, ox + (1 + 0.004f * k) * cosf(c * i + k * 6.28f / 128.0f), oy + (1 + 0.004f * k) * sinf(c * j + k * 6.28f / 128.0f));
}
else
{
glerminal_set(i, j, k, 0);
}
}
}
}
glerminal_flush();
}
}
int main(int argc, char** argv)
{
glerminal_run(init, mainloop);
}