random num of branches
This commit is contained in:
parent
0fd7aeb8d7
commit
a286744fe5
13
main.cpp
13
main.cpp
@ -26,6 +26,7 @@ Color ColorLerp(Color c1, Color c2, float amount)
|
|||||||
struct branch
|
struct branch
|
||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
|
uint8_t numOfBranches;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct draw_args
|
struct draw_args
|
||||||
@ -68,8 +69,14 @@ void draw_branch(draw_args arg)
|
|||||||
Vector2 next = draw_line(arg.start, arg.angleDeg, arg.lenghth, arg.dep);
|
Vector2 next = draw_line(arg.start, arg.angleDeg, arg.lenghth, arg.dep);
|
||||||
|
|
||||||
float next_len = 0.7f;
|
float next_len = 0.7f;
|
||||||
draw_calls.push_back((draw_args){next, arg.angleDeg + 45, arg.lenghth * next_len, arg.dep + 1});
|
float sectors = tree[arg.dep].numOfBranches + 1;
|
||||||
draw_calls.push_back((draw_args){next, arg.angleDeg - 45, arg.lenghth * next_len, arg.dep + 1});
|
float degres = 180.0f / sectors;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < tree[arg.dep].numOfBranches; i++)
|
||||||
|
{
|
||||||
|
float newAngle = arg.angleDeg - 90 + (degres * (i + 1));
|
||||||
|
draw_calls.push_back((draw_args){next, newAngle, arg.lenghth * next_len, arg.dep + 1});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_tree(draw_args first)
|
void draw_tree(draw_args first)
|
||||||
@ -91,6 +98,8 @@ void generate_tree()
|
|||||||
uint8_t g = GetRandomValue(0, 255);
|
uint8_t g = GetRandomValue(0, 255);
|
||||||
uint8_t b = GetRandomValue(0, 255);
|
uint8_t b = GetRandomValue(0, 255);
|
||||||
tree[i].color = (Color){r, g, b, 255};
|
tree[i].color = (Color){r, g, b, 255};
|
||||||
|
|
||||||
|
tree[i].numOfBranches = GetRandomValue(1, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
tree[0].color = tree[1].color;
|
tree[0].color = tree[1].color;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user