-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build Process
- Unit Testing
- Internalization
- Friendly Errors
- Other (specify if possible)
p5.js version
1.4.2
Web browser and version
105.0.5195.127
Operating System
Windows 10 19043.1826
Steps to reproduce this
I came across a non-trivial situation.
A bit of context: in my last project I was using beginShape() and I had the need to draw each line to the main layer and to the SVG layer. I tried it like this:
createCanvas(100, 100);
let svg = createGraphics(100, 100);
beginShape();
svg.beginShape();
...
vertex(x1, y1);
curveVertex(x2, y2);
vertex(x3, y3);
svg.vertex(x4, y4);
svg.curveVertex(x5, y5);
svg.vertex(x6, y6);
...
endShape();
svg.endShape();
But it turned out that the shape system ignored launching from under the element. All my vertexes were dumped into one shape, i.e. every vertex was duplicated. Which broke all my curves.
However, I discovered another funny thing:
createCanvas(100, 100);
let svg = createGraphics(100, 100);
beginShape();
...
vertex(x1, y1);
curveVertex(x2, y2);
vertex(x3, y3);
...
endShape();
svg.endShape();
This construction works and the shape, once created, can be written into any number of canvases by calling endShape from under an element.
BUT. It turns out that calling endShape will reset parameters of the shape. I.e. it loses information about whether it is a curve or a set of straight lines. This makes no sense at all, because all these parameters are re-filled when the next beginShape is called.
Here are two sketches to demonstrate.
Standard p5 library: link
A library that has the zeroing to default removed: link
My suggestion: allow the created shape to be used multiple times without such complications OR allow to store created shape in a variable for later use.