ArrayList<Cell> cells;
int j=50;
void setup() {
size(500, 500);
cells=new ArrayList<Cell>();
int q=int(random(1, 5)); //red fill value //fill *51
for (int i=0; i<1; i++) {
cells.add(new Cell(0, 0, 15, color(q*51, 0, 0), 100, 50)); //adds a new cell for each iteration
j+=50;
println(q+" "+i); //prints value of the red and then iteration of the for loop
}
}
void draw() {
printArray(cells); //prints my array list but it is not working prints "[[email protected]]"
for (int i=0; i<cells.size(); i++) {
background(255); //supposed to remove all of the other square trail
cells.get(i).display(); //displays each rectangle
}
}
class Cell {
private int x;
private int y;
private int speed;
private color c;
private int wwidth;
private int hheight;
public Cell(int xpos, int ypos, int speedy, color col, int widthh, int heightt) { // then set all of the private vars to these public ones
x=xpos;
y=ypos;
speed=speedy;
c=col;
wwidth=widthh;
hheight=heightt;
}
void display() {
fill(c);
rectMode(CORNERS);
rect(x, y, wwidth, hheight);
if (y<=height+hheight) { //if y location of the rect is less than the window then increase y pos
y+=speed; //increase y by speed
}
println(y+" "+speed);
}
}
Я хочу, чтобы прямоугольник не следовал за прямоугольником. Мне также нужно распечатать ячейки ArrayList, но String s: cells println (s) не работает ... Может кто-нибудь мне помочь? Я хочу, чтобы прямоугольник приземлялся внизу и сидел там, как он, но без длинной строки прямоугольников, следующих за ним. Любая помощь будет принята с благодарностью.Как распечатать ArrayList в процессе обработки и как обновить фон
Edit: проще работать
Этот вопрос является слишком широким. Я предлагаю разделить два вопроса на отдельные вопросы и разместить меньший [MCVE] (http://stackoverflow.com/help/mcve) вместе с каждым. Что именно вы имеете в виду, когда говорите «это не работает»? –