Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 171
  1. float[] maxTemperatures = {25.3,31.8,40.6,24.6,17.8,27.5,32.3,35.3,42.1,22.6,25.1,30.2,34.1,32.5
  2. ,26.5,23.6,24,26.1,22.2,20.1,27.4,25.9,20.9,23.7,25.7,26.6,27.1,30.8,38.8,43.3,35.6};
  3.  
  4. // Set up canvas size
  5. size(400, 300);
  6.  
  7. // Define temperature ranges
  8. String[] temperatureRanges = {"0-10", "11-20", "21-30", "31-40", "41-50"};
  9.  
  10. // Count of days for each temperature range
  11. int[] temperatureCounts = new int[5];
  12.  
  13. // Fill temperatures by range
  14. for (float temp : maxTemperatures) {
  15.   if (temp >= 0 && temp <= 10) {
  16.     temperatureCounts[0]++;
  17.   } else if (temp >= 11 && temp <= 20) {
  18.     temperatureCounts[1]++;
  19.   } else if (temp >= 21 && temp <= 30) {
  20.     temperatureCounts[2]++;
  21.   } else if (temp >= 31 && temp <= 40) {
  22.     temperatureCounts[3]++;
  23.   } else if (temp >= 41 && temp <= 50) {
  24.     temperatureCounts[4]++;
  25.   }
  26. }
  27.  
  28. // Set text and rectangle parameters
  29. textSize(15);
  30. fill(0);
  31. textAlign(CENTER, CENTER);
  32. int x = 50; // Starting x-coordinate for the table
  33. int y = 50; // Starting y-coordinate for the table
  34. int rowHeight = 30; // Height of each row
  35. int columnWidth = 150; // Width of each column
  36.  
  37. // Draw table outline
  38. stroke(0);
  39. noFill();
  40. rect(x, y, columnWidth * 2, rowHeight * (temperatureRanges.length + 1));
  41.  
  42. // Draw table headers
  43. fill(200);
  44. rect(x, y, columnWidth, rowHeight);
  45. rect(x + columnWidth, y, columnWidth, rowHeight);
  46. fill(0);
  47. text("Temperature Range (\u00B0C)", x + 75, y + 15);
  48. text("Number of Days", x + columnWidth + 75, y + 15);
  49. y += rowHeight; // Move to the next row
  50.  
  51. // Draw table rows
  52. for (int i = 0; i < temperatureRanges.length; i++) {
  53.   if (i % 2 == 0) {
  54.     fill(240);
  55.   } else {
  56.     fill(255);
  57.   }
  58.   rect(x, y, columnWidth, rowHeight);
  59.   rect(x + columnWidth, y, columnWidth, rowHeight);
  60.   fill(0);
  61.   text(temperatureRanges[i], x + 75, y + 15);
  62.   text(temperatureCounts[i], x + columnWidth + 75, y + 15);
  63.   y += rowHeight; // Move to the next row
  64. }
  65.  
  66. save("Activity18.png");