我正在尝试将数组列表中的椭圆绘制到 PGraphics 层上。到目前为止,这有效。但是,我需要给 PGraphics 图层一个白色背景。添加背景的那一刻,我无法通过鼠标单击添加任何椭圆。我已经尝试在 PGraphics 图层上绘制没有背景的椭圆,并且再次在具有背景的第二个 PGraphics 图层上绘制。但这仍然会导致椭圆在一遍又一遍地绘制时变得像素化的问题。我怎样才能使椭圆从数组列表逐渐添加到唯一的 PGrpahics 层?
PGraphics pg;
ArrayList<Circle> circles;
void setup () {
size(500, 500);
circles = new ArrayList<Circle>();
circles.add(new Circle());
pg = createGraphics(width, height);
}
void draw() {
background(255);
image(pg, 0, 0);
for (int i = circles.size()-1; i >= 0; i--) {
Circle circle = circles.get(i);
circle.display();
}
}
void mousePressed() {
circles.add(new Circle());
}
而这部分……我把后台功能注释掉了……</p>
class Circle {
int x = int(random(width));
int y = int(random(height));
int size;
Circle() {
}
void display() {
pg.beginDraw();
//pg.background(255);
pg.ellipse(x, y, 20, 20);
pg.endDraw();
}
}