Skip to content

Commit 1335fae

Browse files
authored
Detailed explanation for livesketch.js
1 parent 2b7b7f8 commit 1335fae

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/examples.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,25 @@ This is a new feature of the example pages so you should choose no more than 6 f
7171
## Cover image
7272

7373
Each example has an image or animation that comes from P5.js code. The cover should be exported as a `.png` from the original p5.js code from [here](https://github.com/processing/processing-docs/tree/master/content/examples_p5) to a size of `1280px720` (keeping the same proportions than the original sketch). If the example doesn't have a p5.js file, then the upscaling has to be done from the `.pde` files from [here](https://github.com/processing/processing-docs/tree/master/content/examples). The naming of the image it's the same than the content file.
74+
75+
## Live Sketch
76+
Most examples include a `livesketch.js` file implemented in p5.js, designed to replicate the original Processing sketch's behavior as closely as possible. This file is not automatically generated but must be authored and updated by a contributor. It allows the example to run in a browser.
77+
78+
### Structure of a Live Sketch
79+
80+
The code uses instance mode and is encapsulated in a `runLiveSketch()` function.
81+
82+
All p5.js functions and variables must be accessed using the `s` instance (e.g., `s.createCanvas()`).
83+
84+
```javascript
85+
function runLiveSketch(s) {
86+
s.setup = () => {
87+
s.createCanvas(640, 360);
88+
// Initialization code
89+
};
90+
91+
s.draw = () => {
92+
// Drawing code
93+
};
94+
}
95+
```

0 commit comments

Comments
 (0)