Updated quickstart instructions in the readme
This commit is contained in:
15
README.md
15
README.md
@@ -8,14 +8,27 @@ To use PyCanvas, you can add the following to the top of your skulpt builtInRead
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
if (x === 'screen' || x === './screen.js') {
|
if (x === 'screen' || x === './screen.js') {
|
||||||
|
const url = new URL('screen.js', window.location.href).href;
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", "path/to/screen.js", false);
|
xhr.open("GET", url, false);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
if (xhr.status === 200) return xhr.responseText;
|
if (xhr.status === 200) return xhr.responseText;
|
||||||
else throw "Could not load screen.js";
|
else throw "Could not load screen.js";
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
And set these variables before running the 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;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Then you can use it in your code like this:
|
Then you can use it in your code like this:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|||||||
Reference in New Issue
Block a user