Skip to content

Updated custom-shapes-and-smooth-curves.mdx #856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 44 commits into from
Closed
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cfc7dc4
fixed typo: frameCount is a variable not a function
notthewave Feb 20, 2025
e4097c7
remove editor related images
raclim Apr 16, 2025
eefe59e
add updated editor images for intro tutorials
raclim Apr 16, 2025
47a1c6e
update image paths and alt text for editor images in intro tutorials
raclim Apr 16, 2025
a14fea8
Update contributors list
ksen0 Apr 17, 2025
d3ec73b
Merge pull request #804 from processing/update-contributors-main2
ksen0 Apr 17, 2025
2a18cb6
Revert "Update p5.js to v1.11.4"
davepagurek Apr 17, 2025
2b87485
Rebuild contributor docs, contributors, reference, p5 version
davepagurek Apr 17, 2025
dd79321
Update version
davepagurek Apr 17, 2025
9513801
Merge pull request #812 from processing/feat/perf
davepagurek Apr 18, 2025
774f7a5
Add libraries, fix bug with old featured ones not getting cycled
davepagurek Apr 23, 2025
1c8ee99
Merge pull request #819 from processing/more-libraries
davepagurek Apr 24, 2025
bd13ec3
Create p5.fps.yaml
taylorvance Apr 20, 2025
79c4e04
Add p5.fps image
taylorvance Apr 21, 2025
720f5c6
Larger fps img
taylorvance Apr 21, 2025
9bae89e
Merge pull request #816 from taylorvance/main
davepagurek Apr 25, 2025
bf92e00
Renamed `p5.ascify.yaml` to `p5.asciify.yaml`.
humanbydefinition May 4, 2025
03093c4
fix .lowerCase error
clairep94 May 5, 2025
9d48a44
minimal error handling with no return value for errors
clairep94 May 5, 2025
43b62aa
add minimal error handling to other functions
clairep94 May 5, 2025
8a7bd6c
update community 10 sketches to be fetched with getCuratedSketches wi…
clairep94 May 5, 2025
092e049
remove call to getSketchSize
clairep94 May 10, 2025
63bc0a9
Add note
clairep94 May 10, 2025
cebf48a
refactor getSketch to first check for sketchId. with test console log
clairep94 May 10, 2025
76d4202
destructure return from getSketch for legibility and revert title to …
clairep94 May 10, 2025
7c87f32
test if getSketchSize is necessary
clairep94 May 10, 2025
fa5e551
remove comments about getSketcheSize, should be implemented after OP …
clairep94 May 10, 2025
4fc8788
cleanup
clairep94 May 10, 2025
13318ef
Merge pull request #838 from clairep94/patchfix_final
ksen0 May 12, 2025
9d86cf1
update screenshots with consistent browser theme
raclim May 12, 2025
62bfc80
Merge branch 'main' into updated-editor-introduction
raclim May 12, 2025
7333293
Merge pull request #840 from raclim/updated-editor-introduction
ksen0 May 13, 2025
e548b53
Merge branch 'main' into main
ksen0 May 13, 2025
da3a49c
Merge pull request #834 from humanbydefinition/main
ksen0 May 13, 2025
39011c3
Merge branch 'main' into patch-1
ksen0 May 13, 2025
880567d
Set iframe srcdoc attribute to blank to prevent iframe navigation
limzykenneth May 14, 2025
0cab50d
Update p5.js to v1.11.7
github-actions[bot] May 14, 2025
93e7f72
Merge branch 'main' into patch-1
perminder-17 May 15, 2025
040ae7e
Merge pull request #706 from notthewave/patch-1
perminder-17 May 15, 2025
11e93ae
Merge pull request #844 from limzykenneth/fix-reference-history
limzykenneth May 19, 2025
2d25eeb
submission for shapeSVG library
ifenghm May 20, 2025
e0f17b2
rename file
ifenghm May 21, 2025
583dfb3
Merge pull request #847 from irenelfeng/main
ksen0 May 23, 2025
86fc3c6
Updated custom-shapes-and-smooth-curves.mdx
jishnunambiarr May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 74 additions & 74 deletions public/reference/data.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/search-indices/en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/search-indices/es.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/search-indices/hi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/search-indices/ko.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/search-indices/zh-Hans.json

Large diffs are not rendered by default.

