diff --git a/packages/autopaint/index.js b/packages/autopaint/index.js new file mode 100644 index 0000000..a9be4c0 --- /dev/null +++ b/packages/autopaint/index.js @@ -0,0 +1,48 @@ +/** + * Autopaint for JsOS + * Copyright (c) PROPHESSOR 2018 + */ + +'use strict'; + +const $ = require('../../core/graphics/jsmb-pseudo'); + +exports.call = (cmd, args, api, exit) => { + const [SCW, SCH] = [$.screenWidth(), $.screenHeight()]; + let [x, y] = [SCW / 2, SCH / 2]; + + const render = () => { + const direction = $.random(0, 100); + + if (direction < 25 && y > 0) y--; + else if (direction < 50 && x < SCW) x++; + else if (direction < 75 && y < SCH) y++; + else if (x > SCW / 2) x--; + + $ + .setColor($.random(0, 0xF)) + .drawString('#', x, y) + .drawString('#', SCW - x, y) + .repaint(); + }; + + const timer = setInterval(render, 50); + + const onKeyDown = (key) => { + if (key.type === 'f12') { + clearInterval(timer); + api.keyboard.onKeydown.remove(onKeyDown); + + return exit(0); + } + }; + + api.keyboard.onKeydown.add(onKeyDown); + + $ + .cls() + .setColor(0xE) + .drawString('Welcome to Autopaint app! Press F12 to exit.', 0, 0); +}; + +exports.commands = ['autopaint']; diff --git a/packages/autopaint/npi.json b/packages/autopaint/npi.json new file mode 100644 index 0000000..a872d8f --- /dev/null +++ b/packages/autopaint/npi.json @@ -0,0 +1,12 @@ +{ + "name": "autopaint", + "version": "1.0.0", + "author": "PROPHESSOR", + "help": { + "description": "Port of the PROPHESSOR's autopaint program to JsOS. It's a random drawing screen saver.", + "usage": "start autopaint" + }, + "libs": [ + "jsmb-pseudo" + ] +} \ No newline at end of file