From 16be8b13079e5f06b3b2684ea490826832bc9c32 Mon Sep 17 00:00:00 2001 From: Hugo H Date: Thu, 25 Dec 2025 20:05:30 +0000 Subject: [PATCH] Add Quickstart --- Quickstart.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Quickstart.md diff --git a/Quickstart.md b/Quickstart.md new file mode 100644 index 0000000..61d9534 --- /dev/null +++ b/Quickstart.md @@ -0,0 +1,42 @@ +To add PyCanvas into your application with skulpt, just add the following to the top of your builtInRead() function: +```javascript +if (x === 'screen' || x === './screen.js') { + const url = new URL('screen.js', window.location.href).href; + const xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.send(); + if (xhr.status === 200) return xhr.responseText; + else throw "Could not load screen.js"; +} +``` +Now set these variables when you run your code: +```javascript +const canvas = document.getElementById('canvas'); +const container = document.getElementById('preview-container'); +if (canvas && container) { + const w = Math.floor(container.clientWidth); + const h = Math.floor(container.clientHeight); + canvas.width = w; + canvas.height = h; +} +``` + +And create a canvas with the id `canvas` inside a div with the id `preview-container`. + +--- + +To create a basic application, define your functions and pass them to s.start() in a dictionary: + +```python +import screen as s + +def draw(): + s.cls(0) + s.text(s.CENTERX, s.CENTERY, "Hello World", 7) + +s.start({ + "loop": { + "draw": draw + } +}) +``` \ No newline at end of file