Skip to content

Commit 0d9ab40

Browse files
authored
Added 1.x to 2.0 transition guide
1 parent 9052e2d commit 0d9ab40

File tree

1 file changed

+87
-19
lines changed

1 file changed

+87
-19
lines changed

README.md

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,111 @@
11
# p5.js-compatibility
22

3-
Addons that add p5.js 1.x to p5.js 2.x
3+
Addons that add p5.js 1.x featureto p5.js 2.x
44

5-
## What do you think?
5+
Even as p5.js 2.0 becomes more stable, p5.js 1.x will continue to be supported for at least a year. Between 1.x and 2.0, there are many additions, and some breaking changes. In addition to making p5.js 2.0 available as a library, we are working on preparing several compatibility addons that would make it possible to keep using 1.x features that are no longer part of 2.0.
6+
7+
We are working on three compatibility addons which will make these 1.x features available for 2.0:
8+
9+
1. [preload.js](https://github.com/processing/p5.js-compatibility/blob/main/src/preload.js)
10+
11+
2. [shapes.js](https://github.com/processing/p5.js-compatibility/blob/main/src/shapes.js)
12+
13+
3. Data structures
614

715
Your feedback is welcome [on this issue](https://github.com/processing/p5.js/issues/7488)!
816

9-
## Compatibility Addons
17+
# How to update p5.js code from 1.x to 2.0
1018

11-
Even as p5.js 2.0 becomes more stable, p5.js 1.x will continue to be supported for at least a year. Between 1.x and 2.0, there are many additions, and some breaking changes. In addition to making p5.js 2.0 available as a library, we are working on preparing several compatibility addons that would make it possible to keep using 1.x features that are no longer part of 2.0.
19+
Most things are the same between p5.js 1.x and 2.0, but there are some big differences: p5.js 2.0 has new capabilities, and it also no longer supports some aspects of p5.js 1.x.
1220

13-
We are working on three compatibility addons which will make these 1.x features available for 2.0:
21+
## Do I have to update my 1.x sketches? Maybe!
22+
23+
First, you should try to update the version and see if the sketch still runs! In many cases, no actions are needed - just update the version and you’re all set.
24+
25+
## However, if the sketch doesn’t run anymore using 2.0, then you can either update it to use 2.0, or keep it using 1.x. If any of this sounds applicable, then follow the guide below to update your sketches:
26+
27+
* If you want to use p5.js 2.0 features, like variable-weight fonts
28+
* If you need your sketches to work after August, 2026. At that point, 1.x will no longer be supported, and 2.0 will become the default in the p5.js Editor. If you face any challenges in making updates, please consider joining the discussion and filing bugs to help make p5.js 2.0 a robust tool for the whole community.
29+
* If you want to use an addon or community library that uses p5.js 2.0 featurescal
30+
* If you want to be able to better integrate with other tools and libraries in the JavaScript ecosystem
31+
32+
## How can I update my 1.x sketches? Three steps!
33+
34+
Step 1: Switch to 2.0 by using one of the [beta releases](https://github.com/processing/p5.js/releases/) when you import the core library! An [option to switch to 2.0 will be available in the p.js Editor](https://github.com/processing/p5.js-web-editor/pull/3334) once the new release is live!
35+
36+
Step 2: Try running your sketch! In many cases, this will work right away, and no other changes would be needed.
37+
38+
Step 3: If your 1.x sketch does not run with p5.js 2.0, you have two options:
1439

15-
1. `preload()`
40+
* Update your code to match 2.0
41+
* or (2) Include a compatibility addon (after release, [this will also be possible in the p.js Editor](https://github.com/processing/p5.js-web-editor/pull/3334) once the new release is live.
1642

17-
2. `beginShape`/`endShape` API
43+
# Changes to make if you are…
1844

19-
3. Data structures (see full list below)
45+
## …loading Images, Sound, Fonts, and other Assets
2046

21-
So, for example, if you want to use something like `preload()`, which has been removed in 2.0, you could use a `<script>` tag to import both p5.js 2.0 and the compatibility addon for that feature. If you do that, any use of preload() just like in 1.x will continue to work.
47+
One of the biggest changes in 2.0 is involves how you can include other files, media, and assets. The p5.js 1.x style of using `preload()` does not reflect anymore how assets are loaded on the web, so p5.js 2.0 uses JavaScript’s async/await keywords to support asynchronicity.
2248

23-
## Data Structures 1.x Compatibility
49+
If you’re interested in the history of async [read on here](https://dev.to/limzykenneth/asynchronous-p5js-20-458f)!
2450

25-
One bit change relates to data structures in JavaScript. We’re planning on removing the following functions in p5.js 2.0.
51+
To play around, check out [the example from the p5.js 1.x `preload()` reference](https://p5js.org/reference/p5/preload/), but get a very big file instead of bricks.jpg.
2652

27-
These were originally in p5.js because, historically, they were also in Processing. However, p5.js is a JavaScript library, and JavaScript objects and key-value maps can be used instead of these functions:
53+
This is the p5.js 1.x code, and it will result in a blank “Loading…” screen and then show the image:
54+
55+
```
56+
let img;
57+
58+
// Load an image and create a p5.Image object.
59+
function preload() {
60+
img = loadImage('/assets/bricks.jpg');
61+
}
62+
63+
function setup() {
64+
createCanvas(100, 100);
65+
66+
// Make a red background - will not actually see this in 1.x
67+
background(255, 0, 0);
68+
69+
// Draw the image.
70+
image(img, 0, 0);
71+
72+
describe('A red brick wall.');
73+
}
74+
```
75+
76+
Using p5.js 2.0, and it will result in the red background being shown before the image loads, so people viewing your sketch don’t have to look at a blank screen:
77+
78+
```
79+
let img;
80+
81+
async function setup() {
82+
createCanvas(100, 100);
83+
img = await loadImage('/assets/bricks.jpg');
84+
85+
// Make a red background - in 2.0 will be shown while the image loads
86+
background(255, 0, 0);
87+
88+
// Draw the image.
89+
image(img, 0, 0);
90+
91+
describe('A red brick wall.');
92+
}
93+
```
94+
95+
## …making Shapes
96+
97+
Short guide coming soon! For now, you can [find out more here](https://github.com/processing/p5.js/issues/6766)
98+
99+
## …using non-JS Data Structures
100+
101+
One bit change relates to data structures in JavaScript. The following funcitons have been removed in p5.js 2.0. These were originally in p5.js 1.x because, historically, they were also in Processing. However, p5.js is a JavaScript library, and JavaScript objects and key-value maps can be used instead of these functions:
28102

29103
* `createStringDict()`
30104
* `createNumberDict()`
31105
* `p5.TypedDict`
32106
* `p5.NumberDict`
33107

34-
Instead of the above functions, we would recommend using built-in JavaScript Objects: https://p5js.org/reference/p5/Object/
108+
Instead of the above functions, we would recommend using [built-in JavaScript Objects](https://p5js.org/reference/p5/Object/ )
35109

36110
The below functions are also better supported in JavaScript itself:
37111

@@ -44,9 +118,3 @@ The below functions are also better supported in JavaScript itself:
44118
* `splice()`
45119
* `subset()`
46120

47-
Lastly, `table` IO functions would also be affected:
48-
49-
* `loadTable()`
50-
* `saveTable()`
51-
* `p5.Table`
52-
* `p5.TableRow`

0 commit comments

Comments
 (0)