Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 153
  1. void setup() {
  2.   size(400, 400);
  3.   background(255);
  4.  
  5.   // Define data for the bars
  6.   int[] data = {50, 100, 150, 200};
  7.  
  8.   // Define colors for the bars
  9.   color[] colors = {color(255, 0, 0), color(0, 255, 0), color(0, 0, 255), color(255, 255, 0)};
  10.  
  11.   // Draw bars
  12.   float barWidth = width / data.length;
  13.   for (int i = 0; i < data.length; i++) {
  14.     float barHeight = map(data[i], 0, max(data), 0, height);
  15.     strokeWeight(2 + i * 0.5); // Increase line thickness for larger bars
  16.     strokeCap(SQUARE); // Change line ending
  17.     fill(colors[i]);
  18.     rect(i * barWidth, height - barHeight, barWidth, barHeight);
  19.    
  20.     // Display values above the bars
  21.     textSize(12);
  22.     textAlign(CENTER);
  23.     fill(0);
  24.     text(str(data[i]), i * barWidth + barWidth / 2, height - barHeight - 5);
  25.   }
  26. }
  27.