Processing - Translation and Rotation, in for loop [Solved] -
i using processing seek , draw , i'm stuck on loop i'm trying run.
i have sketch create shorter taking advantage of translate , rotate commands. however, reason can't work. if comment out first loop ("for (int k = 0;...)" draws, correctly, in 1 of 8 quadrants. want rotate 45 degrees, draw again, , go on until goes total 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){ // 1 having problem with... (int k = 0; k == 8; k ++){ // loop 8 times, finish 8 rotations pushmatrix(); translate(hwidth,hheight); rotate(radians(45)); (int = 0; < hwidth; i+= steps){ line(i,0,hwidth-i,hheight-i); } popmatrix(); } } void draw(){ stroke(255); grid(); rotatinggrid(10); }
so if comment out first loop (and closing bracket), correctly works. how can loop that, rotating 7 times, instead of putting "rotate(radians(45))" , loop 7 more times?
thanks advice or help.
the first loop should (int k = 0; k< 8; k++) if want run 8 times. if want angle go 45, 90, ... 360, can add together variable this:
int angle = 0; .... angle+=45; rotate(radians(angle)); ....
also, may want swap rotate , translate if want rotate object's origin instead of having in bigger circle, not sure effect want here.
processing
No comments:
Post a Comment