c# - WinForms中的等离子效果,如何创建连续循环
问题描述
我正在尝试使用 C# 和 Winforms 创建一些简单的图形(“等离子”效果)。我的代码中有两个类,(main)Form1 和 Plasmadraw。
在 Plasmadraw 我有以下设置:
class Plasmadraw
{
int y;
int x;
double i;
double pii = 3.1415;
public void Draw(Graphics gfx, int addition)
{
for (int i = 0; i < 23040; i++)
{
x = x + 10;
if (x == 1920)
{
x = 0;
y = y + 10;
}
if (y == 1200)
{
y = 0;
}
double v = Math.Sin((x * 0.5) + i * 0.001 * addition);
double c = v * pii;
double d = c + (2 * pii / 3);
double f = c + (6 * pii / 3);
double r = 255 * Math.Abs(Math.Sin(c));
double g = 255 * Math.Abs(Math.Sin(d));
double b = 255 * Math.Abs(Math.Sin(f));
int r1 = (int)r;
int g1 = (int)g;
int b1 = (int)b;
Color e = Color.FromArgb(r1, g1, b1);
SolidBrush brush = new SolidBrush(e);
Rectangle rect = new Rectangle(x, y, 10, 10);
gfx.FillRectangle(brush, rect);
}
}
}
然后在 Form1 我有 Paint 事件:
private void Form1_Paint(object sender, PaintEventArgs e)
{
Plasmadraw plasmaeffect = new Plasmadraw();
for (int a = 0; a < 30; a++)
{
plasmaeffect.Draw(e.Graphics, a);
Invalidate();
}
这是构建逻辑的某种完全错误的方法吗?我设法通过创建一个列表然后在 Paint 事件中使用 Foreach (& Invalidate()) 运行该列表来创建一些图形效果(移动精灵等)。但是,我想学习一些做事的新方法,而不是照搬旧方法。
解决方案
推荐阅读
- mysql - 如何将外部模型添加到 ObjectionJS?
- python - 尝试使用 pip 安装桌面库时如何修复“错误:命令错误,退出状态 1:”?
- c - 为什么斐波那契数列的索引需要小于或等于 1?
- node.js - 如果用户有权限如何发送消息
- php - Laravel Model 有很多不同类型的模型(模型的集合)
- vuejs3 - 将数据传递给 createApp (vue)
- android - Android:如何停止 Firestore 交易?
- r - 如何合并两个数据框并仅保留不同的列(内容)?
- python - 如何跳过操作系统错误以使我的 for 循环不会中断?
- postgresql - 通过 docker 守护进程传递 sql 备份文件以填充 docker 数据库