Hi @nktlst,
You could store in an array the possible start angles and then, during iteration, pick them at random while making sure to select the corresponding translation vector.
W = H = 800 # dimensions of canvas
N = 4.0 # number of cols/rows
S = W/N # step size
T = (PVector(0,0), PVector(S,0), PVector(S,S), PVector(0,S)) # 4 possible translation vectors
A = (0, HALF_PI, PI, PI+HALF_PI) # corresponding 4 "start" angles
def setup():
size(W, H)
background(0)
for i in xrange(N*N):
x = (i%N) * S # x position
y = (i//N) * S # y position
ri = int(random(4)) # pick an index at random
t = T[ri] # select a translation vector accordingly
a = A[ri] # select a start angle accordingly
pushMatrix()
translate(t.x, t.y)
fill(random(20,120))
arc(x, y, S*2, S*2, a, a+HALF_PI)
popMatrix()
EDIT:
Processing Java version (please feel free to modify if incorrect):
int W = 800; // dimensions of canvas
int H = W;
int N = 4; // number of cols/rows
float S = W/N; // step size
PVector[] T = {new PVector(0,0), new PVector(S,0), new PVector(S,S), new PVector(0,S)}; // 4 possible translation vectors
float[] A = {0, HALF_PI, PI, PI+HALF_PI} ; // corresponding 4 "start" angles
void setup(){
size(800, 800);
background(0);
for (int i=0; i<N*N; i++){
float x = (i%N) * S; // x position
float y = (i/N) * S; // y position
int ri = int(random(4)); // pick an index at random
PVector t = T[ri]; // select a translation vector accordingly
float a = A[ri]; // select a start angle accordingly
pushMatrix();
translate(t.x, t.y);
fill(random(20,120));
arc(x, y, S*2, S*2, a, a+HALF_PI);
popMatrix();
}
}