using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test_security
{
public partial class Form7 : Form
{
private List<Particle> particles;
private Timer timer;
private Random random;
private readonly int particleCount = 100;
public Form7()
{
InitializeComponent();
InitializeParticles();
InitializeTimer();
}
private void InitializeParticles()
{
particles = new List<Particle>();
random = new Random();
for (int i = 0; i < particleCount; i++)
{
int size = random.Next(2, 15);
int speedX = random.Next(-5, 6);
int speedY = random.Next(-5, 6);
int x = random.Next(ClientSize.Width);
int y = random.Next(ClientSize.Height);
particles.Add(new Particle(new Point(x, y), size, speedX, speedY));
}
}
private void InitializeTimer()
{
timer = new Timer();
timer.Interval = 30; // Tiempo de actualización en milisegundos
timer.Tick += Timer_Tick;
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
foreach (Particle particle in particles)
{
particle.Update(ClientRectangle);
}
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
foreach (Particle particle in particles)
{
e.Graphics.DrawLine(Pens.Green, particle.Position,
particle.PreviousPosition);
}
}
}
public class Particle
{
public Point Position { get; private set; }
public Point PreviousPosition { get; private set; }
public int Size { get; private set; }
public int SpeedX { get; private set; }
public int SpeedY { get; private set; }
public Particle(Point position, int size, int speedX, int speedY)
{
Position = position;
PreviousPosition = position;
Size = size;
SpeedX = speedX;
SpeedY = speedY;
}
public void Update(Rectangle bounds)
{
PreviousPosition = Position;
Position = new Point(Position.X + SpeedX, Position.Y + SpeedY);
if (Position.X < bounds.Left || Position.X > bounds.Right - Size)
{
SpeedX *= -1;
}
if (Position.Y < bounds.Top || Position.Y > bounds.Bottom - Size)
{
SpeedY *= -1;
}
}
}
}