Use size from dna on the tree
This commit is contained in:
parent
5670183dc0
commit
f60b63e082
@ -9,9 +9,10 @@ struct DrawArgs
|
|||||||
{
|
{
|
||||||
Vector2 start;
|
Vector2 start;
|
||||||
float angleDeg;
|
float angleDeg;
|
||||||
float lenghth;
|
float length;
|
||||||
int dep;
|
int dep;
|
||||||
Color parent;
|
Color parent;
|
||||||
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tree
|
class Tree
|
||||||
@ -28,13 +29,15 @@ private:
|
|||||||
Dna *m_dna;
|
Dna *m_dna;
|
||||||
uint128 branchSeed;
|
uint128 branchSeed;
|
||||||
|
|
||||||
int size = 0;
|
int canvasSize = 0;
|
||||||
Vector2 start = {0};
|
Vector2 start = {0};
|
||||||
std::list<DrawArgs> draw_calls;
|
std::list<DrawArgs> draw_calls;
|
||||||
|
|
||||||
void drawBranch();
|
void drawBranch();
|
||||||
|
|
||||||
inline uint8_t get_num_of_branches(uint8_t dep);
|
inline int get_num_of_branches(int dep);
|
||||||
inline Color get_start_color(DrawArgs &arg);
|
inline Color get_start_color(DrawArgs &arg);
|
||||||
inline Color get_end_color(uint8_t dep, Color &start);
|
inline Color get_end_color(int dep, Color &start);
|
||||||
|
inline int get_start_size(DrawArgs &arg);
|
||||||
|
inline int get_end_size(DrawArgs &arg, int start);
|
||||||
};
|
};
|
@ -36,6 +36,7 @@ struct Branch
|
|||||||
uint8_t size;
|
uint8_t size;
|
||||||
uint8_t size_parent;
|
uint8_t size_parent;
|
||||||
uint8_t size_level;
|
uint8_t size_level;
|
||||||
|
uint8_t size_change;
|
||||||
uint8_t size_var;
|
uint8_t size_var;
|
||||||
|
|
||||||
uint8_t length;
|
uint8_t length;
|
||||||
|
@ -15,10 +15,18 @@ constexpr int max_color_change = 15;
|
|||||||
constexpr int min_color_change = -15;
|
constexpr int min_color_change = -15;
|
||||||
constexpr float color_parent_mix = 0.6f;
|
constexpr float color_parent_mix = 0.6f;
|
||||||
|
|
||||||
|
constexpr int max_size = 20;
|
||||||
|
constexpr int min_size = 2;
|
||||||
|
constexpr int max_size_var = 5;
|
||||||
|
constexpr int min_size_var = -5;
|
||||||
|
constexpr int max_size_chnage = 5;
|
||||||
|
constexpr int min_size_change = -5;
|
||||||
|
|
||||||
|
constexpr int sizes[] = {2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
|
||||||
// Public
|
// Public
|
||||||
void Tree::init(int size)
|
void Tree::init(int size)
|
||||||
{
|
{
|
||||||
this->size = size;
|
this->canvasSize = size;
|
||||||
start.x = size / 2;
|
start.x = size / 2;
|
||||||
start.y = size;
|
start.y = size;
|
||||||
}
|
}
|
||||||
@ -29,7 +37,7 @@ void Tree::draw(Dna *dna)
|
|||||||
|
|
||||||
m_dna = dna;
|
m_dna = dna;
|
||||||
branchSeed = dna->branchSeed;
|
branchSeed = dna->branchSeed;
|
||||||
draw_calls.push_back({start, 0, (float)size / 4, 0});
|
draw_calls.push_back({start, 180.0f, (float)canvasSize / 4, 0});
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,23 +62,24 @@ void Tree::drawBranch()
|
|||||||
{
|
{
|
||||||
DrawArgs arg = draw_calls.front();
|
DrawArgs arg = draw_calls.front();
|
||||||
|
|
||||||
float angle = ((arg.angleDeg + 180.0f) * PI) / 180.0f;
|
float angle = ((arg.angleDeg) * PI) / 180.0f;
|
||||||
float nx = arg.lenghth * std::sin(angle);
|
float nx = arg.length * std::sin(angle);
|
||||||
float ny = arg.lenghth * std::cos(angle);
|
float ny = arg.length * std::cos(angle);
|
||||||
Vector2 end = {arg.start.x + nx, arg.start.y + ny};
|
Vector2 end = {arg.start.x + nx, arg.start.y + ny};
|
||||||
|
|
||||||
float thick = 2.0;
|
int size_start = get_start_size(arg);
|
||||||
float fstep = 1.0 / ((arg.lenghth / thick) * 1.5);
|
int size_end = get_end_size(arg, size_start);
|
||||||
|
float fstep = 1.0 / ((arg.length / size_start) * 2.0f);
|
||||||
|
|
||||||
Color colorStart = get_start_color(arg);
|
Color colorStart = get_start_color(arg);
|
||||||
|
|
||||||
Color colorEnd = get_end_color(arg.dep, colorStart);
|
Color colorEnd = get_end_color(arg.dep, colorStart);
|
||||||
|
|
||||||
for (float i = 0; i < 1; i += fstep)
|
for (float i = 0; i < 1; i += fstep)
|
||||||
{
|
{
|
||||||
Vector2 point = Vector2Lerp(arg.start, end, i);
|
Vector2 point = Vector2Lerp(arg.start, end, i);
|
||||||
Color color = ColorLerp(colorStart, colorEnd, i);
|
Color color = ColorLerp(colorStart, colorEnd, i);
|
||||||
DrawCircleV(point, thick, color); // Fester on the phone to call DrawCircle insted of the Circle shader
|
int size = Lerp(size_start, size_end, i);
|
||||||
|
DrawCircleV(point, size, color); // Fester on the phone to call DrawCircle insted of the Circle shader
|
||||||
// Circle::setColor(color);
|
// Circle::setColor(color);
|
||||||
// Circle::draw(point.x, point.y, thick); // TODO Change to BeginShaderMode and EndShaderMode only onece
|
// Circle::draw(point.x, point.y, thick); // TODO Change to BeginShaderMode and EndShaderMode only onece
|
||||||
|
|
||||||
@ -90,11 +99,11 @@ void Tree::drawBranch()
|
|||||||
for (size_t i = 0; i < get_num_of_branches(arg.dep); i++)
|
for (size_t i = 0; i < get_num_of_branches(arg.dep); i++)
|
||||||
{
|
{
|
||||||
float newAngle = arg.angleDeg - 90 + (degres * (i + 1));
|
float newAngle = arg.angleDeg - 90 + (degres * (i + 1));
|
||||||
draw_calls.push_back({end, newAngle, arg.lenghth * next_len, arg.dep + 1, colorEnd});
|
draw_calls.push_back({end, newAngle, arg.length * next_len, arg.dep + 1, colorEnd, size_end});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint8_t Tree::get_num_of_branches(uint8_t dep)
|
inline int Tree::get_num_of_branches(int dep)
|
||||||
{
|
{
|
||||||
if (m_dna->branches[dep].branch_count < 128)
|
if (m_dna->branches[dep].branch_count < 128)
|
||||||
return 2;
|
return 2;
|
||||||
@ -123,7 +132,7 @@ inline Color Tree::get_start_color(DrawArgs &arg)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color Tree::get_end_color(uint8_t dep, Color &start)
|
inline Color Tree::get_end_color(int dep, Color &start)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
start.r + m_dna->branches[dep].colorR_change,
|
start.r + m_dna->branches[dep].colorR_change,
|
||||||
@ -131,3 +140,32 @@ inline Color Tree::get_end_color(uint8_t dep, Color &start)
|
|||||||
start.b + m_dna->branches[dep].colorB_change,
|
start.b + m_dna->branches[dep].colorB_change,
|
||||||
255};
|
255};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int Tree::get_start_size(DrawArgs &arg)
|
||||||
|
{
|
||||||
|
int size = Remap(m_dna->branches[arg.dep].size, 0, 255, min_size, max_size);
|
||||||
|
size += Remap(m_dna->branches[arg.dep].size_var, 0, 255, min_size_var, max_size_var) * mrand::getFloat(&branchSeed);
|
||||||
|
|
||||||
|
if (arg.dep > 0)
|
||||||
|
{
|
||||||
|
float size_parent = m_dna->branches[arg.dep].size_parent / 255.0f;
|
||||||
|
size = std::lerp(size, arg.size, size_parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
float mix_level = m_dna->branches[arg.dep].size_level / 255.0f;
|
||||||
|
size = std::lerp(size, sizes[MAX_DEPTH - arg.dep - 1], mix_level);
|
||||||
|
|
||||||
|
if (size < 1)
|
||||||
|
size = 1;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int Tree::get_end_size(DrawArgs &arg, int start)
|
||||||
|
{
|
||||||
|
int size = Remap(m_dna->branches[arg.dep].size_change, 0, 255, min_size_change, max_size_chnage);
|
||||||
|
size += start;
|
||||||
|
|
||||||
|
if (size < 1)
|
||||||
|
size = 1;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user