hi, I tried to do it with Objects, so that you can store the data from the lines in a clean way, of course, there is still much to do, mostly with the spawn system and the offset, but I think this might be useful
P.S. someone flagged my post and I don’t know why, I guess someone CAN be offended by lines of code lol, anyway, before flagging me at least tell me why
int I = 10;
Line[] l = new Line[I];
float offset = 50;
void setup(){
size(900, 900);
for(int i=0;i<I;i++){
l[i] = new Line(width/2 + random(-offset, offset), height/2 + random(-offset, offset), i * 360 / I, round(random(10, 50)));
}
}
void draw(){
for(int i=0;i<I;i++){
l[i].add_pos();
l[i].show();
}
}
class Line{
float px, py; // starting point
int lifespan = 10; // arbitrary lifespan of the line, could be changed to be random
int life_soFar = 0;//this is the counter for the lifespan, when this is == lifespan, the line stops to grow
float a_limit = PI / 3; //limit angle of steer for each iteration, if it's very small, the line will be almost straight, it's RADIANS
float a = 0;
float step = 15;//how far is a turn from another
float dir = 0;//the direcion of the line, otherwise all the lines would be parallel and point to hte right
ArrayList<PVector> pos; // the line is made of a dynamic array of Vectors that stores every point of this line
color c = color(255,0,0); // this can be whatever...
Line(float px, float py, float dir, int lifespan){ // dir input is in DEGREES, but the variable gets conveted in RADIANS
this.px = px;
this.py = py;
pos = new ArrayList<PVector>();
this.dir = radians(dir);
this.lifespan = lifespan;
}
void add_pos(float a_l){ // a_l is called here so that you can change dynamicaly the amplitude of the angle_limit while you get further
if(life_soFar < lifespan){
a = random(-a_l, a_l);
if(pos.size() > 0){
int I = pos.size() -1;
pos.add(new PVector(pos.get(I).x + step * cos(a + dir), pos.get(I).y + step * sin(a + dir)));// from the prev position, it moves a fraction of the step on the x, and on the y
}else{
pos.add(new PVector(px + step * cos(a + dir), py + step * sin(a + dir)));// first step is from the starting point
}
life_soFar++;
}
}
void add_pos(){
add_pos(a_limit);
}
void show(){
if(pos.size() > 0){
stroke(c);
for(int j=1;j<pos.size(); j++){
line(pos.get(j-1).x, pos.get(j-1).y, pos.get(j).x, pos.get(j).y);
}
noStroke();
}
}
}