From bf2be407e4cac21e19b297fc7de3beed38717835 Mon Sep 17 00:00:00 2001 From: Andrea Bianchi Date: Tue, 1 Apr 2025 13:16:47 +0900 Subject: [PATCH] w6 clock exercise --- w6_clock/clock.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ w6_clock/index.html | 12 ++++++++++++ w6_clock/index.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 w6_clock/clock.js create mode 100644 w6_clock/index.html create mode 100644 w6_clock/index.js diff --git a/w6_clock/clock.js b/w6_clock/clock.js new file mode 100644 index 0000000..a416e59 --- /dev/null +++ b/w6_clock/clock.js @@ -0,0 +1,44 @@ +/* + * Clock Module + */ + +/** + * @typedef Clock + * @type {object} + * @property {number} x - The x-coordinate of the clock center. + * @property {number} y - The y-coordinate of the clock center. + * @property {number} radius - The radius of the clock. + * @property {string} color - The color of the clock. + * @property {number} oneSecondMs - The interval in milliseconds for one second. + * @property {number} hours - The current hour. + * @property {number} minutes - The current minute. + * @property {number} seconds - The current second. + */ + +const createClock = (color, oneSecondMs) => (x, y, radius) => { + // return a clock +}; + +// export const createSportsClock = createClock('#FFF000', 500); +// export const createStandardClock = createClock('#FFFFFF', 1000); + +export const drawClock = (clock) => { + // draw the clock face +}; + +export function startClock(clock) { + // start animating the clock +} + +export function stopClock(intervalId) { + // stop the clock +} + +// Private Helpers +const tick = (clock) => { + // return a new clock that advances the time of 1 second +}; + +const drawClockHands = (x, y, alpha, length) => { + // draw the clock hands +}; diff --git a/w6_clock/index.html b/w6_clock/index.html new file mode 100644 index 0000000..2d45de5 --- /dev/null +++ b/w6_clock/index.html @@ -0,0 +1,12 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git a/w6_clock/index.js b/w6_clock/index.js new file mode 100644 index 0000000..db009cc --- /dev/null +++ b/w6_clock/index.js @@ -0,0 +1,30 @@ +import { + createStandardClock, + createSportsClock, + drawClock, + startClock, + stopClock, +} from './clock.js'; + +let clock; +let timer; + +window.setup = function () { + createCanvas(800, 600); + + // clock = createStandardClock(width / 2, height / 2, 200); + // clock = createSportsClock(width / 2, height / 2, 200); + // timer = startClock(clock); +}; + +window.draw = function () { + background('#eee'); + // drawClock(clock); +}; + +window.keyPressed = function () { + if (key === 's' || key === 'S') { + // stopClock(timer); + console.log('Clock stopped'); + } +};