111,098
社区成员




private void timer_Tick(object sender, EventArgs e)
{
Tick++;
if (Tick % 10 == 0)
{
SnowFlake s = new SnowFlake();
Random rd = new Random();
s.X = rand.Next(-20, this.Width + 20);
s.Y = 0f;
s.XVelocity = (float)(rand.NextDouble() - 0.5f) * 2f;
s.YVelocity = (float)(rand.NextDouble() * 3) + 1f;
s.Rotation = rand.Next(0, 359);
s.RotVelocity = rand.Next(-3, 3) * 2;
s.image = Image.FromFile(@"Resources\" + rd.Next(1, 4) + ".gif");
if (s.RotVelocity == 0)
{
s.RotVelocity = 3;
}
s.Scale = (float)(rand.NextDouble() / 2) + 0.75f;
SnowFlakes.Add(s);
}
Graphics g = Graphics.FromImage(screenImage);
g.Clear(Color.Transparent);
g.SmoothingMode = SmoothingMode.HighSpeed;
for (int i = 0; i < SnowFlakes.Count; i++)
{
SnowFlake s1 = SnowFlakes[i];
s1.X += s1.XVelocity;
s1.Y += s1.YVelocity;
s1.Rotation += s1.RotVelocity;
s1.XVelocity += ((float)rand.NextDouble() - 0.5f) * 0.7f;
s1.XVelocity = Math.Max(s1.XVelocity, -2f);
s1.XVelocity = Math.Min(s1.XVelocity, +2f);
if (s1.Y > this.Height)
{
SnowFlakes.RemoveAt(i);
}
else
{
g.ResetTransform();
g.TranslateTransform(-16, -16, MatrixOrder.Append); //pan
g.ScaleTransform(s1.Scale, s1.Scale, MatrixOrder.Append); //scale
g.RotateTransform(s1.Rotation, MatrixOrder.Append); //rotate
g.TranslateTransform(s1.X, s1.Y, MatrixOrder.Append); //pan
g.DrawImage(s1.image, 0, 0); //draw
}
}
g.Dispose();
SetBackground(screenImage);
}
private void button1_Click(object sender, EventArgs e)