【发布时间】:2021-06-21 15:58:08
【问题描述】:
我正在尝试使用 random(); 更改一些圆圈对象的位置。我的问题是我要么可以在 setup() 中初始化随机位置……(不能在 draw() 中覆盖它们……或者在 draw() 中初始化它们……所以一切都发生得太快了……我不想放慢速度down frameRate() 或者...所以我认为编写一个额外的函数并且每 30 帧调用一次就可以解决它 - 但是我的圆圈对象被当作一个对象处理并绘制在同一个位置...我错过了什么?我认为逻辑有点棘手?感谢您的任何帮助!
Circle[] circles = new Circle[3];
float rX;
float rY;
float posX;
void setup () {
size(540, 960);
randomizePositions();
}
void randomizePositions() {
rX = random(width);
rY = random(height);
}
void draw() {
background(#c1c1c1);
for (int i = 0; i <circles.length; i++) {
circles[i] = new Circle(rX, rY);
}
for (int i = 0; i < circles.length; i++) {
circles[i].display();
}
if (frameCount % 30 == 0) {
randomizePositions();
}
}
这是我的对象:
class Circle {
int size;
float x;
float y;
Circle(float tempX, float tempY) {
size = width/10;
x = tempX;
y = tempY;
}
void display() {
float wave = sin(radians(frameCount*10));
for (int i = 0; i < 10 * wave; i++) {
noFill();
stroke(0);
strokeWeight(20);
ellipse(x, y, i * size, i * size);
}
}
}
【问题讨论】:
标签: arrays object random processing