add redraw the tree with KEY_R
This commit is contained in:
parent
3d9e6c9f7d
commit
0fd7aeb8d7
39
main.cpp
39
main.cpp
@ -6,6 +6,12 @@
|
|||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#define MAX_DEPTH 11
|
#define MAX_DEPTH 11
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 800;
|
||||||
|
#define textureWidth screenWidth
|
||||||
|
#define textureHeight screenHeight
|
||||||
|
|
||||||
|
const Vector2 start = {textureWidth / 2, textureHeight};
|
||||||
|
|
||||||
Color ColorLerp(Color c1, Color c2, float amount)
|
Color ColorLerp(Color c1, Color c2, float amount)
|
||||||
{
|
{
|
||||||
@ -32,6 +38,7 @@ struct draw_args
|
|||||||
|
|
||||||
static std::vector<branch> tree(MAX_DEPTH);
|
static std::vector<branch> tree(MAX_DEPTH);
|
||||||
static std::list<draw_args> draw_calls;
|
static std::list<draw_args> draw_calls;
|
||||||
|
static RenderTexture2D target;
|
||||||
|
|
||||||
Vector2 draw_line(Vector2 start, float angleDeg, float lenghth, int dep)
|
Vector2 draw_line(Vector2 start, float angleDeg, float lenghth, int dep)
|
||||||
{
|
{
|
||||||
@ -89,27 +96,25 @@ void generate_tree()
|
|||||||
tree[0].color = tree[1].color;
|
tree[0].color = tree[1].color;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
void new_tree()
|
||||||
{
|
{
|
||||||
const int screenWidth = 800;
|
|
||||||
const int screenHeight = 800;
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib");
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
const int textureWidth = screenWidth;
|
|
||||||
const int textureHeight = screenHeight;
|
|
||||||
|
|
||||||
RenderTexture2D target = LoadRenderTexture(textureWidth, textureHeight);
|
|
||||||
Vector2 start = {textureWidth / 2, textureHeight};
|
|
||||||
|
|
||||||
generate_tree();
|
generate_tree();
|
||||||
|
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
draw_tree((draw_args){start, 0, textureHeight / 4, 1});
|
draw_tree((draw_args){start, 0, textureHeight / 4, 1});
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
target = LoadRenderTexture(textureWidth, textureHeight);
|
||||||
|
|
||||||
|
new_tree();
|
||||||
|
|
||||||
Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height};
|
Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height};
|
||||||
Rectangle dest = {0, 0, screenWidth, screenHeight};
|
Rectangle dest = {0, 0, screenWidth, screenHeight};
|
||||||
@ -118,6 +123,12 @@ int main(void)
|
|||||||
|
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_R))
|
||||||
|
{
|
||||||
|
new_tree();
|
||||||
|
}
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);
|
DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user