the three for loop blues
in
Programming Questions
•
1 year ago
I've come across this issue a number of times and since I don't have a super systematic approach to dealing with it...
So say you have two nested for loops:
- void setup() {
- size(640,480);
- background(255);
- }
- void draw() {
- for (int i=0; i<64; i++) {
- for (int j=0; j<48; j++) {
- pushMatrix();
- stroke(255,0,128,200);
- rect(i*10, j*10, 10, 10);
- popMatrix();
- }}
- }
what's the best way to cope with a third for loop? what would you do? below, of course, slows everything to a crawl:
- void setup() {
- size(640,480);
- background(255);
- }
- void draw() {
- for (int i=0; i<64; i++) {
- for (int j=0; j<48; j++) {
- for (int t=0; t<48; t++) {
- pushMatrix();
- stroke(255,0,128,200);
- rect(i*10, j*10, 1+t, 10);
- popMatrix();
- t++;
- if (t > 10){
- t = 0;
- }
- }}}
- }
define t outside the existing for loops.. Would appreciate any insight.
1