Skip to content

Instantly share code, notes, and snippets.

@edwingustafson
Last active August 27, 2022 13:29
Show Gist options
  • Save edwingustafson/29b672139a7e9660a76ee633733fcd9b to your computer and use it in GitHub Desktop.
Save edwingustafson/29b672139a7e9660a76ee633733fcd9b to your computer and use it in GitHub Desktop.
Maze generator with experimental Node command-line argument parsing
#!/usr/bin/node
import { parseArgs } from 'node:util';
/*
Based on the Commodore 64 single line maze generator
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
as described at https://10print.org/
*/
const defaults = { char0: '\u2571', char1: '\u2572', delay: '50', };
const options = {
char0: { type: 'string', short: '0', },
char1: { type: 'string', short: '1', },
delay: { type: 'string', short: 'd', }
};
const { values } = parseArgs({ options });
const char0 = values.char0 || defaults.char0;
const char1 = values.char1 || defaults.char1;
const delay = parseInt(values.delay || defaults.delay);
const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
for(;;) {
process.stdout.write(Math.random() < 0.5 ? char0 : char1);
await sleep(delay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment