add Color class for easy change

This commit is contained in:
Nikola Petrov 2024-05-02 20:50:45 +02:00
parent 513874d61c
commit eb4020a4ee
4 changed files with 39 additions and 14 deletions

View File

@ -18,12 +18,8 @@ private:
int size = 0; int size = 0;
Texture2D texShapes = {1, 1, 1, 1, 7}; Texture2D texShapes = {1, 1, 1, 1, 7};
Color backGroundColor = {21, 34, 56, 255};
size_t numOfStarts = 150; size_t numOfStarts = 150;
Color starColor = WHITE;
Color moonColor = {240, 240, 190, 255};
float minSizeOfMoon = 0.05f; float minSizeOfMoon = 0.05f;
float maxSizeOfMoon = 0.075f; float maxSizeOfMoon = 0.075f;
float maxYPosOfMoon = 0.75f; float maxYPosOfMoon = 0.75f;
@ -32,8 +28,6 @@ private:
float bigRingBlend = 0.02f; float bigRingBlend = 0.02f;
float smallRingBlend = 0.05f; float smallRingBlend = 0.05f;
Color backMountenColor = {28, 28, 38, 255};
Color frontMountenColor = {0, 0, 0, 255};
float colorRatio1 = 0.3f; float colorRatio1 = 0.3f;
float colorRatio2 = 0.5f; float colorRatio2 = 0.5f;
float mounten1 = 0.6875f; float mounten1 = 0.6875f;

View File

@ -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;
};

View File

@ -1,4 +1,5 @@
#include "canvas/BackGround.hpp" #include "canvas/BackGround.hpp"
#include "canvas/BackGroundColors.hpp"
#include "Math.hpp" #include "Math.hpp"
#include "raylib.h" #include "raylib.h"
@ -14,12 +15,13 @@ void BackGround::init(int size)
void BackGround::newGen() void BackGround::newGen()
{ {
ClearBackground(backGroundColor); BackGroundColors::setColor();
ClearBackground(BackGroundColors::backGroundColor);
starts(); starts();
moon(); moon();
mounten(20, 0.3, (int)(mounten1 * size), (int)(mounten2 * size), backMountenColor); mounten(20, 0.3, (int)(mounten1 * size), (int)(mounten2 * size), BackGroundColors::backMountenColor);
mounten(21, 0.3, (int)(mounten2 * size), (int)(mounten3 * size), ColorLerp(backMountenColor, frontMountenColor, colorRatio1)); 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(backMountenColor, frontMountenColor, colorRatio2)); mounten(23, 0.3, (int)(mounten3 * size), (int)(mounten4 * size), ColorLerp(BackGroundColors::backMountenColor, BackGroundColors::frontMountenColor, colorRatio2));
} }
void BackGround::starts() void BackGround::starts()
@ -37,7 +39,7 @@ void BackGround::starts()
int weight = GetRandomValue(1, 3); int weight = GetRandomValue(1, 3);
float alph = ((float)GetRandomValue(10, 200)) / 255.0f; 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); rlColor4ub(color.r, color.g, color.b, color.a);
if (star) if (star)
@ -72,9 +74,9 @@ void BackGround::moon()
int ring1 = (float)r * bigRingRatio; int ring1 = (float)r * bigRingRatio;
int ring2 = (float)r * smallRingRatio; int ring2 = (float)r * smallRingRatio;
DrawCircle(xpos, ypos, r + ring1, ColorLerp(backGroundColor, moonColor, bigRingBlend)); DrawCircle(xpos, ypos, r + ring1, ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::moonColor, bigRingBlend));
DrawCircle(xpos, ypos, r + ring2, ColorLerp(backGroundColor, moonColor, smallRingBlend)); DrawCircle(xpos, ypos, r + ring2, ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::moonColor, smallRingBlend));
DrawCircle(xpos, ypos, r, moonColor); DrawCircle(xpos, ypos, r, BackGroundColors::moonColor);
} }
void BackGround::mounten(size_t mountenSegments, float scale, int min, int max, Color color) void BackGround::mounten(size_t mountenSegments, float scale, int min, int max, Color color)

View File

@ -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};
}