using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
public class Particles
{
#region variables
public static Form _Instance;
public static (int, int)[] AvailableSpeeds;
public static int _CircleNum;
public static int _ConnectLines;
public static Random rand = new Random();
public static List<Circles> _Particles = new List<Circles>();
public static List<Lines> _Lines = new List<Lines>();
private static Bitmap _bufferBitmap;
public static Color _LineColor;
#endregion
public static void Setup(Form Instance, int CircleNum, Color CircleColor,
int ConnectLines, Color LineColor) //start
{
_Instance = Instance;
_CircleNum = CircleNum;
_ConnectLines = ConnectLines;
[Link] += DrawCirclesAndLines;
_LineColor = LineColor;
_bufferBitmap = new Bitmap(_Instance.Width, _Instance.Height);
List<(int, int)> speedsList = new List<(int, int)>();
for (int j = -1; j <= 1; j++)
{
for (int k = -1; k <= 1; k++)
{
if (j != 0 || k != 0)
{
[Link]((j, k));
}
}
}
Shuffle(speedsList);
while ([Link] < CircleNum * 2)
{
[Link](speedsList);
Shuffle(speedsList);
}
AvailableSpeeds = [Link](CircleNum * 2).ToArray();
for (int i = 0; i < CircleNum; i++)
{
var speedIndex = i % [Link];
var (speedX, speedY) = AvailableSpeeds[speedIndex];
_Particles.Add(new Circles()
{
Size = [Link](2, 2),
Pos = new Point([Link]([Link]),
[Link]([Link])),
Speed = new Point(speedX, speedY),
color = CircleColor,
Opacity = 255,
});
}
for (int i = 0; i < _Particles.Count; i++)
{
for (int j = i + 1; j < _Particles.Count; j++)
{
int x1 = _Particles[i].Pos.X;
int y1 = _Particles[i].Pos.Y;
int x2 = _Particles[j].Pos.X;
int y2 = _Particles[j].Pos.Y;
Lines newLine = new Lines
{
Size = 2,
Pos = new Point(x1, y1),
Pos2 = new Point(x2, y2),
Color = LineColor,
Opacity = 50
};
_Lines.Add(newLine);
}
}
public static void Shuffle<T>(List<T> list)
{
int n = [Link];
while (n > 1)
{
n--;
int k = [Link](n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
public static void MoveCircles(List<Circles> circles)
{
Random random = new Random();
for (int i = 0; i < [Link]; i++)
{
Circles circle = circles[i];
int newX = [Link].X + [Link].X;
int newY = [Link].Y + [Link].Y;
if (newX - [Link] < 0 || newX + [Link] >
_Instance.[Link])
{
[Link] = new Point(-[Link].X, [Link].Y);
}
if (newY - [Link] < 0 || newY + [Link] >
_Instance.[Link])
{
[Link] = new Point([Link].X, -[Link].Y);
}
[Link] = new Point(newX, newY);
circles[i] = circle;
}
public static void DrawCirclesAndLines(object sender, PaintEventArgs e)
{
if (_Instance.WindowState != [Link])
{
using (Graphics bufferGraphics = [Link](_bufferBitmap))
{
[Link] =
[Link];
[Link] =
[Link];
[Link] =
[Link];
[Link] =
[Link];
[Link] =
[Link];
[Link] =
[Link];
[Link](_Instance.BackColor);
DrawCircles(bufferGraphics);
DrawLines(bufferGraphics);
}
[Link](_bufferBitmap, [Link]);
}
}
public static void DrawCircles(Graphics g)
{
foreach (var circle in _Particles)
{
[Link](new SolidBrush([Link]([Link],
[Link])),
[Link].X - [Link], [Link].Y -
[Link],
[Link] * 2, [Link] * 2);
}
}
public static void DrawLines(Graphics g)
{
_Lines.Clear();
for (int i = 0; i < _Particles.Count; i++)
{
for (int j = i + 1; j < _Particles.Count; j++)
{
int x1 = _Particles[i].Pos.X;
int y1 = _Particles[i].Pos.Y;
int x2 = _Particles[j].Pos.X;
int y2 = _Particles[j].Pos.Y;
Lines newLine = new Lines
{
Size = 2,
Pos = new Point(x1, y1),
Pos2 = new Point(x2, y2),
Color = _LineColor,
Opacity = 25
};
_Lines.Add(newLine);
}
}
foreach (var line in _Lines)
{
double distance = CalculateDistance([Link], line.Pos2);
if (distance <= 45.0f)
{
using (Pen pen = new Pen([Link]([Link],
[Link]), [Link]))
{
[Link](pen, [Link], line.Pos2);
}
}
}
}
public static double CalculateDistance(Point p1, Point p2)
{
return [Link]([Link](p2.X - p1.X, 2) + [Link](p2.Y - p1.Y, 2));
}
}
public class Circles
{
public int Size { get; set; }
public Point Pos { get; set; }
public Point Speed { get; set; }
public Color color { get; set; }
public int Opacity { get; set; }
}
public class Lines
{
public int Size { get; set; }
public Point Pos { get; set; }
public Point Pos2 { get; set; }
public Color Color { get; set; }
public int Opacity { get; set; }
}
}