Save point for converion of colors
This commit is contained in:
12
src/Math.cpp
12
src/Math.cpp
@@ -16,11 +16,21 @@ Color ColorLerp(Color c1, Color c2, float amount)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Color ColorAdd(Color c, int add)
|
||||
Color ColorAddValue(Color c, int add)
|
||||
{
|
||||
int r = std::clamp(c.r + add, 0, 255);
|
||||
int g = std::clamp(c.g + add, 0, 255);
|
||||
int b = std::clamp(c.b + add, 0, 255);
|
||||
|
||||
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, c.a};
|
||||
}
|
||||
|
||||
Color ColorAdd(Color c1, Color c2)
|
||||
{
|
||||
int r = std::clamp(c1.r + c2.r, 0, 255);
|
||||
int g = std::clamp(c1.g + c2.g, 0, 255);
|
||||
int b = std::clamp(c1.b + c2.b, 0, 255);
|
||||
int a = std::clamp(c1.a + c2.a, 0, 255);
|
||||
|
||||
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a};
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void BackGround::draw(Dna *dna)
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawRectangleGradientV(0, 0, canvasSize, canvasSize, ColorAdd(BackGroundColors::backGroundColor, 60), BackGroundColors::backGroundColor);
|
||||
DrawRectangleGradientV(0, 0, canvasSize, canvasSize, ColorAddValue(BackGroundColors::backGroundColor, 60), BackGroundColors::backGroundColor);
|
||||
}
|
||||
|
||||
drawSun();
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#define ITER_PER_FRAME 5000
|
||||
|
||||
constexpr int max_num_of_branches = 3;
|
||||
|
||||
// Public
|
||||
void Tree::init(int size)
|
||||
{
|
||||
@@ -22,6 +24,7 @@ void Tree::draw(Dna *dna)
|
||||
Circle::setSoftEdge(false);
|
||||
|
||||
m_dna = dna;
|
||||
branchSeed = dna->branchSeed;
|
||||
draw_calls.push_back({start, 0, (float)size / 4, 1});
|
||||
tick();
|
||||
}
|
||||
@@ -56,34 +59,24 @@ Vector2 Tree::drawLine()
|
||||
float thick = 2.0;
|
||||
float fstep = 1.0 / ((arg.lenghth / thick) * 1.5);
|
||||
|
||||
Color colorParent = {
|
||||
m_dna->branches[arg.dep - 1].colorR,
|
||||
m_dna->branches[arg.dep - 1].colorG,
|
||||
m_dna->branches[arg.dep - 1].colorB,
|
||||
255};
|
||||
Color colorStart = get_start_color(arg.dep);
|
||||
|
||||
Color colorM = {
|
||||
m_dna->branches[arg.dep].colorR,
|
||||
m_dna->branches[arg.dep].colorG,
|
||||
m_dna->branches[arg.dep].colorB,
|
||||
255};
|
||||
Color colorEnd = get_end_color(arg.dep, colorStart);
|
||||
|
||||
for (float i = 0; i < 1; i += fstep)
|
||||
{
|
||||
Vector2 point = Vector2Lerp(arg.start, end, i);
|
||||
Color color = ColorLerp(colorParent, colorM, i);
|
||||
Color color = ColorLerp(colorStart, colorEnd, i);
|
||||
DrawCircleV(point, thick, color); // Fester on the phone to call DrawCircle insted of the Circle shader
|
||||
// Circle::setColor(color);
|
||||
// Circle::draw(point.x, point.y, thick); // TODO Change to BeginShaderMode and EndShaderMode only onece
|
||||
|
||||
// use
|
||||
// DrawRectangleGradientEx
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
inline uint8_t get_num_of_branches(uint8_t count)
|
||||
{
|
||||
return ((float)count / 255.0f) * 3 + 1;
|
||||
}
|
||||
|
||||
void Tree::drawBranch()
|
||||
{
|
||||
DrawArgs arg = draw_calls.front();
|
||||
@@ -93,12 +86,48 @@ void Tree::drawBranch()
|
||||
Vector2 next = drawLine();
|
||||
|
||||
float next_len = 0.7f;
|
||||
float sectors = get_num_of_branches(m_dna->branches[arg.dep].branch_count) + 1;
|
||||
float sectors = get_num_of_branches(arg.dep) + 1;
|
||||
float degres = 180.0f / sectors;
|
||||
|
||||
for (size_t i = 0; i < get_num_of_branches(m_dna->branches[arg.dep].branch_count); i++)
|
||||
for (size_t i = 0; i < get_num_of_branches(arg.dep); i++)
|
||||
{
|
||||
float newAngle = arg.angleDeg - 90 + (degres * (i + 1));
|
||||
draw_calls.push_back({next, newAngle, arg.lenghth * next_len, arg.dep + 1});
|
||||
}
|
||||
}
|
||||
|
||||
inline uint8_t Tree::get_num_of_branches(uint8_t dep)
|
||||
{
|
||||
return ((float)m_dna->branches[dep].branch_count / 255.0f) * max_num_of_branches + 1;
|
||||
}
|
||||
|
||||
inline Color Tree::get_start_color(uint8_t dep)
|
||||
{
|
||||
Color ret = {
|
||||
m_dna->branches[dep].colorR,
|
||||
m_dna->branches[dep].colorG,
|
||||
m_dna->branches[dep].colorB,
|
||||
255};
|
||||
|
||||
if (dep > 0)
|
||||
{
|
||||
Color parent = {
|
||||
m_dna->branches[dep - 1].colorR,
|
||||
m_dna->branches[dep - 1].colorG,
|
||||
m_dna->branches[dep - 1].colorB,
|
||||
255};
|
||||
float mix = ((float)m_dna->branches[dep].color_parent) / 255.0f;
|
||||
ret = ColorLerp(ret, parent, mix);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline Color Tree::get_end_color(uint8_t dep, Color &start)
|
||||
{
|
||||
return {
|
||||
start.r + m_dna->branches[dep].colorR_change,
|
||||
start.g + m_dna->branches[dep].colorG_change,
|
||||
start.b + m_dna->branches[dep].colorB_change,
|
||||
255};
|
||||
}
|
||||
Reference in New Issue
Block a user