ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Particulas program


Enviado por   •  25 de Junio de 2024  •  Tutorial  •  425 Palabras (2 Páginas)  •  36 Visitas

Página 1 de 2

----

Coloque em baixo do public partial class

----

private List<PointF> particlePositions = new List<PointF>( );

private List<PointF> particleVelocities = new List<PointF>( );

private int numerodeparticula = 11;

private Random random = new Random( );

private Color particleColor = Color.FromArgb( 46, 54, 139 ); // Cor roxa escura

dentro do PUBLIC NOMEDOSEUFORM coloque isso

InitializeParticles( );

timer.Interval = 10;

timer.Tick += Timer_Tick;

timer.Start( );

depois coloque isso em qualquer parte do codigo do form

protected override void OnPaint( PaintEventArgs e )

{

base.OnPaint( e );

Graphics g = e.Graphics;

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

for( int i = 0; i < numerodeparticula; ++i )

{

g.FillEllipse( new SolidBrush( particleColor ), particlePositions[ i ].X - 1.5f, particlePositions[ i ].Y - 1.5f, 3, 3 );

}

}

private void Timer_Tick( object sender, EventArgs e )

{

for( int i = 0; i < numerodeparticula; ++i )

{

particlePositions[ i ] = new PointF(

particlePositions[ i ].X + particleVelocities[ i ].X,

particlePositions[ i ].Y + particleVelocities[ i ].Y

);

if( particlePositions[ i ].X < 0 particlePositions[ i ].X > ClientSize.Width

particlePositions[ i ].Y < 0 || particlePositions[ i ].Y > ClientSize.Height )

{

particlePositions[ i ] = new PointF( random.Next( 0, ClientSize.Width ), random.Next( 0, ClientSize.Height ) );

particleVelocities[ i ] = new PointF( (float)( random.NextDouble( ) * 2 - 1 ), (float)( random.NextDouble( ) * 2 - 1 ) );

}

}

Invalidate( );

}

private void InitializeParticles( )

{

for( int i = 0; i < numerodeparticula; ++i )

{

particlePositions.Add( new PointF( random.Next( 0, ClientSize.Width ), random.Next( 0, ClientSize.Height ) ) );

particleVelocities.Add( new PointF( (float)( random.NextDouble( ) * 2 - 1 ), (float)( random.NextDouble( ) * 2 - 1 ) ) );

}

}

----

NÃO ESQUECA DE ADICIONAR UM TIMER E RENOMEAR O NOME DELE PARA "timer"

----

...

Descargar como (para miembros actualizados) txt (2 Kb) pdf (44 Kb) docx (8 Kb)
Leer 1 página más »
Disponible sólo en Clubensayos.com