My assignment is to generate a hair-like/fur-like texture. For this case, I’m creating a circle of this texture and I would like some advice on how to improve it.
PGraphics create_fur_circle(int colour, int radius) {
PGraphics pg = createGraphics(radius*2, radius*2);
int x,y,v_x,v_y, v_x_0, v_y_0;
int v_norm=10;
int alpha=200;
float thickness=0.1;
int N_lines=1000;
int l_line=100;
float alpha_max=3.14/3; // Angle between old vector v_0 and new vector v
pg.beginDraw();
pg.stroke(colour, alpha);
pg.strokeWeight(thickness);
for (int i=0; i<N_lines; i+=1) {
// Finding x,y in circle
do {
x = int(random(width));
y = int(random(height));
} while(dist(width/2,height/2,x,y) > radius);
// Finding v with certain |v|
do {
v_x = int(random(-v_norm,v_norm));
v_y = int(random(-v_norm,v_norm));
} while(dist(0,0,v_x,v_y)>v_norm);
for (int j=0; j<l_line; j+=1) {
if (dist(width/2,height/2,x,y) > radius) break;
// Drawing line
pg.line(x, y, x+v_x, y+v_y);
// Moving x, y
x+=v_x;
y+=v_y;
// Store old vector coordinates
v_x_0=v_x;
v_y_0=v_y;
do {
v_x = int(random(-v_norm,v_norm));
v_y = int(random(-v_norm,v_norm));
// We need two conditions:
// 1- The norm v_x,v_y is not greater than d
// 2- The angle between v_x_0,v_y_0 (preceding vector) and v_x,v_y is not greater than alpha_max
} while(dist(0,0,v_x,v_y)>v_norm && acos((v_x_0*v_x+v_y_0*v_y)/(v_norm*v_norm))>alpha_max);
}
}
pg.endDraw();
return pg;
}
Here is the result:
Thanks.