0
我已经将几个随机绘制的线的坐标存储在对象数组中。 我现在想能够以编程方式处理数组中所有对象的x1。我无法弄清楚如何做到这一点,甚至不知道如何查看存储行的坐标。如果我做println()
我只是得到对象的内存引用。如何访问作为数组中对象存储的形状的坐标
这里是到目前为止的代码:
class Line{
public float x1, y1, x2, y2;
public Line(float x1, float y1, float x2, float y2){
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public void draw(){
line(x1, y1, x2, y2);
float rot = random(360);
rotate(rot);
}
//public boolean intersects(Line other){
// //left as exercise for reader
//}
}
ArrayList<Line> lines = new ArrayList<Line>();
void setup(){
background(204);
size(600, 600);
for(int i = 0; i < 20; i++){
float r = random(500);
float s = random(500);
lines.add(new Line(r,s,r+10,s+10));
printArray(lines);
for(Line line : lines){
line.draw();
}
}
}