Nested for loop


/ Published in: Processing
Save to your folder(s)

Simple example demonstrating nested for loops, colors, shapes, fill, stroke/no stroke, canvas size and smooth.


Copy this code and paste it in your HTML
  1. void setup() {
  2. size(400, 400);
  3. background(0);
  4. smooth();
  5. stroke(255, 50);
  6. //noStroke();
  7. }
  8.  
  9. void draw() {
  10.  
  11. for(int i = 0; i < width; i+=50) {
  12.  
  13. for(int j = 0; j < height; j+=50) {
  14. fill(100, 0, 150, 100);
  15. ellipse(25 + i, 25 + j, 50, 50);
  16. fill(20, 100, 0, 50);
  17. rect(i, j, 50, 50);
  18. println("i = " + i + " j = " + j);
  19. }
  20.  
  21. }
  22.  
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.