- void setup() {
- size(600, 600);
- // Define integer variables
- int num1 = 5;
- int num2 = -8;
- int num3 = 10;
- int num4 = -3;
- int num5 = 7;
- // Set background color
- background(255);
- // Display each number with appropriate color
- fill(0); // Set fill color to black
- textSize(20); // Set text size
- // Display num1
- if (num1 >= 0) {
- fill(0, 255, 0); // Green color for positive number
- text(num1, 50, 50);
- } else {
- fill(255, 0, 0); // Red color for negative number
- text(abs(num1), 50, 50); // Calculate absolute value
- }
- // Display num2
- if (num2 >= 0) {
- fill(0, 255, 0); // Green color for positive number
- text(num2, 150, 50);
- } else {
- fill(255, 0, 0); // Red color for negative number
- text(abs(num2), 150, 50); // Calculate absolute value
- }
- // Display num3
- if (num3 >= 0) {
- fill(0, 255, 0); // Green color for positive number
- text(num3, 250, 50);
- } else {
- fill(255, 0, 0); // Red color for negative number
- text(abs(num3), 250, 50); // Calculate absolute value
- }
- // Display num4
- if (num4 >= 0) {
- fill(0, 255, 0); // Green color for positive number
- text(num4, 350, 50);
- } else {
- fill(255, 0, 0); // Red color for negative number
- text(abs(num4), 350, 50); // Calculate absolute value
- }
- // Display num5
- if (num5 >= 0) {
- fill(0, 255, 0); // Green color for positive number
- text(num5, 450, 50);
- } else {
- fill(255, 0, 0); // Red color for negative number
- text(abs(num5), 450, 50); // Calculate absolute value
- }
- save("activity2.png");
- }