Add DNA to background
This commit is contained in:
parent
8ad328eb1e
commit
ee7b674c6d
@ -1,39 +1,33 @@
|
||||
#include <vector>
|
||||
|
||||
#include "canvas/Sun.hpp"
|
||||
#include "values/Dna.hpp"
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
struct Moon
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float size;
|
||||
};
|
||||
|
||||
class BackGround
|
||||
{
|
||||
|
||||
public:
|
||||
BackGround() = default;
|
||||
~BackGround() = default;
|
||||
void init(int size);
|
||||
void init(int canvasSize);
|
||||
void deinit();
|
||||
void newGen();
|
||||
void draw();
|
||||
void draw(Dna *dna);
|
||||
|
||||
private:
|
||||
void drawStars();
|
||||
void drawSun();
|
||||
void drawMounten(size_t mountenSegments, int min, int max, Color color);
|
||||
|
||||
Dna *m_dna;
|
||||
|
||||
uint128 mountenSeed;
|
||||
uint128 starSeed;
|
||||
|
||||
Sun sun;
|
||||
|
||||
Moon m_moon;
|
||||
int colorSet;
|
||||
int time;
|
||||
|
||||
int size = 0;
|
||||
int canvasSize = 0;
|
||||
|
||||
constexpr static size_t numOfStarts = 150;
|
||||
constexpr static float moonXOffset = 0.1f;
|
||||
|
27
inc/values/Dna.hpp
Normal file
27
inc/values/Dna.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include <cinttypes>
|
||||
|
||||
struct uint128
|
||||
{
|
||||
uint32_t a;
|
||||
uint32_t b;
|
||||
uint32_t c;
|
||||
uint32_t d;
|
||||
};
|
||||
|
||||
struct Moon
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float size;
|
||||
};
|
||||
|
||||
struct Dna
|
||||
{
|
||||
Moon moon;
|
||||
int colorSet;
|
||||
int time;
|
||||
uint128 mountenSeed;
|
||||
uint128 starSeed;
|
||||
};
|
||||
|
||||
Dna newDna();
|
@ -1,8 +1,13 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
struct uint128;
|
||||
|
||||
namespace mrand
|
||||
{
|
||||
void setSeed(unsigned long long seed);
|
||||
int getValue(int min, int max);
|
||||
float getFloat(uint128 *state);
|
||||
float getFloat();
|
||||
int getValue(int min, int max, uint128 *state);
|
||||
uint32_t getInt();
|
||||
}
|
@ -10,9 +10,9 @@
|
||||
#include <raymath.h>
|
||||
|
||||
// Public
|
||||
void BackGround::init(int size)
|
||||
void BackGround::init(int canvasSize)
|
||||
{
|
||||
this->size = size;
|
||||
this->canvasSize = canvasSize;
|
||||
sun.init();
|
||||
}
|
||||
|
||||
@ -21,34 +21,28 @@ void BackGround::deinit()
|
||||
sun.deinit();
|
||||
}
|
||||
|
||||
void BackGround::newGen()
|
||||
void BackGround::draw(Dna *dna)
|
||||
{
|
||||
m_dna = dna;
|
||||
mountenSeed = dna->mountenSeed;
|
||||
starSeed = dna->starSeed;
|
||||
|
||||
m_moon = {mrand::getFloat(), mrand::getFloat(), mrand::getFloat()};
|
||||
colorSet = mrand::getValue(0, 3);
|
||||
time = floor(Remap(m_moon.y, 0, 1, 4, 0));
|
||||
BackGroundColors::setColor(m_dna->colorSet, m_dna->time);
|
||||
|
||||
BackGroundColors::setColor(colorSet, time);
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
void BackGround::draw()
|
||||
{
|
||||
if (colorSet == 3)
|
||||
if (m_dna->colorSet == 3)
|
||||
{
|
||||
ClearBackground(BackGroundColors::backGroundColor);
|
||||
drawStars();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawRectangleGradientV(0, 0, size, size, ColorAdd(BackGroundColors::backGroundColor, 60), BackGroundColors::backGroundColor);
|
||||
DrawRectangleGradientV(0, 0, canvasSize, canvasSize, ColorAdd(BackGroundColors::backGroundColor, 60), BackGroundColors::backGroundColor);
|
||||
}
|
||||
|
||||
drawSun();
|
||||
drawMounten(20, (int)(mounten1min * size), (int)(mounten1max * size), BackGroundColors::MountenColor1);
|
||||
drawMounten(21, (int)(mounten2min * size), (int)(mounten2max * size), BackGroundColors::MountenColor2);
|
||||
drawMounten(23, (int)(mounten3min * size), (int)(mounten3max * size), BackGroundColors::MountenColor3);
|
||||
drawMounten(20, (int)(mounten1min * canvasSize), (int)(mounten1max * canvasSize), BackGroundColors::MountenColor1);
|
||||
drawMounten(21, (int)(mounten2min * canvasSize), (int)(mounten2max * canvasSize), BackGroundColors::MountenColor2);
|
||||
drawMounten(23, (int)(mounten3min * canvasSize), (int)(mounten3max * canvasSize), BackGroundColors::MountenColor3);
|
||||
}
|
||||
|
||||
void BackGround::drawStars()
|
||||
@ -60,10 +54,10 @@ void BackGround::drawStars()
|
||||
|
||||
for (size_t i = 0; i < numOfStarts; i++)
|
||||
{
|
||||
int x = mrand::getFloat() * size;
|
||||
int y = mrand::getFloat() * size;
|
||||
int weight = mrand::getFloat() * 3 + 1;
|
||||
float alph = Normalize(mrand::getFloat(), 0.04f, 0.8f);
|
||||
int x = mrand::getFloat(&starSeed) * canvasSize;
|
||||
int y = mrand::getFloat(&starSeed) * canvasSize;
|
||||
int weight = mrand::getFloat(&starSeed) * 3 + 1;
|
||||
float alph = Normalize(mrand::getFloat(&starSeed), 0.04f, 0.8f);
|
||||
Color color = ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::starColor, alph);
|
||||
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
@ -93,21 +87,21 @@ void BackGround::drawStars()
|
||||
|
||||
void BackGround::drawSun()
|
||||
{
|
||||
int r = ((m_moon.y * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * size;
|
||||
int xpos = Lerp(size * moonXOffset, size - size * moonXOffset, m_moon.x);
|
||||
int ypos = Lerp(size * moonXOffset, maxYPosOfMoon * size, m_moon.y);
|
||||
int r = ((m_dna->moon.y * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
||||
int xpos = Lerp(canvasSize * moonXOffset, canvasSize - canvasSize * moonXOffset, m_dna->moon.x);
|
||||
int ypos = Lerp(canvasSize * moonXOffset, maxYPosOfMoon * canvasSize, m_dna->moon.y);
|
||||
|
||||
if (colorSet == 3)
|
||||
if (m_dna->colorSet == 3)
|
||||
{
|
||||
sun.setColor(BackGroundColors::moonColor);
|
||||
r = ((m_moon.size * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * size;
|
||||
r = ((m_dna->moon.size * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color color = {0};
|
||||
color.r = 255;
|
||||
color.g = std::lerp(200, 50, m_moon.y);
|
||||
color.b = std::lerp(50, 0, m_moon.y);
|
||||
color.g = std::lerp(200, 50, m_dna->moon.y);
|
||||
color.b = std::lerp(50, 0, m_dna->moon.y);
|
||||
color.a = 255;
|
||||
|
||||
sun.setColor(color);
|
||||
@ -118,9 +112,9 @@ void BackGround::drawSun()
|
||||
void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color color)
|
||||
{
|
||||
int x = 0;
|
||||
int diff = size / (mountenSegments - 1);
|
||||
int diff = canvasSize / (mountenSegments - 1);
|
||||
|
||||
float p = mrand::getFloat();
|
||||
float p = mrand::getFloat(&mountenSeed);
|
||||
|
||||
int y = Lerp(min, max, p);
|
||||
rlSetTexture(1);
|
||||
@ -133,20 +127,20 @@ void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color col
|
||||
// topLeft
|
||||
rlVertex2f(x, y);
|
||||
// bottomLeft
|
||||
rlVertex2f(x, size);
|
||||
rlVertex2f(x, canvasSize);
|
||||
|
||||
p = mrand::getFloat();
|
||||
p = mrand::getFloat(&mountenSeed);
|
||||
y = Lerp(min, max, p);
|
||||
x += diff;
|
||||
// topRight
|
||||
rlVertex2f(x, y);
|
||||
|
||||
// bottomRight
|
||||
rlVertex2f(x, size);
|
||||
rlVertex2f(x, canvasSize);
|
||||
// topRight
|
||||
rlVertex2f(x, y);
|
||||
|
||||
rlVertex2f(x - diff, size);
|
||||
rlVertex2f(x - diff, canvasSize);
|
||||
}
|
||||
rlEnd();
|
||||
rlSetTexture(0);
|
||||
|
@ -11,7 +11,9 @@ void Canvas::newGen(RenderTexture2D &target)
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
|
||||
backGround.newGen();
|
||||
Dna dna = newDna();
|
||||
|
||||
backGround.draw(&dna);
|
||||
tree.newGen();
|
||||
|
||||
EndTextureMode();
|
||||
|
25
src/values/Dna.cpp
Normal file
25
src/values/Dna.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
#include "values/Dna.hpp"
|
||||
#include "values/mrand.hpp"
|
||||
|
||||
#include <raymath.h>
|
||||
|
||||
Dna newDna()
|
||||
{
|
||||
Dna dna = {0};
|
||||
dna.moon = {mrand::getFloat(), mrand::getFloat(), mrand::getFloat()};
|
||||
dna.colorSet = mrand::getValue(0, 3);
|
||||
dna.time = std::floor(Remap(mrand::getFloat(), 0, 1, 4, 0));
|
||||
|
||||
dna.mountenSeed.a = mrand::getInt();
|
||||
dna.mountenSeed.b = mrand::getInt();
|
||||
dna.mountenSeed.c = mrand::getInt();
|
||||
dna.mountenSeed.d = mrand::getInt();
|
||||
dna.starSeed.a = mrand::getInt();
|
||||
dna.starSeed.b = mrand::getInt();
|
||||
dna.starSeed.c = mrand::getInt();
|
||||
dna.starSeed.d = mrand::getInt();
|
||||
|
||||
return dna;
|
||||
}
|
@ -48,6 +48,11 @@ namespace mrand
|
||||
rprand_state[3] = (uint32_t)((rprand_splitmix64(rprand_seed) & 0xffffffff00000000) >> 32);
|
||||
}
|
||||
|
||||
uint32_t getInt()
|
||||
{
|
||||
return my_rprand_xoshiro(rprand_state);
|
||||
}
|
||||
|
||||
int getValue(int min, int max)
|
||||
{
|
||||
int value = my_rprand_xoshiro(rprand_state) % (std::abs(max - min) + 1) + min;
|
||||
@ -60,15 +65,15 @@ namespace mrand
|
||||
return my_rprand_xoshiro(rprand_state) / 4294967295.0f;
|
||||
}
|
||||
|
||||
int getValue(int min, int max, uint32_t state[4])
|
||||
int getValue(int min, int max, uint128 *state)
|
||||
{
|
||||
int value = my_rprand_xoshiro(state) % (std::abs(max - min) + 1) + min;
|
||||
int value = my_rprand_xoshiro((uint32_t *)state) % (std::abs(max - min) + 1) + min;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
float getFloat(uint32_t state[4])
|
||||
float getFloat(uint128 *state)
|
||||
{
|
||||
return my_rprand_xoshiro(state) / 4294967295.0f;
|
||||
return my_rprand_xoshiro((uint32_t *)state) / 4294967295.0f;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user