Skip to content
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

Overhaul custom shapes for p5.js 2.0 #7373

Merged
merged 114 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
62567a9
commit message
GregStanton Nov 9, 2024
2107ecb
Add custom_shapes.js to eventually replace vertex.js
GregStanton Nov 9, 2024
e38b3b9
Set up files for custom shape refactor
GregStanton Nov 12, 2024
cff8461
Merge branch 'dev-2.0' of https://github.com/processing/p5.js into de…
GregStanton Nov 12, 2024
b778784
Add inline documentation for Shape class
GregStanton Nov 12, 2024
19e8c48
Fix documentation of default parameter for Shape constructor
GregStanton Nov 12, 2024
8eb74e6
Update inline documentation for p5.Shape
GregStanton Nov 13, 2024
f0fc908
Document p5.Vertex
GregStanton Nov 14, 2024
1a05d51
Fix code snippet in p5.Vertex documentation
GregStanton Nov 14, 2024
45591b0
Revise p5.Vertex documentation and add todo comment about a new imple…
GregStanton Nov 15, 2024
37c2db4
Move TODO comments out of the code (and into project timeline)
GregStanton Nov 15, 2024
9663eda
Document p5.Contour
GregStanton Nov 15, 2024
5cd71a2
Document p5.ShapePrimitive (and revise some other documentation).
GregStanton Nov 15, 2024
84a0fde
Revise docs for clarity.
GregStanton Nov 15, 2024
0b117cc
Add TODO comment about Vertex interface
GregStanton Nov 22, 2024
2fcc2b0
Describe custom vertex properties in Shape docs
GregStanton Nov 22, 2024
d862591
Revise p5.Contour docs based on new design
GregStanton Nov 22, 2024
8ea67c5
Remove @constructor tags (YUIDoc syntax)
GregStanton Nov 22, 2024
1443b53
Fix typo in Shape docs
GregStanton Nov 22, 2024
78940ff
Update p5.ShapePrimitive docs with new design
GregStanton Nov 22, 2024
4dac39e
Update p5.Vertex docs to reflect new design
GregStanton Nov 22, 2024
567ff25
Make p5.Vertex and p5.Shape constructors consistent
GregStanton Nov 22, 2024
dbff7a2
Merge branch 'dev-2.0' of https://github.com/processing/p5.js into de…
GregStanton Nov 22, 2024
727ff60
Move fill and stroke into the base renderer
davepagurek Nov 18, 2024
c756172
Add vertex state getter
davepagurek Nov 18, 2024
b4e43e5
Fix usage of false instead of null
davepagurek Nov 22, 2024
64e319b
Add properties to current shape
davepagurek Nov 22, 2024
290f5c7
Update vertexProperties to make setters
davepagurek Nov 23, 2024
cd156bf
Refactor old vertex() into legacyVertex() and start making new vertex()
davepagurek Nov 23, 2024
bc252e3
Implement Vertex constructor
GregStanton Nov 23, 2024
0c61aaf
Implement ShapePrimitive, add some doc tags
GregStanton Nov 23, 2024
2326ff5
Add PATH to constants.js
GregStanton Nov 23, 2024
75030a5
Implement Contour
GregStanton Nov 23, 2024
70a6fa6
Add EMPTY_PATH to constants.js
GregStanton Nov 23, 2024
d7aec76
Add kind getter to Contour to handle EMPTY_PATH
GregStanton Nov 23, 2024
27f0b26
Add tag to Anchor docs
GregStanton Nov 23, 2024
4eaa56f
Implement Anchor, add vertices to ShapePrimitive
GregStanton Nov 23, 2024
13f21d9
Implement Segment, add tags to docs
GregStanton Nov 24, 2024
787ca3c
Implement addToShape on ShapePrimitive (base class)
GregStanton Nov 24, 2024
dbf64f6
Changed initial value of index in Segment
GregStanton Nov 24, 2024
65c2d32
Add note in Segment docs
GregStanton Nov 24, 2024
20922c7
Move index out of base Segment class
GregStanton Nov 24, 2024
9468d2e
Add at() method on Shape, revise Segment & Anchor, implement LineSegm…
GregStanton Nov 24, 2024
13b0519
Merge branch 'dev-2.0' of https://github.com/processing/p5.js into de…
GregStanton Nov 26, 2024
6adb65a
Implement all custom shape constants as Symbols
GregStanton Nov 26, 2024
ee77b1c
Implement PrimitiveShapeCreators
GregStanton Nov 26, 2024
b6aec19
Set all custom shape constants to numbers (for now)
GregStanton Nov 27, 2024
69ed953
Make PrimitiveShapeCreators work with number constants instead of Sym…
GregStanton Nov 27, 2024
893c897
Merge branch 'dev-2.0' of https://github.com/processing/p5.js into de…
GregStanton Nov 27, 2024
60739f0
Implement beginShape(), endShape() on Shape and update docs
GregStanton Nov 27, 2024
15001d9
Implement vertex() on Shape, refactor, fix bugs
GregStanton Nov 27, 2024
e862092
Fix spacing
GregStanton Nov 27, 2024
722125b
Implement abstract base class PrimitiveVisitor
GregStanton Nov 28, 2024
4fd0458
Add anchor visitor method to base class
GregStanton Nov 28, 2024
18a2e6c
Implement PrimitiveToPath2DConverter with anchor and line segment vis…
GregStanton Nov 28, 2024
a42fb19
Use only new rendering code and start connecting visitors
davepagurek Nov 28, 2024
49be169
Initial WebGL tesselation support
davepagurek Nov 29, 2024
d7f722a
Remove duplicate line of code
GregStanton Dec 2, 2024
18179eb
Add comment about naming
GregStanton Dec 3, 2024
2eb615a
Remove trailing spaces per linter
GregStanton Dec 3, 2024
ba4b42f
Implement getEndVertex() on base class (derived classes may override it)
GregStanton Dec 3, 2024
e86d2e0
Implement BezierSegment class and modify PrimitiveShapeCreators to re…
GregStanton Dec 3, 2024
a25cbaf
Add comment about Bezier order
GregStanton Dec 3, 2024
94ce58e
Revise comment about Bezier order
GregStanton Dec 3, 2024
3b5a0fc
Implement bezierOrder(), revise BezierSegment
GregStanton Dec 3, 2024
81a9da8
Merge branch 'dev-2.0' of https://github.com/processing/p5.js into de…
GregStanton Dec 3, 2024
0368609
Refactor, implement all vertex functions on Shape
GregStanton Dec 3, 2024
002d4a1
Merge branch 'dev-2.0' of https://github.com/processing/p5.js into de…
GregStanton Dec 3, 2024
9e63827
Implement Path2D visitor method for Bezier segments
GregStanton Dec 3, 2024
3ca8c6f
Add explanatory and to-do comments
GregStanton Dec 4, 2024
34e629b
Implement SplineSegment and refactor
GregStanton Dec 4, 2024
8b45067
Fix naming
GregStanton Dec 4, 2024
38e3906
Fix warning message and spacing
GregStanton Dec 4, 2024
e4a1749
Fix logic for warning message in SplineSegment
GregStanton Dec 4, 2024
0e6debe
Implement catmullRomToBezier()
GregStanton Dec 4, 2024
a33fde0
Refactor and implement spline segment visitor
GregStanton Dec 4, 2024
9a27eb4
Connect bezier methods
davepagurek Dec 4, 2024
22e4450
Add spline end modes
davepagurek Dec 5, 2024
dba73b3
Update warning check
davepagurek Dec 5, 2024
d608016
Fix missing bits
davepagurek Dec 5, 2024
1eb56fe
Merge branch 'dev-2.0' into greg
davepagurek Dec 5, 2024
7fd2eb2
Support WebGL custom vertex attributes
davepagurek Dec 5, 2024
b26ca0f
Implement WebGL bezier vertex subdivision
davepagurek Dec 6, 2024
9cb0dda
Implement spline vertices for WebGL
davepagurek Dec 6, 2024
9b6745a
Only pass fill, stroke, and texture coordinates if they are supported
davepagurek Dec 7, 2024
2ea2f77
Handle endShape(CLOSE) with a stroke join
davepagurek Dec 7, 2024
76dab14
Only use JOIN internally when closing a shape
davepagurek Dec 7, 2024
746bc1f
Handle closing of contours
davepagurek Dec 7, 2024
7e33ec7
Remove begin/endGeometry in favor of buildGeometry
davepagurek Dec 11, 2024
949ca22
Add WebGL handling for other shape primitives
davepagurek Dec 11, 2024
9765060
Add 2D path visitors
davepagurek Dec 12, 2024
e16839c
Convert more legacy WebGL shape code
davepagurek Dec 12, 2024
80e1c3e
Get 2D clipping working again
davepagurek Dec 12, 2024
7fbcaa6
Add to-do comment and fix mistake
GregStanton Dec 13, 2024
cf4e1e1
Merge remote-tracking branch 'origin/dev-2.0' into dev-2.0
GregStanton Dec 13, 2024
c37d444
Merge remote-tracking branch 'upstream/dev-2.0' into dev-2.0
GregStanton Dec 13, 2024
da3c1fc
Address linter warnings
GregStanton Dec 13, 2024
4805583
Replace shouldAddToShape() with addedToShape() and implement on base …
GregStanton Dec 13, 2024
d46c68a
Replace addedToShape() with a local variable
GregStanton Dec 13, 2024
bf66a98
Remove unnecessary constructors from derived classes
GregStanton Dec 13, 2024
3d6afa4
Implement isolated and tessellation primitives, fix visitors
GregStanton Dec 14, 2024
b6725bb
Fix fills not working with QUAD_STRIP
davepagurek Dec 14, 2024
2e31059
Fix QUAD_STRIP in 2d mode
davepagurek Dec 14, 2024
7818a24
Fix more 2D bugs
davepagurek Dec 14, 2024
315da93
Fix POINTS mode in 2D
davepagurek Dec 14, 2024
999339e
Fix some spline test issues, rename curveVertex to splineVertex every…
davepagurek Dec 14, 2024
1cb1fde
Fix more tests referring to TESS
davepagurek Dec 14, 2024
33fc602
Fix contour ends not having a join in WebGL
davepagurek Dec 14, 2024
f7d0255
Fix some vertex property tests, switch some to visual tests, fix inst…
davepagurek Dec 14, 2024
4b3606b
Fix the rest of the RendererGL tests!
davepagurek Dec 14, 2024
593322c
Un-break typography tests
davepagurek Dec 14, 2024
fe78cfe
Add new tests
davepagurek Dec 14, 2024
00f414a
Remove console logs
davepagurek Dec 14, 2024
6f10af2
Use new SHOW/HIDE names, INCLUDE/EXCLUDE
davepagurek Dec 14, 2024
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
57 changes: 49 additions & 8 deletions preview/global/sketch.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
console.log(p5);
const vertSrc = `#version 300 es
precision mediump float;
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;

in vec3 aPosition;
in vec2 aOffset;

void main(){
vec4 positionVec4 = vec4(aPosition.xyz, 1.0);
positionVec4.xy += aOffset;
gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
}
`;

