Add strings with info every 1 minute of route travelled

This commit is contained in:
glax 2024-07-24 22:09:45 +02:00
parent d07deeccaf
commit 02e3b1e5a3

View File

@ -16,11 +16,12 @@ public static class Renderer
float deltaLat = maxCoordinates.Item1 - minCoordinates.Item1; float deltaLat = maxCoordinates.Item1 - minCoordinates.Item1;
float deltaLon = maxCoordinates.Item2 - minCoordinates.Item2; float deltaLon = maxCoordinates.Item2 - minCoordinates.Item2;
float multiplier = deltaLat > deltaLon ? longestEdge / deltaLat : longestEdge / deltaLon; float multiplier = deltaLat > deltaLon ? longestEdge / deltaLat : longestEdge / deltaLon;
int width = (int)(deltaLon * multiplier);
int height = (int)(deltaLat * multiplier);
Bitmap bitmap = new(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Bitmap bitmap = new((int)(deltaLon * multiplier), (int)(deltaLat * multiplier), System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics graphics = Graphics.FromImage(bitmap); Graphics graphics = Graphics.FromImage(bitmap);
Pen previous = new (Color.White, 2); Pen previous = new (Color.LightSeaGreen, 2);
using(GraphicsPath capPath = new ()) using(GraphicsPath capPath = new ())
{ {
// A triangle // A triangle
@ -50,15 +51,27 @@ public static class Renderer
if (r.RouteFound) if (r.RouteFound)
{ {
Pen route = new(Color.Red, 2); Pen route = new(Color.Blue, 4);
TimeSpan previousPrint = TimeSpan.Zero;
float distance = 0;
TimeSpan time = TimeSpan.Zero;
foreach (Step step in r.Steps) foreach (Step step in r.Steps)
{ {
Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height); Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height);
Point endCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node2, minCoordinates, multiplier, bitmap.Height); Point endCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node2, minCoordinates, multiplier, bitmap.Height);
graphics.DrawLine(route, startCoordinates, endCoordinates); graphics.DrawLine(route, startCoordinates, endCoordinates);
distance += step.Distance;
time += TimeSpan.FromHours(step.Distance / 1000 / step.Speed);
if (time - previousPrint > TimeSpan.FromSeconds(60))
{
previousPrint += TimeSpan.FromSeconds(60);
Point printCoordinates = new(endCoordinates.X + 30, endCoordinates.Y + 30);
graphics.DrawLine(route, endCoordinates, printCoordinates);
graphics.DrawString($"{distance:000000}m\n{time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 8), new SolidBrush(Color.Blue), printCoordinates);
}
} }
graphics.DrawString($"Distance: {r.Distance:000000.00}m\nTime: {r.Time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 18), new SolidBrush(Color.White), 2, 2); graphics.DrawString($"Distance: {r.Distance:000000.00}m\nTime: {r.Time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 24), new SolidBrush(Color.White), 2, 2);
} }
Directory.CreateDirectory(new FileInfo(outputPath).DirectoryName!); Directory.CreateDirectory(new FileInfo(outputPath).DirectoryName!);