This commit is contained in:
2024-12-29 19:07:48 +01:00
parent e42cd89337
commit 25b18f8484
4 changed files with 48 additions and 65 deletions

View File

@@ -23,6 +23,7 @@ void Tree::draw(Dna *dna)
m_dna = dna;
draw_calls.push_back({start, 0, (float)size / 4, 1});
tick();
}
bool Tree::tick()
@@ -55,10 +56,22 @@ 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 colorM = {
m_dna->branches[arg.dep].colorR,
m_dna->branches[arg.dep].colorG,
m_dna->branches[arg.dep].colorB,
255};
for (float i = 0; i < 1; i += fstep)
{
Vector2 point = Vector2Lerp(arg.start, end, i);
Color color = ColorLerp(m_dna->branches[arg.dep - 1].color, m_dna->branches[arg.dep].color, i);
Color color = ColorLerp(colorParent, colorM, 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
@@ -66,6 +79,11 @@ Vector2 Tree::drawLine()
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();
@@ -74,11 +92,11 @@ void Tree::drawBranch()
Vector2 next = drawLine();
float next_len = m_dna->branches[arg.dep].lenghthRatio;
float sectors = m_dna->branches[arg.dep].numOfBranches + 1;
float next_len = 0.7f;
float sectors = get_num_of_branches(m_dna->branches[arg.dep].branch_count) + 1;
float degres = 180.0f / sectors;
for (size_t i = 0; i < m_dna->branches[arg.dep].numOfBranches; i++)
for (size_t i = 0; i < get_num_of_branches(m_dna->branches[arg.dep].branch_count); i++)
{
float newAngle = arg.angleDeg - 90 + (degres * (i + 1));
draw_calls.push_back({next, newAngle, arg.lenghth * next_len, arg.dep + 1});

View File

@@ -15,24 +15,25 @@ void newDna(Dna &dna)
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();
for (size_t i = 0; i < MAX_DEPTH; i++)
dna.branchSeed.a = mrand::getInt();
dna.branchSeed.b = mrand::getInt();
dna.branchSeed.c = mrand::getInt();
dna.branchSeed.d = mrand::getInt();
for (size_t i = 0; i < dna.branches.size(); i++)
{
uint8_t r = mrand::getValue(0, 255);
uint8_t g = mrand::getValue(0, 255);
uint8_t b = mrand::getValue(0, 255);
dna.branches[i].color = {r, g, b, 255};
dna.branches[i].numOfBranches = mrand::getValue(1, 3);
dna.branches[i].lenghthRatio = ((float)mrand::getValue(600, 700)) / 1000.0f;
uint8_t *array = (uint8_t *)&dna.branches[i];
for (size_t i = 0; i < sizeof(Branch); i++)
{
array[i] = mrand::getValue(0, 254);
}
}
dna.branches[0].color = dna.branches[1].color;
return;
}
}