10 changed files with 192 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||
using speedLight.BL.Models; |
|||
|
|||
namespace speedLight.BL.Intf; |
|||
|
|||
public interface IMechanicProvider |
|||
{ |
|||
IEnumerable<Mechanic> GetMechanics(); |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using speedLight.BL.Models; |
|||
|
|||
namespace speedLight.BL.Intf; |
|||
|
|||
public interface IPictureSourceProvider |
|||
{ |
|||
IEnumerable<Picture> GetPictureItems(); |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
namespace speedLight.BL.Models; |
|||
|
|||
public class Ball |
|||
{ |
|||
public long PathCount { get; set; } |
|||
public Point Location { get;set; } = new Point(0,0); |
|||
public Point From { get; set; } = new Point(0,0); |
|||
public Point To { get; set; } = new Point(0,0); |
|||
public double SpeedX { get; set; } |
|||
public double SpeedY { get; set; } |
|||
|
|||
public void Init(Point from, Point to, double speed) |
|||
{ |
|||
Location = new Point(from.X, from.Y); |
|||
From = new Point(from.X, from.Y); |
|||
To = new Point(to.X, to.Y); |
|||
double sin = (From.Y - To.Y) / (From.X - To.X); |
|||
SpeedY = speed * sin; |
|||
SpeedX = speed * (1 / sin); |
|||
} |
|||
|
|||
public void Move() |
|||
{ |
|||
double minX = From.X < To.X ? From.X : To.X; |
|||
double minY = From.Y < To.Y ? From.Y : To.Y; |
|||
double maxX = From.X > To.X ? From.X : To.X; |
|||
double maxY = From.Y > To.Y ? From.Y : To.Y; |
|||
if ((minX > Location.X) || (maxX < Location.X)) |
|||
{ |
|||
SpeedX = -SpeedX; |
|||
PathCount++; |
|||
} |
|||
if ((minY > Location.Y) || (maxY < Location.Y)) |
|||
{ |
|||
SpeedY = -SpeedY; |
|||
PathCount++; |
|||
} |
|||
|
|||
Location.X += SpeedX; |
|||
Location.Y += SpeedY; |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace speedLight.BL.Models; |
|||
|
|||
public class Mechanic |
|||
{ |
|||
|
|||
|
|||
public Mechanic(double speed, string title) |
|||
{ |
|||
Speed = speed; |
|||
Title = title; |
|||
} |
|||
|
|||
public string Title { get; set; } |
|||
public double Speed { get; set; } |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace speedLight.BL.Models; |
|||
|
|||
public class Picture |
|||
{ |
|||
public override string ToString() |
|||
{ |
|||
return $"{Name} ({Distance} м.)"; |
|||
} |
|||
|
|||
public Point PointFrom { get; set; } |
|||
public Point PointTo { get; set; } |
|||
public double Distance { get; set; } |
|||
public string Name { get; set; } |
|||
public string Url { get; set; } |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace speedLight.BL.Models; |
|||
|
|||
public class PictureList |
|||
{ |
|||
public List<Picture> Items { get; private set; } = new List<Picture>(); |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace speedLight.BL.Models; |
|||
|
|||
public class Point |
|||
{ |
|||
public Point(double x, double y) |
|||
{ |
|||
X = x; |
|||
Y = y; |
|||
} |
|||
|
|||
public double X { get; set; } |
|||
public double Y { get; set; } |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using speedLight.BL.Intf; |
|||
using speedLight.BL.Models; |
|||
|
|||
namespace speedLight.BL.Providers; |
|||
|
|||
public class DataProvider: IMechanicProvider, IPictureSourceProvider |
|||
{ |
|||
public IEnumerable<Mechanic> GetMechanics() |
|||
{ |
|||
return new List<Mechanic>() |
|||
{ |
|||
new Mechanic(300, "Звук"), |
|||
new Mechanic(300000000, "Свет"), |
|||
}; |
|||
} |
|||
|
|||
public IEnumerable<Picture> GetPictureItems() |
|||
{ |
|||
return new List<Picture>() |
|||
{ |
|||
new Picture() |
|||
{ |
|||
Name = "Эйфелева башня", |
|||
PointFrom = new Point(100, 100), |
|||
PointTo = new Point(100, 200), |
|||
Distance = 330, |
|||
Url = "https://cdn2.tu-tu.ru/image/pagetree_node_data/1/13d18a14f7afddb06f546aa1aba237cc/", |
|||
}, |
|||
new Picture() |
|||
{ |
|||
Name = "Камп Ноу", |
|||
PointFrom = new Point(100, 100), |
|||
PointTo = new Point(100, 200), |
|||
Distance = 120, |
|||
Url = "https://footballtravel.com/uploads/2020/06/Camp-Nou-1024x683.jpg" |
|||
}, |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Net.Http; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Media.Imaging; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace speedLight.UI.Helpers; |
|||
|
|||
public class ImageHelper |
|||
{ |
|||
public static Bitmap LoadFromResource(Uri resourceUri) |
|||
{ |
|||
return new Bitmap(AssetLoader.Open(resourceUri)); |
|||
} |
|||
|
|||
public static async Task<Bitmap?> LoadFromWeb(Uri url) |
|||
{ |
|||
using var httpClient = new HttpClient(); |
|||
try |
|||
{ |
|||
var response = await httpClient.GetAsync(url); |
|||
response.EnsureSuccessStatusCode(); |
|||
var data = await response.Content.ReadAsByteArrayAsync(); |
|||
return new Bitmap(new MemoryStream(data)); |
|||
} |
|||
catch (HttpRequestException ex) |
|||
{ |
|||
Console.WriteLine($"An error occurred while downloading image '{url}' : {ex.Message}"); |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace speedLight.UI.Models; |
|||
|
|||
public class ScreenPoint |
|||
{ |
|||
public ScreenPoint(int x, int y) |
|||
{ |
|||
X = x; |
|||
Y = y; |
|||
} |
|||
|
|||
public int X { get; set; } |
|||
public int Y { get; set; } |
|||
} |
|||
Loading…
Reference in new issue