Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 134
  1. void setup() {
  2.   size(600, 600);
  3.  
  4.   // Define integer variables
  5.   int num1 = 5;
  6.   int num2 = -8;
  7.   int num3 = 10;
  8.   int num4 = -3;
  9.   int num5 = 7;
  10.  
  11.   // Set background color
  12.   background(255);
  13.  
  14.   // Display each number with appropriate color
  15.   fill(0); // Set fill color to black
  16.   textSize(20); // Set text size
  17.  
  18.   // Display num1
  19.   if (num1 >= 0) {
  20.     fill(0, 255, 0); // Green color for positive number
  21.     text(num1, 50, 50);
  22.   } else {
  23.     fill(255, 0, 0); // Red color for negative number
  24.     text(abs(num1), 50, 50); // Calculate absolute value
  25.   }
  26.  
  27.   // Display num2
  28.   if (num2 >= 0) {
  29.     fill(0, 255, 0); // Green color for positive number
  30.     text(num2, 150, 50);
  31.   } else {
  32.     fill(255, 0, 0); // Red color for negative number
  33.     text(abs(num2), 150, 50); // Calculate absolute value
  34.   }
  35.  
  36.   // Display num3
  37.   if (num3 >= 0) {
  38.     fill(0, 255, 0); // Green color for positive number
  39.     text(num3, 250, 50);
  40.   } else {
  41.     fill(255, 0, 0); // Red color for negative number
  42.     text(abs(num3), 250, 50); // Calculate absolute value
  43.   }
  44.  
  45.   // Display num4
  46.   if (num4 >= 0) {
  47.     fill(0, 255, 0); // Green color for positive number
  48.     text(num4, 350, 50);
  49.   } else {
  50.     fill(255, 0, 0); // Red color for negative number
  51.     text(abs(num4), 350, 50); // Calculate absolute value
  52.   }
  53.  
  54.   // Display num5
  55.   if (num5 >= 0) {
  56.     fill(0, 255, 0); // Green color for positive number
  57.     text(num5, 450, 50);
  58.   } else {
  59.     fill(255, 0, 0); // Red color for negative number
  60.     text(abs(num5), 450, 50); // Calculate absolute value
  61.   }
  62.  
  63.   save("activity2.png");
  64. }