From eb4020a4eed9b50ac1caa82eaddf8e21c12bb741 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Thu, 2 May 2024 20:50:45 +0200 Subject: [PATCH] add Color class for easy change --- inc/canvas/BackGround.hpp | 6 ------ inc/canvas/BackGroundColors.hpp | 13 +++++++++++++ src/canvas/BackGround.cpp | 18 ++++++++++-------- src/canvas/BackGroundColors.cpp | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 inc/canvas/BackGroundColors.hpp create mode 100644 src/canvas/BackGroundColors.cpp diff --git a/inc/canvas/BackGround.hpp b/inc/canvas/BackGround.hpp index aa61bf1..34c9649 100644 --- a/inc/canvas/BackGround.hpp +++ b/inc/canvas/BackGround.hpp @@ -18,12 +18,8 @@ private: int size = 0; Texture2D texShapes = {1, 1, 1, 1, 7}; - Color backGroundColor = {21, 34, 56, 255}; - size_t numOfStarts = 150; - Color starColor = WHITE; - Color moonColor = {240, 240, 190, 255}; float minSizeOfMoon = 0.05f; float maxSizeOfMoon = 0.075f; float maxYPosOfMoon = 0.75f; @@ -32,8 +28,6 @@ private: float bigRingBlend = 0.02f; float smallRingBlend = 0.05f; - Color backMountenColor = {28, 28, 38, 255}; - Color frontMountenColor = {0, 0, 0, 255}; float colorRatio1 = 0.3f; float colorRatio2 = 0.5f; float mounten1 = 0.6875f; diff --git a/inc/canvas/BackGroundColors.hpp b/inc/canvas/BackGroundColors.hpp new file mode 100644 index 0000000..b8ea1c3 --- /dev/null +++ b/inc/canvas/BackGroundColors.hpp @@ -0,0 +1,13 @@ +#include "raylib.h" + +class BackGroundColors +{ +private: +public: + static void setColor(); + static Color backGroundColor; + static Color starColor; + static Color moonColor; + static Color backMountenColor; + static Color frontMountenColor; +}; diff --git a/src/canvas/BackGround.cpp b/src/canvas/BackGround.cpp index 4b11386..e183fa4 100644 --- a/src/canvas/BackGround.cpp +++ b/src/canvas/BackGround.cpp @@ -1,4 +1,5 @@ #include "canvas/BackGround.hpp" +#include "canvas/BackGroundColors.hpp" #include "Math.hpp" #include "raylib.h" @@ -14,12 +15,13 @@ void BackGround::init(int size) void BackGround::newGen() { - ClearBackground(backGroundColor); + BackGroundColors::setColor(); + ClearBackground(BackGroundColors::backGroundColor); starts(); moon(); - mounten(20, 0.3, (int)(mounten1 * size), (int)(mounten2 * size), backMountenColor); - mounten(21, 0.3, (int)(mounten2 * size), (int)(mounten3 * size), ColorLerp(backMountenColor, frontMountenColor, colorRatio1)); - mounten(23, 0.3, (int)(mounten3 * size), (int)(mounten4 * size), ColorLerp(backMountenColor, frontMountenColor, colorRatio2)); + mounten(20, 0.3, (int)(mounten1 * size), (int)(mounten2 * size), BackGroundColors::backMountenColor); + mounten(21, 0.3, (int)(mounten2 * size), (int)(mounten3 * size), ColorLerp(BackGroundColors::backMountenColor, BackGroundColors::frontMountenColor, colorRatio1)); + mounten(23, 0.3, (int)(mounten3 * size), (int)(mounten4 * size), ColorLerp(BackGroundColors::backMountenColor, BackGroundColors::frontMountenColor, colorRatio2)); } void BackGround::starts() @@ -37,7 +39,7 @@ void BackGround::starts() int weight = GetRandomValue(1, 3); float alph = ((float)GetRandomValue(10, 200)) / 255.0f; - Color color = ColorLerp(backGroundColor, starColor, alph); + Color color = ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::starColor, alph); rlColor4ub(color.r, color.g, color.b, color.a); if (star) @@ -72,9 +74,9 @@ void BackGround::moon() int ring1 = (float)r * bigRingRatio; int ring2 = (float)r * smallRingRatio; - DrawCircle(xpos, ypos, r + ring1, ColorLerp(backGroundColor, moonColor, bigRingBlend)); - DrawCircle(xpos, ypos, r + ring2, ColorLerp(backGroundColor, moonColor, smallRingBlend)); - DrawCircle(xpos, ypos, r, moonColor); + DrawCircle(xpos, ypos, r + ring1, ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::moonColor, bigRingBlend)); + DrawCircle(xpos, ypos, r + ring2, ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::moonColor, smallRingBlend)); + DrawCircle(xpos, ypos, r, BackGroundColors::moonColor); } void BackGround::mounten(size_t mountenSegments, float scale, int min, int max, Color color) diff --git a/src/canvas/BackGroundColors.cpp b/src/canvas/BackGroundColors.cpp new file mode 100644 index 0000000..8ab0191 --- /dev/null +++ b/src/canvas/BackGroundColors.cpp @@ -0,0 +1,16 @@ +#include "canvas/BackGroundColors.hpp" + +Color BackGroundColors::backGroundColor; +Color BackGroundColors::starColor; +Color BackGroundColors::moonColor; +Color BackGroundColors::backMountenColor; +Color BackGroundColors::frontMountenColor; + +void BackGroundColors::setColor() +{ + backGroundColor = {21, 34, 56, 255}; + starColor = WHITE; + moonColor = {240, 240, 190, 255}; + backMountenColor = {28, 28, 38, 255}; + frontMountenColor = {0, 0, 0, 255}; +}