Hi,
I am trying to write a program to render a brick-wall like pattern. At a high level, fixed length paths will be created as the wall ‘grows,’ which new paths being added as the current ones become ‘filled’ with the probabilistic based cross hatching.
This works great for a single Path, but as soon as the ArrayList contains more than a single object, only a single path (sometimes different from any paths in the ArrayList) is drawn. This is very confusing to me. I have done some internet research and come up with little pertaining to this specific problem.
As a test case, comment out 2 of the paths in the Wall constructor and run the program. A single fuzzy path will be drawn. Now, include either of (or both of) the others and run again.
I have also ran this with several Path objects not held in an ArrayList, with the looping done in draw(), with the same effect. Further, I have tried with more simplistic display() functions and still am unable to generate the expected behaviror.
Thanks
//dimensions for each brick (height, width, num)
float bh = 30;
float bw = 100;
int num_bricks = 10;
Wall wall;
void setup(){
size(500, 400);
background(255);
wall = new Wall(6);
}
void draw(){
wall.update();
wall.display();
}
class Path{
PVector start;
PVector end;
boolean filled;
PVector current_loc;
float r;
PVector velocity;
Path(PVector a, PVector b, float thickness){
start=a;
end=b;
filled = false;
r = thickness;
velocity = PVector.sub(b,a).normalize();
current_loc = a;
}
void update(){
//check if the path is done yet, and if not move one more step
if(current_loc.dist(end)==0){
filled=true;
velocity.mult(0);
}
else{
current_loc.add(velocity);
}
}
void display(){
//rotate the matrix and draw a line perpendicular to direction of travel
float theta = PI/2;
strokeWeight(5);
stroke(0);
pushMatrix();
translate(current_loc.x, current_loc.y);
rotate(theta);
float len = randomGaussian()*r/5+r;
line(-len,0,len,0);
popMatrix();
}
}
class Wall{
//collection of paths to create the wall from
ArrayList<Path> paths;
PVector start;
//how thick each line of separation should be
float thickness;
Wall(float thickness){
thickness = thickness;
start = new PVector(width/2, height/2);
paths = new ArrayList<Path>();
//manually initialize a T shape composed of 3 paths
paths.add(new Path(start, PVector.add(start, new PVector(bw/2, 0)), thickness));
paths.add(new Path(start, PVector.add(start, new PVector(-bw/2, 0)), thickness));
paths.add(new Path(start, PVector.add(start, new PVector(0, bh)), thickness));
}
void update(){
for(Path p:paths){
if(p.filled == false){
p.update();
}
}
}
void display(){
for(Path p:paths){
p.display();
}
}
}