Skip to content

Commit

Permalink
Fixing GenImagePerlinNoise() being stretched, if Image is not rectang…
Browse files Browse the repository at this point in the history
…ular (#4276)
  • Loading branch information
Bugsia committed Aug 23, 2024
1 parent 74350fa commit 77172e3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,13 +1112,18 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
{
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));

float aspectRatio = (float)width / (float)height;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
float nx = (float)(x + offsetX)*(scale/(float)width);
float ny = (float)(y + offsetY)*(scale/(float)height);

// Apply aspect ratio compensation to wider side
if (width > height) nx *= aspectRatio;
else ny /= aspectRatio;

// Basic perlin noise implementation (not used)
//float p = (stb_perlin_noise3(nx, ny, 0.0f, 0, 0, 0);

Expand Down

0 comments on commit 77172e3

Please sign in to comment.