transform to pascal case
This commit is contained in:
parent
6d7a4c03d5
commit
4d3474bc18
@ -30,15 +30,15 @@ private:
|
||||
|
||||
int canvasSize = 0;
|
||||
Vector2 start = {0};
|
||||
std::list<DrawArgs> draw_calls;
|
||||
std::list<DrawArgs> drawCalls;
|
||||
|
||||
void drawBranch();
|
||||
|
||||
inline int get_num_of_branches(int dep);
|
||||
inline Color get_start_color(DrawArgs &arg);
|
||||
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);
|
||||
inline float get_lenght(DrawArgs &arg);
|
||||
inline float get_angle_var(DrawArgs &arg);
|
||||
inline int getNumOfBranches(int dep);
|
||||
inline Color getStartColor(DrawArgs &arg);
|
||||
inline Color getEndColor(int dep, Color &start);
|
||||
inline int getStartSize(DrawArgs &arg);
|
||||
inline int getEndSize(DrawArgs &arg, int start);
|
||||
inline float getLength(DrawArgs &arg);
|
||||
inline float getAngleVar(DrawArgs &arg);
|
||||
};
|
@ -33,19 +33,19 @@ struct Branch
|
||||
int8_t colorR_change;
|
||||
int8_t colorG_change;
|
||||
int8_t colorB_change;
|
||||
uint8_t color_var;
|
||||
uint8_t colorVar;
|
||||
|
||||
uint8_t size;
|
||||
uint8_t size_parent;
|
||||
uint8_t size_level;
|
||||
uint8_t size_change;
|
||||
uint8_t size_var;
|
||||
uint8_t sizeParent;
|
||||
uint8_t sizeLevel;
|
||||
uint8_t sizeChange;
|
||||
uint8_t sizeVar;
|
||||
|
||||
uint8_t length;
|
||||
uint8_t length_var;
|
||||
uint8_t lengthVar;
|
||||
|
||||
uint8_t branch_count;
|
||||
uint8_t branch_angle_var;
|
||||
uint8_t branchCount;
|
||||
uint8_t branchAngleVar;
|
||||
};
|
||||
|
||||
struct Dna
|
||||
|
@ -10,24 +10,23 @@
|
||||
|
||||
#define ITER_PER_FRAME 5000
|
||||
|
||||
constexpr int max_num_of_branches = 3;
|
||||
constexpr int max_color_change = 15;
|
||||
constexpr int min_color_change = -15;
|
||||
constexpr float color_parent_mix = 0.6f;
|
||||
constexpr int maxColorChange = 15;
|
||||
constexpr int minColorChange = -15;
|
||||
constexpr float colorParentMix = 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 maxSize = 20;
|
||||
constexpr int minSize = 2;
|
||||
constexpr int maxSizeVar = 5;
|
||||
constexpr int minSizeVar = -5;
|
||||
constexpr int maxSizeChange = 5;
|
||||
constexpr int MinSizeChange = -5;
|
||||
constexpr int sizes[] = {2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
|
||||
static_assert(sizeof(sizes) / sizeof(int) == MAX_POSIBLE_DEPTH);
|
||||
|
||||
float lengths[MAX_DEPTH];
|
||||
|
||||
constexpr float max_angles[] = {5.0f, 5.0f, 5.0f, 10.0f, 10.0f, 10.0f, 15.0f, 15.0f, 20.0f, 20.0f, 20.0f};
|
||||
static_assert(sizeof(max_angles) / sizeof(float) == MAX_POSIBLE_DEPTH);
|
||||
constexpr float maxAngles[] = {5.0f, 5.0f, 5.0f, 10.0f, 10.0f, 10.0f, 15.0f, 15.0f, 20.0f, 20.0f, 20.0f};
|
||||
static_assert(sizeof(maxAngles) / sizeof(float) == MAX_POSIBLE_DEPTH);
|
||||
|
||||
void calculateLevels(int canvasSize)
|
||||
{
|
||||
@ -53,51 +52,51 @@ void Tree::draw(Dna *dna)
|
||||
|
||||
m_dna = dna;
|
||||
branchSeed = dna->branchSeed;
|
||||
draw_calls.push_back({start, 180.0f, 0});
|
||||
drawCalls.push_back({start, 180.0f, 0});
|
||||
tick();
|
||||
}
|
||||
|
||||
bool Tree::tick()
|
||||
{
|
||||
size_t i = 0;
|
||||
while (!draw_calls.empty())
|
||||
while (!drawCalls.empty())
|
||||
{
|
||||
drawBranch();
|
||||
draw_calls.pop_front();
|
||||
drawCalls.pop_front();
|
||||
i++;
|
||||
if (i >= ITER_PER_FRAME)
|
||||
break;
|
||||
}
|
||||
|
||||
return draw_calls.empty();
|
||||
return drawCalls.empty();
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
void Tree::drawBranch()
|
||||
{
|
||||
DrawArgs arg = draw_calls.front();
|
||||
DrawArgs arg = drawCalls.front();
|
||||
if (arg.dep == MAX_DEPTH)
|
||||
return;
|
||||
float angle_var = get_angle_var(arg);
|
||||
float angle = ((arg.angleDeg + angle_var) * PI) / 180.0f;
|
||||
float length = get_lenght(arg);
|
||||
float angleVar = getAngleVar(arg);
|
||||
float angle = ((arg.angleDeg + angleVar) * PI) / 180.0f;
|
||||
float length = getLength(arg);
|
||||
float nx = length * std::sin(angle);
|
||||
float ny = length * std::cos(angle);
|
||||
Vector2 end = {arg.start.x + nx, arg.start.y + ny};
|
||||
|
||||
int size_start = get_start_size(arg);
|
||||
int size_end = get_end_size(arg, size_start);
|
||||
float fstep = 1.0 / ((length / size_start) * 2.0f);
|
||||
int sizeStart = getStartSize(arg);
|
||||
int sizeEnd = getEndSize(arg, sizeStart);
|
||||
float fstep = 1.0 / ((length / sizeStart) * 2.0f);
|
||||
|
||||
Color colorStart = get_start_color(arg);
|
||||
Color colorEnd = get_end_color(arg.dep, colorStart);
|
||||
Color colorStart = getStartColor(arg);
|
||||
Color colorEnd = getEndColor(arg.dep, colorStart);
|
||||
|
||||
for (float i = 0; i < 1; i += fstep)
|
||||
{
|
||||
Vector2 point = Vector2Lerp(arg.start, end, i);
|
||||
Color color = ColorLerp(colorStart, colorEnd, i);
|
||||
int size = Lerp(size_start, size_end, i);
|
||||
int size = Lerp(sizeStart, sizeEnd, i);
|
||||
DrawCircleV(point, size, 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
|
||||
@ -111,25 +110,25 @@ void Tree::drawBranch()
|
||||
if (arg.dep + 1 >= MAX_DEPTH)
|
||||
return;
|
||||
|
||||
float sectors = get_num_of_branches(arg.dep) + 1;
|
||||
float sectors = getNumOfBranches(arg.dep) + 1;
|
||||
float degres = 180.0f / sectors;
|
||||
|
||||
for (size_t i = 0; i < get_num_of_branches(arg.dep); i++)
|
||||
for (size_t i = 0; i < getNumOfBranches(arg.dep); i++)
|
||||
{
|
||||
float newAngle = arg.angleDeg - 90 + (degres * (i + 1));
|
||||
draw_calls.push_back({end, newAngle, arg.dep + 1, colorEnd, size_end});
|
||||
drawCalls.push_back({end, newAngle, arg.dep + 1, colorEnd, sizeEnd});
|
||||
}
|
||||
}
|
||||
|
||||
inline int Tree::get_num_of_branches(int dep)
|
||||
inline int Tree::getNumOfBranches(int dep)
|
||||
{
|
||||
if (m_dna->branches[dep].branch_count < 128)
|
||||
if (m_dna->branches[dep].branchCount < 128)
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline Color Tree::get_start_color(DrawArgs &arg)
|
||||
inline Color Tree::getStartColor(DrawArgs &arg)
|
||||
{
|
||||
Color ret = {
|
||||
m_dna->branches[arg.dep].colorR,
|
||||
@ -139,18 +138,18 @@ inline Color Tree::get_start_color(DrawArgs &arg)
|
||||
|
||||
if (arg.dep > 0)
|
||||
{
|
||||
ret = ColorLerp(ret, arg.parent, color_parent_mix);
|
||||
ret = ColorLerp(ret, arg.parent, colorParentMix);
|
||||
}
|
||||
|
||||
int color_var = Remap(m_dna->branches[arg.dep].color_var, 0, 255, min_color_change, max_color_change);
|
||||
ret.r += color_var * mrand::getFloat(&branchSeed);
|
||||
ret.g += color_var * mrand::getFloat(&branchSeed);
|
||||
ret.b += color_var * mrand::getFloat(&branchSeed);
|
||||
int colorVar = Remap(m_dna->branches[arg.dep].colorVar, 0, 255, minColorChange, maxColorChange);
|
||||
ret.r += colorVar * mrand::getFloat(&branchSeed);
|
||||
ret.g += colorVar * mrand::getFloat(&branchSeed);
|
||||
ret.b += colorVar * mrand::getFloat(&branchSeed);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline Color Tree::get_end_color(int dep, Color &start)
|
||||
inline Color Tree::getEndColor(int dep, Color &start)
|
||||
{
|
||||
return {
|
||||
start.r + m_dna->branches[dep].colorR_change,
|
||||
@ -159,28 +158,28 @@ inline Color Tree::get_end_color(int dep, Color &start)
|
||||
255};
|
||||
}
|
||||
|
||||
inline int Tree::get_start_size(DrawArgs &arg)
|
||||
inline int Tree::getStartSize(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);
|
||||
int size = Remap(m_dna->branches[arg.dep].size, 0, 255, minSize, maxSize);
|
||||
size += Remap(m_dna->branches[arg.dep].sizeVar, 0, 255, minSizeVar, maxSizeVar) * 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 sizeParent = m_dna->branches[arg.dep].sizeParent / 255.0f;
|
||||
size = std::lerp(size, arg.size, sizeParent);
|
||||
}
|
||||
|
||||
float mix_level = m_dna->branches[arg.dep].size_level / 255.0f;
|
||||
size = std::lerp(size, sizes[MAX_DEPTH - arg.dep - 1], mix_level);
|
||||
float mixLevel = m_dna->branches[arg.dep].sizeLevel / 255.0f;
|
||||
size = std::lerp(size, sizes[MAX_DEPTH - arg.dep - 1], mixLevel);
|
||||
|
||||
if (size < 1)
|
||||
size = 1;
|
||||
return size;
|
||||
}
|
||||
|
||||
inline int Tree::get_end_size(DrawArgs &arg, int start)
|
||||
inline int Tree::getEndSize(DrawArgs &arg, int start)
|
||||
{
|
||||
int size = Remap(m_dna->branches[arg.dep].size_change, 0, 255, min_size_change, max_size_chnage);
|
||||
int size = Remap(m_dna->branches[arg.dep].sizeChange, 0, 255, MinSizeChange, maxSizeChange);
|
||||
size += start;
|
||||
|
||||
if (size < 1)
|
||||
@ -188,23 +187,23 @@ inline int Tree::get_end_size(DrawArgs &arg, int start)
|
||||
return size;
|
||||
}
|
||||
|
||||
inline float Tree::get_lenght(DrawArgs &arg)
|
||||
inline float Tree::getLength(DrawArgs &arg)
|
||||
{
|
||||
float lenght = lengths[arg.dep];
|
||||
float lenght_ratio = Remap(m_dna->branches[arg.dep].length, 0, 255, 0.5f, 1.3f);
|
||||
lenght *= lenght_ratio;
|
||||
float lenght_var = Remap(m_dna->branches[arg.dep].length_var, 0, 255, -0.15f, 0.15f);
|
||||
lenght += lenght * lenght_var * mrand::getFloat(&branchSeed);
|
||||
float lenghtRatio = Remap(m_dna->branches[arg.dep].length, 0, 255, 0.5f, 1.3f);
|
||||
lenght *= lenghtRatio;
|
||||
float lenghtVar = Remap(m_dna->branches[arg.dep].lengthVar, 0, 255, -0.15f, 0.15f);
|
||||
lenght += lenght * lenghtVar * mrand::getFloat(&branchSeed);
|
||||
if (lenght < 1)
|
||||
lenght = 1;
|
||||
return lenght;
|
||||
}
|
||||
|
||||
inline float Tree::get_angle_var(DrawArgs &arg)
|
||||
inline float Tree::getAngleVar(DrawArgs &arg)
|
||||
{
|
||||
float angle_var = Remap(m_dna->branches[arg.dep].branch_angle_var, 0, 255, 0.0f, max_angles[arg.dep]);
|
||||
float angleVar = Remap(m_dna->branches[arg.dep].branchAngleVar, 0, 255, 0.0f, maxAngles[arg.dep]);
|
||||
|
||||
angle_var = Lerp(angle_var, -angle_var, mrand::getFloat(&branchSeed));
|
||||
angleVar = Lerp(angleVar, -angleVar, mrand::getFloat(&branchSeed));
|
||||
|
||||
return angle_var;
|
||||
return angleVar;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user