exercises/w3_2_functions/sketch.js

58 lines
1.0 KiB
JavaScript

// Main
const N = 10;
let strips = [];
function setup() {
createCanvas(400, 300);
strips = createStrips(N);
}
function draw() {
background(0);
noStroke();
const stripHeight = height / strips.length;
for (let i = 0; i < strips.length; i++) {
// draw the strips
// const r = ...
}
}
// HELPERS
/**
*
* @typedef {{red:number, green:number, blue:number}} Color
*/
/**
* createRndColorStrip
* @returns Color
*/
function createRndColorStrip() {
return {
red: Math.floor(Math.random() * 255),
green: Math.floor(Math.random() * 255),
blue: Math.floor(Math.random() * 255),
};
}
/**
* getLuminance -- get luminance given an array of Color
* @param {Color} strip
* @returns number
*/
function getLuminance(strip) {
// PLACEHOLDER - return the luminance of the strip
return 0;
}
/**
* createStrips -- create an array of random colors
* @param {number} n
* @returns Color[]
*/
function createStrips(n) {
// PLACEHOLDER - return an arrray of strips of colors
return [];
}