【发布时间】:2022-01-16 09:13:17
【问题描述】:
我有一个任务,我必须使用处理进行火灾模拟。我的目标是制作一个可以射出多个椭圆的圆形烟花。可以找到我正在尝试完成的图像here
我现在的代码似乎是在螺旋中绘制椭圆。如果有人想尝试一下,我已将代码的下载链接复制粘贴到底部。
ArrayList<Ball> ballList;
int timer;
int amount;
int ball;
float angle;
boolean draws;
Ball b;
void setup() {
size(1300, 700);
ballList = new ArrayList<Ball>(ball);
ball= 36;
amount = 1000;
}
void draw() {
background(0);
for (int i = ballList.size()-1; i > -1; i--) {
for (int k = 0; k < ball; k++) {
Ball b = ballList.get(i);
fill(255, 0, 0, b.a);
b.display();
}// for loop
}// for loop
}// void draw
void mousePressed() {
for (int j = 0; j < ball; j++) {
ballList.add (new Ball(angle));
}
}
class Ball {
float X;
float Y;
float rad;
float mx;
float my;
float a;
float draw;
color c = color(random(0, 255), random(0, 255), random(0, 255));
float d;
float angle;
float X2;
float Y2;
float angle2;
float x;
float y;
Ball(float _angle) {
X = mouseX; //mouse X
Y = mouseY; //mouseY;
d = 0;
rad= 10;
angle = _angle;
a = 255;
}//Ball
void display() { // draw the ball and fill in colour
noStroke();
a--;
d++;
angle += 10;
if (angle >= 360) {
angle = 0;
}
angle2 = radians(angle);
X2 = cos(angle2) * d + X;
Y2 = sin(angle2) * d + Y;
a -= 0.5;
ellipse(X2, Y2, rad, rad);
}// void display
}
【问题讨论】:
标签: processing ellipse