MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

javascript_games/sinemessage.js:19–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17const WIDTH = process.stdout.columns - 1;
18
19async function main() {
20 console.log('Sine Message, by Al Sweigart al@inventwithpython.com')
21 console.log('(Press Ctrl-C to quit.)')
22 console.log()
23 console.log('What message do you want to display? (Max', Math.floor(WIDTH / 2), 'chars.)')
24 while (true) {
25 var message = readlineSync.question('> ');
26 if (1 <= message.length <= Math.floor(WIDTH / 2)) {
27 break;
28 }
29 console.log('Message must be 1 to', Math.floor(WIDTH / 2), 'characters long.')
30 }
31
32 let step = 0.0; // The "step" determines how far into the sine wave we are.
33 // Sine goes from -1.0 to 1.0, so we need to change it by a multiplier:
34 let multipler = (WIDTH - message.length) / 2;
35
36 while (true) { // Main program loop.
37 let sinOfStep = Math.sin(step);
38 let padding = ' '.repeat(Math.floor((sinOfStep + 1) * multipler));
39 console.log(padding + message);
40 await sleep(0.1);
41 step += 0.25 // (!) Try changing this to 0.1 to 0.5.
42 }
43}
44
45main();

Callers 1

sinemessage.jsFile · 0.70

Calls 1

sleepFunction · 0.70

Tested by

no test coverage detected