40 changes: 35 additions & 5 deletions src/api/OpenProcessing.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@ export type OpenProcessingCurationResponse = Array<{
title: string;
/** Description of sketch */
description: string;
instructions: string;
mode: string;
createdOn: string;
userID: string;
submittedOn: string;
/** Author's name */
@@ -36,16 +39,19 @@ export type OpenProcessingCurationResponse = Array<{
* @param limit max number of sketches to return
* @returns sketches
*/
export const getCurationSketches = async (
export const getCurationSketches = memoize(async (
limit?: number,
): Promise<OpenProcessingCurationResponse> => {
const limitParam = limit ? `limit=${limit}` : "";
const response = await fetch(
`${openProcessingEndpoint}curation/${curationId}/sketches?${limitParam}`,
);
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
console.error('getCurationSketches', response.status, response.statusText)
}
const payload = await response.json();
return payload as OpenProcessingCurationResponse;
};
});

/**
* API Response from a call to the Sketch endpoint
@@ -69,26 +75,50 @@ export type OpenProcessingSketchResponse = {

/**
* Get info about a specific sketch from the OpenProcessing API
* First checks if the sketch is in the memoized curated sketches and returns the data if so,
* Otherwise calls OpenProcessing API for this specific sketch
*
* https://documenter.getpostman.com/view/16936458/2s9YC1Xa6X#7cd344f6-6e87-426a-969b-2b4a79701dd1
* @param id
* @returns
*/
export const getSketch = memoize(async (
id: string,
): Promise<OpenProcessingSketchResponse> => {
export const getSketch = memoize(
async (id: string): Promise<OpenProcessingSketchResponse> => {
// check for memoized sketch in curation sketches
const curationSketches = await getCurationSketches();
const memoizedSketch = curationSketches.find((el) => el.visualID === id);
if (memoizedSketch) {
return {
...memoizedSketch,
license: "",
} as OpenProcessingSketchResponse;
}

// check for sketch data in Open Processing API
const response = await fetch(`${openProcessingEndpoint}sketch/${id}`);
if (!response.ok) {
//log error instead of throwing error to not cache result in memoize
console.error("getSketch", id, response.status, response.statusText);
}
const payload = await response.json();
return payload as OpenProcessingSketchResponse;
});

/**
* Note: this currently calls `/api/sketch/:id/code`
* But only uses the width and height properties from this call
* Width and height should instead be added to properties for `/api/sketch/:id` or `api/curation/:curationId/sketches` instead
*/
export const getSketchSize = memoize(async (id: string) => {
const sketch = await getSketch(id)
if (sketch.mode !== 'p5js') {
return { width: undefined, height: undefined };
}

const response = await fetch(`${openProcessingEndpoint}sketch/${id}/code`);
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
console.error('getSketchSize', id, response.status, response.statusText)
}
const payload = await response.json();

for (const tab of payload) {
16 changes: 7 additions & 9 deletions src/components/CodeEmbed/frame.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useLayoutEffect, useEffect } from "preact/hooks";
import { useRef, useLayoutEffect, useEffect, useState } from "preact/hooks";
import { cdnLibraryUrl } from "@/src/globals/globals";

interface CodeBundle {
@@ -86,6 +86,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
const p5ScriptTag = document.getElementById(
"p5ScriptTag",
) as HTMLScriptElement;
const [mounted, setMounted] = useState(false);

// For performance, set the iframe to display:none when
// not visible on the page. This will stop the browser
@@ -101,11 +102,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
(entries) => {
entries.forEach((entry) => {
if (!iframeRef.current) return;
if (entry.isIntersecting) {
iframeRef.current.style.removeProperty("display");
} else {
iframeRef.current.style.display = "none";
}
setMounted(entry.isIntersecting);
});
},
{ rootMargin: "20px" },
@@ -118,6 +115,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
useEffect(() => {
(async () => {
if (!p5ScriptTag || !iframeRef.current) return;
if (!mounted) return;

/*
* Uses postMessage to receive the text content of p5.min.js, to be included
@@ -148,7 +146,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
return;
}
})();
}, [props.jsCode]);
}, [props.jsCode, mounted]);

return (
<div
@@ -157,13 +155,13 @@ export const CodeFrame = (props: CodeFrameProps) => {
>
<iframe
ref={iframeRef}
srcDoc={wrapInMarkup({
srcDoc={mounted ? wrapInMarkup({
js: props.jsCode,
css: props.cssCode,
htmlBody: props.htmlBodyCode,
base: props.base,
scripts: props.scripts,
})}
}) : ""}
sandbox="allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
aria-label="Code Preview"
title="Code Preview"
2 changes: 1 addition & 1 deletion src/content/contributor-docs/en/README.mdx
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ Head over to [this link](../contributor_guidelines/) where you will be guided on

Most of the time we will stick with this workflow quite strictly and, especially if you have contributed to other projects before, it may feel like there are too many hoops to jump through for what may be a simple contribution. However, the steps above are aimed to make it easy for you as a contributor and for stewards/maintainers to contribute meaningfully, while also making sure that you won't be spending time working on things that may not be accepted for various reasons. The steps above will help ensure that any proposals or fixes are adequately discussed and considered before any work begin, and often this will actually save you (and the steward/maintainer) time because the PR that would need additional fixing after review, or outright not accepted, would happen less often as a result.

**We see contributing to p5.js as a learning opportunity** and we don't measure sucess by only looking at the volume of contributions we received. There is no time limit on how long it takes you to complete a contribution, so take your time and work at your own pace (we may check in after a long period of inactivity). Ask for help from any of the stewards or maintainers if you need them and we'll try our best to support you. For information related to area stewards or general maintenance of p5.js GitHub repository, please check out the [steward guidelines](../steward_guidelines/).
**We see contributing to p5.js as a learning opportunity** and we don't measure success by only looking at the volume of contributions we received. There is no time limit on how long it takes you to complete a contribution, so take your time and work at your own pace (we may check in after a long period of inactivity). Ask for help from any of the stewards or maintainers if you need them and we'll try our best to support you. For information related to area stewards or general maintenance of p5.js GitHub repository, please check out the [steward guidelines](../steward_guidelines/).

## Non-source code contribution

Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ If the parameter is optional, add square brackets around the name:

### Additional info: Constants

If the parameter takes one or more values defined in [`constants.js`](https://github.com/processing/p5.js/blob/main/src/core/constants.js) , then the type should be specified as `{Constant}` and the valid values should be enumerated in the comment following the `either` keyword, e.g.:
If the parameter takes one or more values defined in [`constants.js`](https://github.com/processing/p5.js/blob/main/src/core/constants.js), then the type should be specified as `{Constant}` and the valid values should be enumerated in the comment following the `either` keyword, e.g.:

```
@param {Constant} horizAlign horizontal alignment, either LEFT, CENTER, or RIGHT
@@ -225,7 +225,7 @@ The relevant `@example` tag to create the above is as follows:

After the `@example` tag, you should start an HTML `<div>` tag followed by a `<code>` tag. In between the opening and closing `<code>` tag, you will insert the relevant example code. The basic principle of writing good example code for the reference is to keep things simple and minimal. The example should be meaningful and explain how the feature works without being too complicated. The example’s canvas should be 100x100 pixels and if the `setup()` function is not included, such as in the example above, the code will be automatically wrapped in a `setup()` function with a default 100x100 pixels gray background canvas created. We won’t go through the details about best practices and code style for the example code here; please see the reference style guide instead.

You can have multiple examples for one feature.To do so, add an additional `<div>` and `<code>` HTML block right after the first closed, separated by a blank line.
You can have multiple examples for one feature. To do so, add an additional `<div>` and `<code>` HTML block right after the first closed, separated by a blank line.

```
* @example
2 changes: 1 addition & 1 deletion src/content/contributor-docs/en/contributor_guidelines.mdx
Original file line number Diff line number Diff line change
@@ -386,7 +386,7 @@ p5.js' code standard or code style is enforced by [ESLlint](https://eslint.org/)

While working on any features of p5.js, it is important to keep in mind the design principles of p5.js. Our priorities may differ from the priorities of other projects, so if you are coming from a different project, we recommend that you familiarize yourself with p5.js' design principles.

* **Access** We prioritize accessibility first and foremost, and decisions we make must take into account how it increases access to historically marginalized groups. Read more about this in our access statement.
* **Access** We prioritize accessibility first and foremost, and decisions we make must take into account how they increase access to historically marginalized groups. Read more about this in our access statement.
* **Beginner Friendly** The p5.js API aims to be friendly to beginner coders, offering a low barrier to creating interactive and visual web content with cutting-edge HTML5/Canvas/DOM APIs.
* **Educational** p5.js is focused on an API and curriculum that supports educational use, including a complete reference to the API with supporting examples, as well as tutorials and sample class curricula that introduce core creative coding principles in a clear and engaging order.
* **JavaScript and its community** p5.js aims to make web development practices more accessible to beginners by modeling proper JavaScript design patterns and usage while abstracting them where necessary. As an open-source library, p5.js also includes the wider JavaScript community in its creation, documentation, and dissemination.
4 changes: 2 additions & 2 deletions src/content/contributor-docs/en/creating_libraries.mdx
Original file line number Diff line number Diff line change
@@ -278,7 +278,7 @@ Your addon library may not extend p5 or p5 classes at all, but instead just offe

**p5.js has two modes, global mode and instance mode.** In global mode, all p5 properties and methods are bound to the `window` object, allowing users to call methods like `background()` without having to prefix them with anything. However, this means you need to be careful not to overwrite native JavaScript functionality. For example “`Math`” and “`console`” are both native Javascript functionalities so you shouldn’t have methods named “`Math`” or “`console`”.

**Class names should use** `PascalCase`**, while methods and properties should use** `camelCase`**.** Classes in p5 are prefixed with p5. We would like to keep this namespace for p5 core classes only, so when you create your own namespace, **do not include the** `p5.` **prefix for class names**. You are welcomed to create your own prefix, or just give them non-prefixed names.
**Class names should use** `PascalCase`**, while methods and properties should use** `camelCase`**.** Classes in p5 are prefixed with p5. We would like to keep this namespace for p5 core classes only, so when you create your own namespace, **do not include the** `p5.` **prefix for class names**. You are welcome to create your own prefix, or just give them non-prefixed names.

```js
// Do not do this
@@ -306,4 +306,4 @@ p5.prototype.myMethod = function(){

**Examples are great, too!** They show people what your library can do. Because this is all JavaScript, people can see them running online before they download anything.[ ](http://jsfiddle.net/) You can create a collection of examples on the p5.js web editor to showcase how your library works.

**Submit your library!** Once your library is ready for distribution and you’d like it included on the [p5js.org/libraries](https://p5js.org/libraries/) page, please submit a pull request on the p5.js website GitHub repository following [this intruction](https://github.com/processing/p5.js-website/blob/main/docs/contributing_libraries.md)!
**Submit your library!** Once your library is ready for distribution and you’d like it included on the [p5js.org/libraries](https://p5js.org/libraries/) page, please submit a pull request on the p5.js website GitHub repository following [this instruction](https://github.com/processing/p5.js-website/blob/main/docs/contributing_libraries.md)!
6 changes: 3 additions & 3 deletions src/content/contributor-docs/en/documentation_style_guide.mdx
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ Always use `let` to declare variables.

**Accessibility terminology**

The following terminiology is adapted from the WordPress documentation guidelines for [Writing inclusive documentation](https://make.wordpress.org/docs/style-guide/general-guidelines/inclusivity/#accessibility-terminology). For more background on people-first language, see the CDC's guide on [Communicating With and About People with Disabilities](https://www.cdc.gov/ncbddd/disabilityandhealth/materials/factsheets/fs-communicating-with-people.html).
The following terminology is adapted from the WordPress documentation guidelines for [Writing inclusive documentation](https://make.wordpress.org/docs/style-guide/general-guidelines/inclusivity/#accessibility-terminology). For more background on people-first language, see the CDC's guide on [Communicating With and About People with Disabilities](https://www.cdc.gov/ncbddd/disabilityandhealth/materials/factsheets/fs-communicating-with-people.html).

| Recommended | Not Recommended |
| --------------------------------------------------------------- | ------------------------------------------------------------------ |
@@ -722,7 +722,7 @@ if (

## Iteration

* Don’t use a `while` or `do-while` loops unless it's necessary. Use `for` loops to iterate a fixed number of times.
* Don’t use `while` or `do-while` loops unless it's necessary. Use `for` loops to iterate a fixed number of times.

```javascript
let numPetals = 7;
@@ -905,7 +905,7 @@ for (let i = 0; i < numbers.length; i += 1) {
let numbersCopy = numbers.slice();
```

* Write arrays on multiple lines when it improves readibility. Use line breaks after the opening bracket and before the closing bracket. Add a trailing comma.
* Write arrays on multiple lines when it improves readability. Use line breaks after the opening bracket and before the closing bracket. Add a trailing comma.

```javascript
// Bad.
12 changes: 6 additions & 6 deletions src/content/contributor-docs/en/fes_contribution_guide.mdx
Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ arc(1, 1, 10.5, 10);
FES will generate the following message in the console:

```
🌸 p5.js says: [sketch.js, line 13] arc() was expecting at least 6 arguments, but received only 4. (http://p5js.org/reference/#/p5/arc)
🌸 p5.js says: [sketch.js, line 13] arc() was expecting at least 6 arguments, but received only 4. (https://p5js.org/reference/p5/arc)
```

Example of a type mismatch
@@ -249,7 +249,7 @@ arc(1, ',1', 10.5, 10, 0, Math.PI);
FES will generate the following message in the console:

```
🌸 p5.js says: [sketch.js, line 14] arc() was expecting Number for the first parameter, received string instead. (http://p5js.org/reference/#/p5/arc)
🌸 p5.js says: [sketch.js, line 14] arc() was expecting Number for the first parameter, received string instead. (https://p5js.org/reference/p5/arc)
```

#### Location
@@ -323,7 +323,7 @@ function preload() {
FES will generate the following message in the console:

```
🌸 p5.js says: [sketch.js, line 8] An error with message "Cannot read properties of undefined (reading 'background')" occurred inside the p5js library when "background" was called. If not stated otherwise, it might be due to "background" being called from preload. Nothing besides load calls (loadImage, loadJSON, loadFont, loadStrings, etc.) should be inside the preload function. (http://p5js.org/reference/#/p5/preload)
🌸 p5.js says: [sketch.js, line 8] An error with message "Cannot read properties of undefined (reading 'background')" occurred inside the p5js library when "background" was called. If not stated otherwise, it might be due to "background" being called from preload. Nothing besides load calls (loadImage, loadJSON, loadFont, loadStrings, etc.) should be inside the preload function. (https://p5js.org/reference/p5/preload)
```

Internal Error Example 2:
@@ -338,7 +338,7 @@ function setup() {
FES will generate the following message in the console:

```js
🌸 p5.js says: [sketch.js, line 12] An error with message "Cannot read properties of undefined (reading 'bind')" occurred inside the p5js library when mouseClicked was called. If not stated otherwise, it might be an issue with the arguments passed to mouseClicked. (http://p5js.org/reference/#/p5/mouseClicked)
🌸 p5.js says: [sketch.js, line 12] An error with message "Cannot read properties of undefined (reading 'bind')" occurred inside the p5js library when mouseClicked was called. If not stated otherwise, it might be an issue with the arguments passed to mouseClicked. (https://p5js.org/reference/p5/mouseClicked)
```

Example of an Error (Scope):
@@ -373,7 +373,7 @@ function setup() {
FES will generate the following message in the console:

```
🌸 p5.js says: [sketch.js, line 2] It seems that you may have accidentally written "xolor" instead of "color". Please correct it to color if you wish to use the function from p5.js. (http://p5js.org/reference/#/p5/color)
🌸 p5.js says: [sketch.js, line 2] It seems that you may have accidentally written "xolor" instead of "color". Please correct it to color if you wish to use the function from p5.js. (https://p5js.org/reference/p5/color)
```

#### Location
@@ -413,7 +413,7 @@ function preload() {
FES will generate the following message in the console:

```
🌸 p5.js says: It seems that you may have accidentally written preLoad instead of preload. Please correct it if it's not intentional. (http://p5js.org/reference/#/p5/preload)
🌸 p5.js says: It seems that you may have accidentally written preLoad instead of preload. Please correct it if it's not intentional. (https://p5js.org/reference/p5/preload)
```

#### Location
2 changes: 1 addition & 1 deletion src/content/contributor-docs/en/friendly_error_system.mdx
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ The basic format of a translation file's item has a key and a value (message) in
{ "key": "value" }
```

For example, we have a ASCII logo saved in this format:
For example, we have an ASCII logo saved in this format:

```json
"logo": " _ \n /\\| |/\\ \n \\ ` ' / \n / , . \\ \n \\/|_|\\/ \n\n"
Loading
Oops, something went wrong.