-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from hx2A/fix302
Fix #302
- Loading branch information
Showing
16 changed files
with
309 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@@ meta | ||
name = bezier_vertices() | ||
type = method | ||
|
||
@@ signatures | ||
bezier_vertices(coordinates: npt.NDArray[np.floating], /) -> None | ||
|
||
@@ variables | ||
coordinates: npt.NDArray[np.floating] - 2D array of bezier vertex coordinates with 6 or 9 columns for 2D or 3D points, respectively | ||
|
||
@@ description | ||
Create a collection of bezier vertices. The purpose of this method is to provide an alternative to repeatedly calling [](py5shape_bezier_vertex) in a loop. For a large number of bezier vertices, the performance of `bezier_vertices()` will be much faster. | ||
|
||
The `coordinates` parameter should be a numpy array with one row for each bezier vertex. The first few columns are for the first control point, the next few columns are for the second control point, and the final few columns are for the anchor point. There should be six or nine columns for 2D or 3D points, respectively. | ||
|
||
Drawing 2D bezier curves requires using the `P2D` renderer and drawing 3D bezier curves requires using the `P3D` renderer. When drawing directly with `Py5Shape` objects, bezier curves do not work at all using the default renderer. | ||
|
||
This method can only be used within a [](py5shape_begin_shape) and [](py5shape_end_shape) pair. | ||
|
||
@@ example | ||
image = Py5Shape_bezier_vertices_0.png | ||
|
||
import numpy as np | ||
|
||
def setup(): | ||
py5.size(100, 100, py5.P2D) | ||
random_bezier_vertices = 100 * np.random.rand(25, 6) | ||
s = py5.create_shape() | ||
with s.begin_shape(): | ||
s.vertex(py5.width / 2, py5.height / 2) | ||
s.bezier_vertices(random_bezier_vertices) | ||
py5.shape(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@@ meta | ||
name = curve_vertices() | ||
type = method | ||
|
||
@@ signatures | ||
curve_vertices(coordinates: npt.NDArray[np.floating], /) -> None | ||
|
||
@@ variables | ||
coordinates: npt.NDArray[np.floating] - 2D array of curve vertex coordinates with 2 or 3 columns for 2D or 3D points, respectively | ||
|
||
@@ description | ||
Create a collection of curve vertices. The purpose of this method is to provide an alternative to repeatedly calling [](py5shape_curve_vertex) in a loop. For a large number of curve vertices, the performance of `curve_vertices()` will be much faster. | ||
|
||
The `coordinates` parameter should be a numpy array with one row for each curve vertex. There should be two or three columns for 2D or 3D points, respectively. | ||
|
||
Drawing 2D curves requires using the `P2D` renderer and drawing 3D curves requires using the `P3D` renderer. When drawing directly with `Py5Shape` objects, curves do not work at all using the default renderer. | ||
|
||
This method can only be used within a [](py5shape_begin_shape) and [](py5shape_end_shape) pair. | ||
|
||
@@ example | ||
image = Py5Shape_curve_vertices_0.png | ||
|
||
import numpy as np | ||
|
||
def setup(): | ||
py5.size(100, 100, py5.P2D) | ||
random_curve_vertices = 100 * np.random.rand(25, 2) | ||
s = py5.create_shape() | ||
with s.begin_shape(): | ||
s.vertex(py5.width / 2, py5.height / 2) | ||
s.curve_vertices(random_curve_vertices) | ||
py5.shape(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@@ meta | ||
name = quadratic_vertices() | ||
type = method | ||
|
||
@@ signatures | ||
quadratic_vertices(coordinates: npt.NDArray[np.floating], /) -> None | ||
|
||
@@ variables | ||
coordinates: npt.NDArray[np.floating] - 2D array of quadratic vertex coordinates with 4 or 6 columns for 2D or 3D points, respectively | ||
|
||
@@ description | ||
Create a collection of quadratic vertices. The purpose of this method is to provide an alternative to repeatedly calling [](py5shape_quadratic_vertex) in a loop. For a large number of quadratic vertices, the performance of `quadratic_vertices()` will be much faster. | ||
|
||
The `coordinates` parameter should be a numpy array with one row for each quadratic vertex. The first few columns are for the control point and the next few columns are for the anchor point. There should be four or six columns for 2D or 3D points, respectively. | ||
|
||
Drawing 2D bezier curves requires using the `P2D` renderer and drawing 3D bezier curves requires using the `P3D` renderer. When drawing directly with `Py5Shape` objects, bezier curves do not work at all using the default renderer. | ||
|
||
@@ example | ||
image = Py5Shape_quadratic_vertices_0.png | ||
|
||
import numpy as np | ||
|
||
def setup(): | ||
py5.size(100, 100, py5.P2D) | ||
random_quadratic_vertices = 100 * np.random.rand(25, 4) | ||
s = py5.create_shape() | ||
with s.begin_shape(): | ||
s.vertex(py5.width / 2, py5.height / 2) | ||
s.quadratic_vertices(random_quadratic_vertices) | ||
py5.shape(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@@ meta | ||
name = vertices() | ||
type = method | ||
|
||
@@ signatures | ||
vertices(coordinates: npt.NDArray[np.floating], /) -> None | ||
|
||
@@ variables | ||
coordinates: npt.NDArray[np.floating] - 2D array of vertex coordinates with 2 or 3 columns for 2D or 3D points, respectively | ||
|
||
@@ description | ||
Create a collection of vertices. The purpose of this method is to provide an alternative to repeatedly calling [](py5shape_vertex) in a loop. For a large number of vertices, the performance of `vertices()` will be much faster. | ||
|
||
The `coordinates` parameter should be a numpy array with one row for each vertex. There should be two or three columns for 2D or 3D points, respectively. | ||
|
||
@@ example | ||
image = Py5Shape_vertices_0.png | ||
|
||
import numpy as np | ||
|
||
def setup(): | ||
random_triangle_vertices = 100 * np.random.rand(25, 2) | ||
s = py5.create_shape() | ||
with s.begin_shape(s.TRIANGLES): | ||
s.vertices(random_triangle_vertices) | ||
py5.shape(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/****************************************************************************** | ||
Part of the py5 library | ||
Copyright (C) 2020-2023 Jim Schmitz | ||
This library is free software: you can redistribute it and/or modify it | ||
under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 2.1 of the License, or (at | ||
your option) any later version. | ||
This library is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
package py5.core; | ||
|
||
import processing.core.PShape; | ||
|
||
public class Py5ShapeHelper { | ||
|
||
public static void vertices(PShape s, float[][] coordinates) { | ||
if (coordinates.length == 0) { | ||
// no vertices | ||
return; | ||
} | ||
|
||
if (coordinates[0].length == 2) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.vertex(coordinates[i][0], coordinates[i][1]); | ||
} | ||
} else if (coordinates[0].length == 3) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.vertex(coordinates[i][0], coordinates[i][1], coordinates[i][2]); | ||
} | ||
} else if (coordinates[0].length == 4) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.vertex(coordinates[i][0], coordinates[i][1], coordinates[i][2], coordinates[i][3]); | ||
} | ||
} else if (coordinates[0].length == 5) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.vertex(coordinates[i][0], coordinates[i][1], coordinates[i][2], coordinates[i][3], coordinates[i][4]); | ||
} | ||
} else { | ||
throw new RuntimeException("the second axis of parameter coordinates must have a length equal to 2, 3, 4, or 5"); | ||
} | ||
} | ||
|
||
public static void bezierVertices(PShape s, float[][] coordinates) { | ||
if (coordinates.length == 0) { | ||
// no vertices | ||
return; | ||
} | ||
|
||
if (coordinates[0].length == 6) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.bezierVertex(coordinates[i][0], coordinates[i][1], coordinates[i][2], coordinates[i][3], coordinates[i][4], | ||
coordinates[i][5]); | ||
} | ||
} else if (coordinates[0].length == 9) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.bezierVertex(coordinates[i][0], coordinates[i][1], coordinates[i][2], coordinates[i][3], coordinates[i][4], | ||
coordinates[i][5], coordinates[i][6], coordinates[i][7], coordinates[i][8]); | ||
} | ||
} else { | ||
throw new RuntimeException("the second axis of parameter coordinates must have a length equal to 6 or 9"); | ||
} | ||
} | ||
|
||
public static void curveVertices(PShape s, float[][] coordinates) { | ||
if (coordinates.length == 0) { | ||
// no vertices | ||
return; | ||
} | ||
|
||
if (coordinates[0].length == 2) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.curveVertex(coordinates[i][0], coordinates[i][1]); | ||
} | ||
} else if (coordinates[0].length == 3) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.curveVertex(coordinates[i][0], coordinates[i][1], coordinates[i][2]); | ||
} | ||
} else { | ||
throw new RuntimeException("the second axis of parameter coordinates must have a length equal to 2 or 3"); | ||
} | ||
} | ||
|
||
public static void quadraticVertices(PShape s, float[][] coordinates) { | ||
if (coordinates.length == 0) { | ||
// no vertices | ||
return; | ||
} | ||
|
||
if (coordinates[0].length == 4) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.quadraticVertex(coordinates[i][0], coordinates[i][1], coordinates[i][2], coordinates[i][3]); | ||
} | ||
} else if (coordinates[0].length == 6) { | ||
for (int i = 0; i < coordinates.length; ++i) { | ||
s.quadraticVertex(coordinates[i][0], coordinates[i][1], coordinates[i][2], coordinates[i][3], coordinates[i][4], | ||
coordinates[i][5]); | ||
} | ||
} else { | ||
throw new RuntimeException("the second axis of parameter coordinates must have a length equal to 4 or 6"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.