Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 133
  1. int initialValue = 10; // Initial integer value
  2. int redCount = 0; // Counter for red numbers
  3. int greenCount = 0; // Counter for green numbers
  4. int blueCount = 0; // Counter for blue numbers
  5.  
  6. void setup() {
  7.   size(600, 200);
  8.   background(255);
  9.  
  10.   // Loop through numbers from 0 to initialValue
  11.   for (int i = 0; i <= initialValue; i++) {
  12.     // Check conditions using if/else if/else statement
  13.     if (i % 2 == 0 && i % 5 == 0) {
  14.       fill(0, 255, 0); // Green for even and divisible by 5
  15.       greenCount++;
  16.     } else if (i % 2 == 0) {
  17.       fill(255, 0, 0); // Red for even numbers
  18.       redCount++;
  19.     } else {
  20.       fill(0, 0, 255); // Blue for odd numbers
  21.       blueCount++;
  22.     }
  23.    
  24.     // Display the number on the canvas
  25.     textSize(20);
  26.     text(i, 50 + i * 30, 100);
  27.   }
  28.  
  29.   // Display the counts at the end of the loop
  30.   fill(0);
  31.   textSize(16);
  32.   text("Red count: " + redCount, 50, 150);
  33.   text("Green count: " + greenCount, 200, 150);
  34.   text("Blue count: " + blueCount, 350, 150);
  35.  
  36.   save("activity11.png");
  37. }