Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 150
  1. int cols = 10;
  2. int rows = 10;
  3. int rectSize;
  4.  
  5. void setup() {
  6.   size(400, 400);
  7.   rectSize = width / cols;
  8.   noLoop(); // We don't need to continuously redraw the pattern
  9. }
  10.  
  11. void draw() {
  12.   background(255);
  13.  
  14.   for (int i = 0; i < cols; i++) {
  15.     for (int j = 0; j < rows; j++) {
  16.       int x = i * rectSize;
  17.       int y = j * rectSize;
  18.       float redColor = map(i, 0, cols-1, 0, 255); // Modify red based on column index
  19.       float greenColor = map(j, 0, rows-1, 0, 255); // Modify green based on row index
  20.       fill(redColor, greenColor, 150); // Vary color based on position
  21.       rect(x, y, rectSize, rectSize);
  22.     }
  23.   }
  24.   save("activity13.png");
  25. }
  26.