xxxxxxxxxx
29
// Basic bar graph example with no scaling
//
// By Professor Jon E. Froehlich
// https://makeabilitylab.cs.uw.edu/
//
const values = [80, 20, 140, 210, 50, 40]
function setup() {
createCanvas(400, 400);
// Print values to console to verify
for(let i = 0; i < values.length; i++){
print(values[i]);
}
}
function draw() {
background(220);
// Set some visual design constants
const rectWidth = 20; // in pixels
const graphBottom = 300; // y location of graph bottom
for(let i=0; i < values.length; i++){
// rect(x, y, w, h) draws a rectangle at x,y with a width w and
// height h. See: https://p5js.org/reference/#/p5/rect
rect(50 + i * rectWidth, graphBottom - values[i], rectWidth, values[i]);
}
}