MCPcopy Create free account
hub / github.com/SFML/SFML / getTerrainColor

Function getTerrainColor

examples/island/Island.cpp:196–215  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Get the terrain color for the given elevation and moisture. ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

194///
195////////////////////////////////////////////////////////////
196sf::Color getTerrainColor(float elevation, float moisture)
197{
198 if (elevation < 0.11f)
199 return {0, 0, static_cast<std::uint8_t>(elevation / 0.11f * 74.f + 181.0f)};
200 if (elevation < 0.14f)
201 return {static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
202 static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
203 255};
204 if (elevation < 0.16f)
205 return {static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
206 static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
207 static_cast<std::uint8_t>(127.0f + (0.16f - elevation) * 128.f / 0.02f)};
208 if (elevation < 0.17f)
209 return {240, 230, 140};
210 if (elevation < 0.4f)
211 return getLowlandsTerrainColor(moisture);
212 if (elevation < snowcapHeight)
213 return getHighlandsTerrainColor(elevation, moisture);
214 return getSnowcapTerrainColor(elevation, moisture);
215}
216
217
218////////////////////////////////////////////////////////////

Callers 1

computeVertexFunction · 0.85

Calls 3

getLowlandsTerrainColorFunction · 0.85
getHighlandsTerrainColorFunction · 0.85
getSnowcapTerrainColorFunction · 0.85

Tested by

no test coverage detected