diff options
| author | Ray <[email protected]> | 2017-06-28 18:27:55 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-06-28 18:27:55 +0200 |
| commit | 5f5bd20f07754323619424e9dca60941d83de302 (patch) | |
| tree | 791a8a4bc04a3ae8dd38d40058184587f4c5a068 /src | |
| parent | c3049a9b06490df865d92009dc80ad0683305128 (diff) | |
| parent | 786cd63057d77e7987fe68986da6bca103c96415 (diff) | |
| download | raylib-5f5bd20f07754323619424e9dca60941d83de302.tar.gz raylib-5f5bd20f07754323619424e9dca60941d83de302.zip | |
Merge pull request #312 from nounoursheureux/image_gen
Add a density parameter to GenImageRadialGradient
Diffstat (limited to 'src')
| -rw-r--r-- | src/raylib.h | 2 | ||||
| -rw-r--r-- | src/textures.c | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/raylib.h b/src/raylib.h index a9483f31..0a4ce091 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -877,7 +877,7 @@ RLAPI void ImageColorBrightness(Image *image, int brightness); // Image generation functions RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient -RLAPI Image GenImageRadialGradient(int width, int height, Color inner, Color outer); // Generate image: radial gradient +RLAPI Image GenImageRadialGradient(int width, int height, float density, Color inner, Color outer); // Generate image: radial 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, float scale); // Generate image: perlin noise diff --git a/src/textures.c b/src/textures.c index 67d03d8d..9b0067cf 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1493,7 +1493,7 @@ Image GenImageGradientH(int width, int height, Color left, Color right) } // Generate image: radial gradient -Image GenImageRadialGradient(int width, int height, Color inner, Color outer) +Image GenImageRadialGradient(int width, int height, float density, Color inner, Color outer) { Color *pixels = (Color*)malloc(width * height * sizeof(Color)); float radius = (width < height) ? (float)width / 2.f : (float)height / 2.f; @@ -1505,7 +1505,8 @@ Image GenImageRadialGradient(int width, int height, Color inner, Color outer) for (int x = 0; x < width; x++) { float dist = hypotf((float)x - center_x, (float)y - center_y); - float factor = dist / radius; + float factor = (dist - radius * density) / (radius * (1.f - density)); + factor = fmax(factor, 0.f); factor = fmin(factor, 1.f); // dist can be bigger than radius so we have to check pixels[y*width + x].r = (int)((float)outer.r * factor + (float)inner.r * (1.f - factor)); pixels[y*width + x].g = (int)((float)outer.g * factor + (float)inner.g * (1.f - factor)); |
