Compare commits

..

2 Commits

Author SHA1 Message Date
270d7c5bfe Week 3.2 functions exercise 2025-03-10 14:24:07 +09:00
36ab0e4bfc Fixing index 2025-03-10 14:18:25 +09:00
3 changed files with 87 additions and 45 deletions

View File

@ -1,49 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<head> <meta charset="UTF-8" />
<meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exercises</title> <title>Exercises</title>
</head> </head>
<body>
<h1>Week1</h1>
<ul>
<li><a href="w1_types">Types</a></li>
</ul>
<h1>Week2</h1>
<ul>
<li><a href="w2_p5">p5.js</a></li>
<li><a href="w2_arrays">Arrays</a></li>
</ul>
<h1>Week3</h1>
<ul>
<li><a href="w3_functions">Functions</a></li>
<li><a href="w3_turtle">Recursion: Turtle</a></li>
<li><a href="w3_tower">Recursion: Tower of Hanoi</a></li>
</ul>
<h1>Week4</h1>
<ul>
<li><a href="w4_watch">Watch</a></li>
<li><a href="w4_HOF">HOF</a></li>
</ul>
<h1>Week7</h1>
<ul>
<li><a href="w7_lights">Lights</a></li>
<li><a href="w7_cars">Cars</a></li>
</ul>
<h1>Week8</h1>
<ul>
<li><a href="w8_factory/">Factory</a></li>
</ul>
<h1>Week10</h1>
<ul>
<li><a href="w10_files_browser/">Files+browser</a></li>
<li><a href="w10_node/">Node</a></li>
<li><a href="w10_promises/">Promises</a></li>
</ul>
</body>
<body>
<h1>Please reopen the IDE by pointing to the folder for each week</h1>
</body>
</html> </html>

21
w3_2_functions/index.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<script src="../libs/js/p5.js"></script>
<script src="../libs/js/p5.dom.min.js"></script>
<script src="../libs/js/p5.sound.min.js"></script>
<meta charset="utf-8" />
<style>
/* Center the canvas */
canvas {
display: block;
margin: 0 auto;
}
</style>
</head>
<script defer src="./sketch.js"></script>
<body></body>
</html>

57
w3_2_functions/sketch.js Normal file
View File

@ -0,0 +1,57 @@
// 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 [];
}