xxxxxxxxxx
27
// Basic line graph example with no scaling
//
// By Professor Jon E. Froehlich
// https://makeabilitylab.cs.uw.edu/
//
const values = [80, 20, 140, 210, 50, 40, 80, 50]
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
// Set some visual design constants
const xSpacing = 20; // in pixels
const graphBottom = 300; // y location of graph bottom
const xMargin = 50;
for(let i = 1; i < values.length; i++){
const xPt1 = xMargin + (i - 1) * xSpacing;
const xPt2 = xMargin + i * xSpacing;
const yPt1 = graphBottom - values[i - 1];
const yPt2 = graphBottom - values[i];
line(xPt1, yPt1, xPt2, yPt2);
}
}