我正在尝试在 c# windows 窗体中下一场紫色的雨,就像这个视频中的那样https://www.youtube.com/watch?v=KkyIDI6rQJI Hes 使用了一种名为 processing with java 编程语言的 ide。
到目前为止,这是我的代码:
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace PurpleRain
{
public partial class MainForm : Form
{
public MainForm()
{
}
float x=150;
float y=1;
float yspeed=1;
public void fall()
{
y=y+yspeed;
if (y>=350)
{
y=0;
}
}
public void show(float a,float b)
{
Graphics g;
g = this.CreateGraphics();
Pen myPen = new Pen(Color.MediumPurple);
myPen.Width = 2;
Pen myErase = new Pen(Color.Lavender);
myErase.Width = 2;
g.DrawLine(myErase, a, b-1, a, b+15);
g.DrawLine(myPen, a, b, a, b+15);
}
void draw()
{
for (int i=0;i<10;i++){
show(x,y);
fall();
}
}
void Timer1Tick(object sender, EventArgs e)
{
draw();
}
}
这段代码所做的是绘制一条紫色线,并通过擦除之前绘制的线使其落到底部。我的问题是添加这条紫色线可能是一百条来模拟视频中的雨,并让它们也从随机的 x 和 y 位置开始。我试过循环,列出无济于事。