diff --git a/parser/output/raylib_api.xml b/parser/output/raylib_api.xml index 1c77f0266..40a70ae7f 100644 --- a/parser/output/raylib_api.xml +++ b/parser/output/raylib_api.xml @@ -1563,6 +1563,15 @@ + + + + + + + + + diff --git a/projects/Geany/raylib.c.tags b/projects/Geany/raylib.c.tags index d41809983..23296648e 100644 --- a/projects/Geany/raylib.c.tags +++ b/projects/Geany/raylib.c.tags @@ -213,6 +213,7 @@ ImageColorReplace|void|(Image *image, Color color, Color replace);| GenImageColor|Image|(int width, int height, Color color);| GenImageGradientLinear|Image|(int width, int height, int direction, Color start, Color end);| GenImageGradientRadial|Image|(int width, int height, float density, Color inner, Color outer);| +GenImageGradientSquare|Image|(int width, int height, int gradientWidth, int gradientHeight, float density, Color inner, Color outer);| GenImageChecked|Image|(int width, int height, int checksX, int checksY, Color col1, Color col2);| GenImageWhiteNoise|Image|(int width, int height, float factor);| GenImagePerlinNoise|Image|(int width, int height, int offsetX, int offsetY, float scale);| diff --git a/projects/Notepad++/raylib_npp_parser/raylib_npp.xml b/projects/Notepad++/raylib_npp_parser/raylib_npp.xml index 890501f2c..2dcd994aa 100644 --- a/projects/Notepad++/raylib_npp_parser/raylib_npp.xml +++ b/projects/Notepad++/raylib_npp_parser/raylib_npp.xml @@ -1396,6 +1396,17 @@ + + + + + + + + + + + diff --git a/projects/Notepad++/raylib_npp_parser/raylib_to_parse.h b/projects/Notepad++/raylib_npp_parser/raylib_to_parse.h index 3f8450130..b09e53f5a 100644 --- a/projects/Notepad++/raylib_npp_parser/raylib_to_parse.h +++ b/projects/Notepad++/raylib_npp_parser/raylib_to_parse.h @@ -319,6 +319,7 @@ RLAPI bool ExportImageAsCode(Image image, const char *fileName); RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color RLAPI Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end); // Generate image: linear gradient RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient +RLAPI Image GenImageGradientSquare(int width, int height, int gradientWidth, int gradientHeight, float density, Color inner, Color outer); // Generate image: square gradient RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise diff --git a/src/raylib.h b/src/raylib.h index 02d8e4445..cbaac57a0 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1241,6 +1241,7 @@ RLAPI bool ExportImageAsCode(Image image, const char *fileName); RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color RLAPI Image GenImageGradientLinear(int width, int height, int direction, Color start, Color end); // Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient +RLAPI Image GenImageGradientSquare(int width, int height, int gradientWidth, int gradientHeight, float density, Color inner, Color outer); // Generate image: square gradient RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise diff --git a/src/rtextures.c b/src/rtextures.c index d1cebe0d4..4ff9f5274 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -764,6 +764,55 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner, return image; } +// Generate image: square gradient +Image GenImageGradientSquare(int width, int weight, int gradientWidth, int gradientHeight, float density, Color inner, Color outer) +{ + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); + + float centerX = (float)width/2.0f; + float centerY = (float)height/2.0f; + + float gradientCenterX = gradientWidth / 2.0f; + float gradientCenterY = gradientHeight / 2.0f; + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + // Calculate the Manhattan distance from the center + float distX = fabsf(x - centerX); + float distY = fabsf(y - centerY); + + // Normalize the distances by the dimensions of the gradient rectangle + float normalizedDistX = distX / gradientCenterX; + float normalizedDistY = distY / gradientCenterY; + + // Calculate the total normalized Manhattan distance + float manhattanDist = fmax(normalizedDistX, normalizedDistY) * density; + + // Clamp the factor between 0 and 1 + float factor = fminf(fmaxf(manhattanDist, 0.f), 1.f); + + // Blend the colors based on the calculated factor + pixels[y*width + x].r = (int)((float)outer.r*factor + (float)inner.r*(1.0f - factor)); + pixels[y*width + x].g = (int)((float)outer.g*factor + (float)inner.g*(1.0f - factor)); + pixels[y*width + x].b = (int)((float)outer.b*factor + (float)inner.b*(1.0f - factor)); + pixels[y*width + x].a = (int)((float)outer.a*factor + (float)inner.a*(1.0f - factor)); + } + } + + Image image = { + .data = pixels, + .width = width, + .height = height, + .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, + .mipmaps = 1 + }; + + return image; +} + + // Generate image: checked Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2) {