I am using Processing to try and draw something and I'm stuck on a FOR loop that I'm trying to run.
I have a sketch that I would like to make shorter by taking advantage of the Translate and Rotate commands. However, for some reason I can't get this to work. If I comment out the first FOR loop ("for (int k = 0;...)" it draws, correctly, in one of my 8 quadrants. I just want to then rotate that 45 degrees, draw again, and continue until it goes full circle.
int hHeight, hWidth;
void setup(){
size(800,800);
hHeight = height/2;
hWidth = width/2;
background(0);
strokeWeight(.5);
}
void grid(){
stroke(255);
line(hWidth,0,hWidth,height);
line(0,hHeight,width,hHeight);
line(width,0,0,height);
line(0,0,width,height);
}
void rotatingGrid(float steps){ // This is the one I am having trouble with...
for (int k = 0; k == 8; k ++){ // loop this 8 times, to complete 8 rotations
pushMatrix();
translate(hWidth,hHeight);
rotate(radians(45));
for (int i = 0; i < hWidth; i+= steps){
line(i,0,hWidth-i,hHeight-i);
}
popMatrix();
}
}
void draw(){
stroke(255);
grid();
rotatingGrid(10);
}
So if you comment out the first FOR loop (and the closing bracket), it correctly works. How can I loop that, rotating it 7 times, instead of just putting the "rotate(radians(45))" and the FOR loop 7 more times?
Thanks for any advice or help.