diff --git a/.gitignore b/.gitignore index e3e9a71..c2abd0a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules **/.DS_Store todo/** _*.js -solution-*.js \ No newline at end of file +solution-*.js +old/ \ No newline at end of file diff --git a/w3_2_functions/index.html b/w3_2_functions/index.html new file mode 100644 index 0000000..c63a3c4 --- /dev/null +++ b/w3_2_functions/index.html @@ -0,0 +1,24 @@ + + + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/w3_2_functions/sorting.js b/w3_2_functions/sorting.js new file mode 100644 index 0000000..b00f692 --- /dev/null +++ b/w3_2_functions/sorting.js @@ -0,0 +1,55 @@ +// Main +const N = 10; +let strips = []; + +function setup() { + createCanvas(400, 300); + strips = createStrips(N); + + // TODO sort the strips by luminance +} + +function draw() { + background(0); + noStroke(); + const h = height / strips.length; + + // TODO draw the strips +} + +// 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) { + // TODO +} + +/** + * createStrips -- create an array of random colors + * @param {number} n + * @returns Color[] + */ +function createStrips(n) { + // TODO +}