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