Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 150
  1.  
  2. void setup() {
  3.   size(500, 500);
  4.  
  5.   // Define parameters
  6.   int numCircles = 5;
  7.   int xAmplitude = width / numCircles;
  8.   int yAmplitude = height / numCircles;
  9.   int bottomMultiplier = 1;
  10.   int topMultiplier = 1;
  11.   int circleNumber = 1;
  12.  
  13.   // Draw circles in a grid pattern
  14.   for (int gridX = xAmplitude / 2; gridX <= width - xAmplitude / 2; gridX += xAmplitude) {
  15.     for (int gridY = (yAmplitude / 2) * bottomMultiplier; gridY <= height - ((yAmplitude / 2) * topMultiplier); gridY += yAmplitude) {
  16.       // Set fill color based on circle number
  17.       if (circleNumber % 2 == 0) {
  18.         fill(0, 0, 175); // Blue color
  19.       } else {
  20.         fill(175, 0, 0); // Red color
  21.       }
  22.      
  23.       // Draw circle
  24.       ellipse(gridX, gridY, xAmplitude, yAmplitude);
  25.      
  26.       // Draw circle number
  27.       fill(0); // Black color
  28.       textSize(16);
  29.       textAlign(CENTER, CENTER);
  30.       text(circleNumber, gridX, gridY);
  31.      
  32.       // Increment circle number
  33.       circleNumber++;
  34.     }
  35.     // Update multipliers for next row
  36.     topMultiplier++;
  37.     bottomMultiplier++;
  38.   }
  39.  
  40.   // Save the output as an image
  41.   save("Assignment5_part2");
  42. }