Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public static int X_WIDTH = 1000;
- public static int Y_WIDTH = 1000;
- public static int RADIUS_SIZE = 50;
- public void RENDER(int personX, int personY)
- {
- Node[] nodes = new Node[]
- {
- new Node(1,100,100,Color.Red),
- new Node(2,150,100,Color.Blue),
- new Node(3,125,150,Color.Green)
- };
- Bitmap bmp = new Bitmap(X_WIDTH, Y_WIDTH);
- for (int x = 0; x < X_WIDTH; x++)
- {
- for (int y = 0; y < Y_WIDTH; y++)
- {
- foreach (Node n in nodes)
- {
- double deltaR = n.GetDistance(x,y);
- if (deltaR < RADIUS_SIZE && (deltaR > RADIUS_SIZE - 1))
- {
- bmp.SetPixel(x, y, ControlPaint.LightLight( n.Color));
- }
- }
- }
- }
- foreach (Node n in nodes)
- {
- bmp.SetPixel(n.Pos.X, n.Pos.Y, n.Color);
- }
- bmp.SetPixel(personX, personY, Color.Black);
- IEnumerable<Beacon> beacons = nodes.Select(n => new Beacon(n.Id, n.GetDistance(personX, personY))).Where(b => b.Distance <= 50);
- for (int x = 0; x < X_WIDTH; x++)
- {
- for (int y = 0; y < Y_WIDTH; y++)
- {
- foreach (Beacon b in beacons)
- {
- Node n = nodes.SingleOrDefault(no => no.Id == b.Id);
- double deltaR = n.GetDistance(x, y);
- if (deltaR < b.Distance && (deltaR > b.Distance - 1))
- {
- bmp.SetPixel(x, y, ControlPaint.Dark(n.Color));
- }
- }
- }
- }
- pictureBox1.Image = bmp;
- Position calcPos = GetPos(beacons, b => nodes.SingleOrDefault(n => b.Id == n.Id));
- MessageBox.Show(String.Format("Actual: {0},{1}\nCalc: {2},{3}", personX, personY, calcPos.X, calcPos.Y));
- }
- public Position GetPos(IEnumerable<Beacon> beacons, Func<Beacon,Node> getNode)
- {
- Position pos = new Position(0,0);
- return pos;
- }
- public Form1()
- {
- InitializeComponent();
- pictureBox1.MouseClick += new MouseEventHandler(pictureBox1_MouseClick);
- }
- void pictureBox1_MouseClick(object sender, MouseEventArgs e)
- {
- RENDER(e.X, e.Y);
- }
- }
- public class Node
- {
- public Position Pos;
- public Color Color;
- public int Id;
- public Node(int id, int x, int y, Color color)
- {
- Id = id;
- Pos = new Position(x, y);
- Color = color;
- }
- public double GetDistance(int x, int y)
- {
- int deltaX = Math.Abs(x - this.Pos.X);
- int deltaY = Math.Abs(y - this.Pos.Y);
- double deltaR = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
- return deltaR;
- }
- }
- public class Beacon
- {
- public int Id;
- public double Distance;
- public Beacon(int id, double distance)
- {
- Id = id;
- Distance = distance;
- }
- }
- public class Position
- {
- public int X;
- public int Y;
- public Position(int x, int y)
- {
- X = x;
- Y = y;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement