Skip to content

Commit

Permalink
brush.arc() added
Browse files Browse the repository at this point in the history
  • Loading branch information
acamposuribe committed Feb 24, 2024
1 parent 9184099 commit ec5c95a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/p5.brush.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>p5.brush.js Example</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p5.brush@1.1.2/dist/p5.brush.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p5.brush@latest/dist/p5.brush.js"></script>
<link rel="stylesheet" href="./style.css">
</head>
<body>
Expand Down
4 changes: 3 additions & 1 deletion example/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ function setup () {
i++
}
*/


brush.arc(100,100,50,0,PI/2)
brush.arc(100,100,45,PI/2,PI)


brush.noStroke()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "p5.brush",
"version": "1.1.2",
"version": "1.1.3",
"description": "Unlock custom brushes, natural fill effects and intuitive hatching in p5.js",
"main": "src/index.js",
"module": "src/index.js",
Expand Down
24 changes: 21 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @fileoverview p5.brush - A comprehensive toolset for brush management in p5.js.
* @version 1.1.2
* @version 1.1.3
* @license MIT
* @author Alejandro Campos Uribe
*
Expand Down Expand Up @@ -681,8 +681,8 @@
*/
export function reBlend() {
_r.push()
_r.set("marker","white",1)
_r.line(-10,-10,-5,-5)
set("marker","white",1)
line(-10,-10,-5,-5)
_r.pop();
}

Expand Down Expand Up @@ -2068,6 +2068,7 @@
* @param {boolean} [r=false] - If true, applies a random factor to the radius for each segment.
*/
export function circle(x,y,radius,r = false) {
_ensureReady();
// Create a new Plot instance for a curve shape
let p = new Plot("curve")
// Calculate the length of the arc for each quarter of the circle
Expand All @@ -2090,6 +2091,22 @@
let o = [x - radius * R.sin(angle),y - radius * R.cos(-angle)]
p.show(o[0],o[1],1)
}

export function arc(x,y,radius,start,end) {
_ensureReady();
// Create a new Plot instance for a curve shape
let p = new Plot("curve")
// Calculate start angle and end angle
let a1 = 270 - R.toDegrees(start), a2 = 270 - R.toDegrees(end);
// Calcualte length arc
let arcAngle = R.toDegrees(end - start);
let l = Math.PI * radius * arcAngle / 180;
// Add segments to plot
p.addSegment(a1, l, 1, true)
p.endPlot(a2, 1, true)
// Fill / hatch / draw
p.draw(x + radius * R.cos(- a1 - 90),y + radius * R.sin(- a1 - 90),1)
}

// Holds the array of vertices for the custom shape being defined. Each vertex includes position and optional pressure.
let _strokeArray = false;
Expand Down Expand Up @@ -2121,6 +2138,7 @@
* @param {string} [a] - An optional argument to close the shape if set to _r.CLOSE.
*/
export function endShape(a) {
_ensureReady();
if (a === _r.CLOSE) {
_strokeArray.push(_strokeArray[0]); // Close the shape by connecting the last vertex to the first
_strokeArray.push(_strokeArray[1]);
Expand Down

0 comments on commit ec5c95a

Please sign in to comment.