const fragSrc = `#version 300 es
precision mediump float;
out vec4 outColor;
void main(){
outColor = vec4(0.0, 1.0, 1.0, 1.0);
}
`;

let myShader;
function setup(){
createCanvas(200, 200);
createCanvas(100, 100, WEBGL);

// Create and use the custom shader.
myShader = createShader(vertSrc, fragSrc);

describe('A wobbly, cyan circle on a gray background.');
}

async function draw(){
background(0, 50, 50);
circle(100, 100, 50);
function draw(){
// Set the styles
background(125);
noStroke();
shader(myShader);

// Draw the circle.
beginShape();
for (let i = 0; i < 30; i++){
const x = 40 * cos(i/30 * TWO_PI);
const y = 40 * sin(i/30 * TWO_PI);

// Apply some noise to the coordinates.
const xOff = 10 * noise(x + millis()/1000) - 5;
const yOff = 10 * noise(y + millis()/1000) - 5;

fill('white');
textSize(30);
text('hello', 10, 30);
// Apply these noise values to the following vertex.
vertexProperty('aOffset', [xOff, yOff]);
vertex(x, y);
}
endShape(CLOSE);
}
32 changes: 16 additions & 16 deletions preview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@
import p5 from '../src/app.js';

const sketch = function (p) {
let f;
const testWebgl = true

p.setup = async function () {
// TODO: make this work without a name
f = await p.loadFont('font/Lato-Black.ttf', 'Lato')
p.createCanvas(200, 200, testWebgl ? p.WEBGL : undefined);
p.setup = function () {
p.createCanvas(100, 100, p.WEBGL);
};

p.draw = function () {
p.background(0, 50, 50);
if (testWebgl) p.translate(-p.width/2, -p.height/2);

p.fill('white');
p.textSize(60);
p.textAlign(p.RIGHT, p.CENTER)
p.textFont(f)
p.text('hello, world!', 0, p.height/2, p.width);
p.background(200);
p.strokeCap(p.SQUARE);
p.strokeJoin(p.MITER);
p.translate(-p.width/2, -p.height/2);
p.noStroke();
p.beginShape();
p.bezierOrder(2);
p.fill('red');
p.vertex(10, 10);
p.fill('lime');
p.bezierVertex(40, 25);
p.fill('blue');
p.bezierVertex(10, 40);
p.endShape();
};
};

new p5(sketch);
</script>
<p style="font-family: Lato">hello, world!</p>
</body>

</html>
4 changes: 4 additions & 0 deletions src/color/p5.Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ class Color {
}

get _array() {
return this.array();
}

array() {
return [...this.color.coords, this.color.alpha];
}

Expand Down
4 changes: 2 additions & 2 deletions src/color/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ function setting(p5, fn){
* </div>
*/
fn.noFill = function() {
this._renderer.states.doFill = false;
this._renderer.noFill();
return this;
};

Expand Down Expand Up @@ -1325,7 +1325,7 @@ function setting(p5, fn){
* </div>
*/
fn.noStroke = function() {
this._renderer.states.doStroke = false;
this._renderer.states.strokeColor = null;
return this;
};

Expand Down
42 changes: 41 additions & 1 deletion src/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,18 @@ export const QUAD_STRIP = 'quad_strip';
* @final
*/
export const TESS = 'tess';
/**
* @typedef {0x0007} EMPTY_PATH
* @property {EMPTY_PATH} EMPTY_PATH
* @final
*/
export const EMPTY_PATH = 0x0007;
/**
* @typedef {0x0008} PATH
* @property {PATH} PATH
* @final
*/
export const PATH = 0x0008;
/**
* @typedef {'close'} CLOSE
* @property {CLOSE} CLOSE
Expand Down Expand Up @@ -1330,4 +1342,32 @@ export const HALF_FLOAT = 'half-float';
* @property {RGBA} RGBA
* @final
*/
export const RGBA = 'rgba';
export const RGBA = 'rgba';

/**
* The `splineEnds` mode where splines curve through
* their first and last points.
* @typedef {unique symbol} INCLUDE
* @property {INCLUDE} INCLUDE
* @final
*/
export const INCLUDE = Symbol('include');

/**
* The `splineEnds` mode where the first and last points in a spline
* affect the direction of the curve, but are not rendered.
* @typedef {unique symbol} EXCLUDE
* @property {EXCLUDE} EXCLUDE
* @final
*/
export const EXCLUDE = Symbol('exclude');

/**
* The `splineEnds` mode where the spline loops back to its first point.
* Only used internally.
* @typedef {unique symbol} JOIN
* @property {JOIN} JOIN
* @final
* @private
*/
export const JOIN = Symbol('join');
3 changes: 0 additions & 3 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,6 @@ class p5 {

this._styles = [];

this._bezierDetail = 20;
this._curveDetail = 20;

this._colorMode = constants.RGB;
this._colorMaxes = {
rgb: [255, 255, 255, 255],
Expand Down
Loading
Loading