Implemented population center generator
This commit is contained in:
@ -12,7 +12,8 @@ namespace TransportGame.MapViewer
|
||||
{
|
||||
None = 0,
|
||||
Elevation = 1,
|
||||
All = Elevation
|
||||
Population = 2,
|
||||
All = Elevation | Population
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@ -36,7 +37,7 @@ namespace TransportGame.MapViewer
|
||||
|
||||
private readonly Color WaterColor = Colors.Navy;
|
||||
private readonly Color ElevationTerrainColor = Colors.White;
|
||||
private readonly Color TerrainColor = Colors.Gray;
|
||||
private readonly Color TerrainColor = Colors.Silver;
|
||||
|
||||
public MapRenderer()
|
||||
{
|
||||
@ -57,14 +58,24 @@ namespace TransportGame.MapViewer
|
||||
Bitmap24 bitmap = new Bitmap24(Convert.ToInt32(map.Width * Scale), Convert.ToInt32(map.Height * Scale));
|
||||
|
||||
// First layer - cells
|
||||
DrawCells(bitmap, map, (layers & Layers.Elevation) > 0);
|
||||
DrawPixels(bitmap, map, (layers & Layers.Elevation) > 0, (layers & Layers.Population) > 0);
|
||||
|
||||
// Done
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCells(Bitmap24 bitmap, Map map, bool elevation)
|
||||
private Color AlphaBlend(Color top, Color dst)
|
||||
{
|
||||
float A = top.ScA + dst.ScA * (1 - top.ScA);
|
||||
float R = (top.ScR * top.ScA + dst.ScR * (1 - top.ScA)) / A;
|
||||
float G = (top.ScG * top.ScA + dst.ScG * (1 - top.ScA)) / A;
|
||||
float B = (top.ScB * top.ScA + dst.ScB * (1 - top.ScA)) / A;
|
||||
|
||||
return Color.FromScRgb(A, R, G, B);
|
||||
}
|
||||
|
||||
private void DrawPixels(Bitmap24 bitmap, Map map, bool elevation, bool population)
|
||||
{
|
||||
for (int x = 0; x < bitmap.Width; x++)
|
||||
for (int y = 0; y < bitmap.Height; y++)
|
||||
@ -76,17 +87,24 @@ namespace TransportGame.MapViewer
|
||||
if (map.IsWater(mapX, mapY))
|
||||
bitmap[x, y] = WaterColor;
|
||||
|
||||
// Draw elevation
|
||||
else if (elevation)
|
||||
{
|
||||
float alpha = map.Heightmap[mapX, mapY]; // map.Heights range is [0,1]
|
||||
bitmap[x, y] = Color.Multiply(ElevationTerrainColor, alpha);
|
||||
}
|
||||
|
||||
// Draw terrain
|
||||
else
|
||||
{
|
||||
bitmap[x, y] = TerrainColor;
|
||||
// Draw elevation
|
||||
if (elevation)
|
||||
{
|
||||
float alpha = map.Heightmap[mapX, mapY]; // map.Heights range is [0,1]
|
||||
bitmap[x, y] = Color.Multiply(ElevationTerrainColor, alpha);
|
||||
}
|
||||
|
||||
// No elevation, just put a terrain color
|
||||
else bitmap[x, y] = TerrainColor;
|
||||
|
||||
// Population
|
||||
if (population)
|
||||
{
|
||||
Color popColor = Color.FromScRgb(map.GetPopulation(mapX, mapY) * 0.7f, 1, 0, 1);
|
||||
bitmap[x, y] = AlphaBlend(popColor, bitmap[x, y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user