You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the running PApplet instance: in Processing, just pass the keyword 'this'
w
width
h
height
void setPath(String _path)
Set the output file path. The filename should include the file type extension. Supported embroidery formats are: .DST, .EXP, .JEF, .PEC, .PES, .VP3, and .XXX. Additionally supported formats are: .PDF, .SVG, .TSV, and .GCODE.
parameter
description
_path
output file path. The format will be automatically inferred from the extension.
void clear()
Clear all current drawings.
parameter
description
void fill(int r, int g, int b)
Change fill color
parameter
description
r
red value, 0-255
g
green value, 0-255
b
blue value, 0-255
returnstroke
void fill(int gray)
Change fill color
parameter
description
gray
grayscale value, 0-255
void noFill()
Disable filling shapes
parameter
description
void stroke(int r, int g, int b)
Change stroke color
parameter
description
r
red value, 0-255
g
green value, 0-255
b
blue value, 0-255
returnfill
void stroke(int gray)
Change stroke color
parameter
description
gray
grayscale value 0-255
void noStroke()
Disable outlining shapes
parameter
description
void strokeWeight(float d)
Change width of stroke
parameter
description
d
the stroke weight to use
void strokeJoin(int j)
Change stroke join (turning point) style
parameter
description
j
Same as Processing strokeJoin, this can be ROUND, MITER, BEVEL etc.
returnstrokeCap
void strokeCap(int j)
Change stroke cap (end point) style
parameter
description
j
Same as Processing strokeCap, this can be ROUND, SQUARE, PROJECT etc.
returnstrokejoin
void ellipseMode(int mode)
Modifies the location from which ellipses are drawn by changing the way in which parameters given to ellipse() are intepreted. also governs circle()
parameter
description
j
Same as Processing ellipseMode, this can be RADIUS, CENTER, CORNER, CORNERS etc.
returnrectMode
void rectMode(int mode)
Modifies the location from which rectangles are drawn by changing the way in which parameters given to rect() are intepreted.
parameter
description
j
Same as Processing rectMode, this can be RADIUS, CENTER, CORNER, CORNERS etc.
returnellipseMode
void bezierDetail(int n)
Change number of steps bezier curve is interpolated.
parameter
description
n
The higher this number, the smoother the Bezier curve.
void hatchMode(int mode)
Change hatching pattern
parameter
description
mode
This can be one of: PARALLEL, CROSS, CONCENTRIC, SPIRAL, PERLIN, VECFIELD, DRUNK
void strokeMode(int mode)
Change outline drawing method
parameter
description
mode
This can be either PERPENDICULAR or TANGENT
void strokeMode(int mode, int tanMode)
Change outline drawing method
parameter
description
mode
This can be either PERPENDICULAR or TANGENT
tanMode
This can be one of COUNT (stroke weight used as line count), WEIGHT (honour stroke weight setting over spacing) or SPACING (honour spacing over stroke weight)
void strokeLocation(float x)
Set the position of the stroke, relative to the shape's edge
parameter
description
x
Float between -1.0 (inside) and 1.0 (outside). 0.0 is centered.
void strokeLocation(int mode)
Set the position of the stroke, relative to the shape's edge
parameter
description
x
This can be one of CENTER, INSIDE, or OUTSIDE
void hatchAngle(float ang)
Change angle of parallel hatch lines
parameter
description
ang
the angle from +x in radians
returnhatchAngleDeg
returnhatchAngles
void hatchAngles(float ang1, float ang2)
Change angles of parallel and cross hatching lines
parameter
description
ang1
the angle from +x in radians (for parallel hatches and the first direction of cross hatching)
ang2
the angle from +x in radians (for second direction of cross hatching)
returnhatchAngle
returnhatchAnglesDeg
void hatchAngleDeg(float ang)
Change angle of parallel hatch lines
parameter
description
ang
the angle from +x in degrees
returnhatchAngle
returnhatchAnglesDeg
void hatchAnglesDeg(float ang1, float ang2)
Change angles of parallel and cross hatching lines
parameter
description
ang1
the angle from +x in degrees (for parallel hatches and the first direction of cross hatching)
ang2
the angle from +x in degrees (for second direction of cross hatching)
returnhatchAngles
returnhatchAngleDeg
void strokeAngle(float ang)
Sets the orientation of the stitches within a stroke
parameter
description
ang
the angle (in radians)
void strokeAngleDeg(float ang)
Sets the orientation of the stitches within a stroke
parameter
description
ang
the angle (in degrees)
void hatchSpacing(float d)
Changes the spacing between hatching lines: a.k.a sparsity or inverse-density
parameter
description
d
the spacing in pixels
returnstrokeSpacing
void strokeSpacing(float d)
Changes the spacing between stroke lines: a.k.a sparsity or inverse-density
parameter
description
d
the spacing in pixels
returnhatchSpacing
void hatchScale(float s)
Changes the scaling for perlin noise hatching
parameter
description
s
the scale
void hatchBackend(int mode)
Switches the algorithms used to compute the drawing
parameter
description
mode
one of ADAPTIVE (use most appropriate method for each situation according to Lingdong) FORCE_VECTOR (uses vector math whenever possible) FORCE_RASTER (first render shapes as raster and re-extract the structures, generally more robust)
void setVecField(VectorField vf)
Set the vector field used for vector field hatching
parameter
description
vf
a vector field defination
void stitchLength(float x)
Set the desirable stitch length. Stitches will try their best to be around this length, but actual length will vary slightly for best result
parameter
description
x
the desirable stitch length
returnminSitchLength
returnsetStitch
void minStitchLength(float x)
Set the minimum stitch length. Drawings with higher precision than this will be resampled down to have at least this stitch length
parameter
description
x
the minimum stitch length
returnstichLength
returnsetStitch
void setStitch(float msl, float sl, float rn)
Set stitch properties
parameter
description
msl
minimum stitch length
sl
desirable stitch length
rn
resample noise
void setRenderOrder(int mode)
Set render order: render strokes over fill, or other way around?
parameter
description
mode
This can either be STROKE_OVER_FILL or FILL_OVER_STROKE
void toggleResample(boolean b)
Turn resampling on and off. For embroidery machines, you might want it; for plotters you probably won't need it.
parameter
description
b
true for on, false for off
void setSpiralDirection(int mode)
Sets whether SPIRAL hatching proceeds clockwise or counterclockwise
parameter
description
mode
This can be CLOCKWISE or COUNTERCLOCKWISE. CW and CCW are also permissible.
void setOutOfBoundsHandler(int mode)
Sets the file exporting behavior if a stitch was placed out of bounds.
parameter
description
mode
This can be one of WARN, CROP, IGNORE, ASK, or ABORT
void satinMode(int mode)
Sets how the SATIN hatching mode operates.
parameter
description
mode
This can be one of ZIGZAG, SIGSAG, or BOUSTROPHEDON
PVector centerpoint(ArrayList< PVector > poly)
Averages a bunch of points
parameter
description
poly
a bunch of points
returna vector holding the average value
PVector centerpoint(ArrayList< ArrayList< PVector >> poly, int whatever)
Averages a bunch of bunches of points
parameter
description
poly
a bunch of bunches of points
whatever
literally pass in whatever. It is necessary because of type erasure in Java, which basically means Java cannot tell the difference between List<T> and List<List<T>> in arguments, so a difference in number of arguments is required for overloading to work
Check if a point is inside a polygon. Dumbed down version of pointinPolygon(3) where I pick the number of trials for you
parameter
description
p
the point in question
poly
the polygon
returntrue means inside, false means outside
PVector randomPointInPolygon(ArrayList< PVector > poly, int trials)
Generate a random point that is inside a polygon
parameter
description
poly
the polygon
trials
number of times we try before giving up
returneither null or a point inside the polygon. If it is null, it either means the polygon has zero or almost zero area, or that the number of trials specified is not large enough to find one
Generate a random point that is inside a polygon Dumbed down version of randomPointInPolygon(2) where I pick the number of trials for you
parameter
description
poly
the polygon
returneither null or a point inside the polygon. If it is null, it either means the polygon has zero or almost zero area, or that the default number of trials is not large enough to find one
void pushPolyline(ArrayList< PVector > poly, int color, float resampleRandomizeOffset)
Add a polyline to the global array of all polylines drawn Applying transformation matrices and resampling All shape drawing routines go through this function for finalization
parameter
description
poly
a polyline
color
the color of the polyline (0xRRGGBB)
resampleRandomOffset
whether to add a random offset during resample step to prevent alignment patterns
void pushPolyline(ArrayList< PVector > poly, int color)
Simplified version for pushPolyline(3) where resampleRandomizeOffset is set to false
Offset a polygon (making it slightly smaller fitting in the original polygon, or slightly bigger wrapping the original polygon)
parameter
description
poly
the polygon
d
the amount of offset. Use negative value for insetting
returna list of polygons. When the given polygon is big at both ends and small in the middle, the inset might break into multiple polygons
int rotatePolygonToMatch(ArrayList< PVector > poly0, ArrayList< PVector > poly1)
When the general shapes of two polygons are similar, this function finds the index offset of vertices for the first polygon so that the vertices best match those of the second polygon with one-to-one correspondence. The number of vertices needs to be the same for the polygons
parameter
description
poly0
the first polygon
poly1
the second polygon
returnthe optimal index offset
ArrayList<ArrayList<PVector> > strokePolygonTangent(ArrayList< PVector > poly, int n, float d)
Draw stroke (outline) for a polygon using the TANGENT style (using vector math)
parameter
description
poly
the polygon
n
number of strokes
d
spacing between the strokes
returnan array of polylines
ArrayList<ArrayList<PVector> > strokePolyTangentRaster(ArrayList< ArrayList< PVector >> polys, int n, float d, int cap, int join, boolean close)
Draw stroke (outline) for (a) poly(gon/line)(s) using the TANGENT style (using raster algorithms)
parameter
description
polys
a set of polyline/polygons, those inside another and have a backward winding will be considered holes
n
number of strokes
d
spacing between the strokes
cap
stroke cap, one of the Processing stroke caps, e.g. ROUND
join
stroke join, one of the Processing stroke joins, e.g. MITER
close
whether the polyline is considered as closed (polygon) or open (polyline)
draws stroke (outline) for (a) poly(gon/line)(s) using current global settings by the user. returns nothing, because it draws to the design directly.
parameter
description
polys
a set of polyline/polygons, those inside another and have a backward winding will be considered holes
close
whether the polyline is considered as closed (polygon) or open (polyline)
ArrayList<ArrayList<PVector> > hatchInset(ArrayList< PVector > poly, float d, int maxIter)
hatch a polygon with CONCENTRIC (a.k.a inset) mode (using vector math). a simplified version of hatchInset(4) where orientation of polygon is always checked
parameter
description
poly
the polygon
d
hatch spacing
maxIter
maximum number of iterations to do inset. The larger the polygon and smaller the spacing, the more iterations is required
minimum length of each segment, segment shorter than this will be downsampled
maxLen
maximum length of each segment (not counting the randomization added on top, specified by randomize)
randomize
amount of randomization in stitch length to avoid alignment patterns. 0 for none
randomizeOffset
amount of randomization to add to the offset of the first stitch in every polyline. 0 for none
returnthe resampled polyline
ArrayList<PVector> resampleN(ArrayList< PVector > poly, int n)
Resample a polyline to make it have N vertices. Can be an upsample or a downsample. Each resultant segment will be the same length, +/- floating point percision errors
parameter
description
poly
the polyline
n
the desired number of vertices
returnthe resampled polyline
ArrayList<PVector> resampleNKeepVertices(ArrayList< PVector > poly, int n)
Resample a polyline to make it have N vertices, while keeping important turning points. Can be an upsample or a downsample. Each resultant segment have approximately same length, but compromising to the preserving of corners
Resample a set of (parallel) polylines by intersecting them with another bunch of parallel lines and using the intersections to break them up. Useful for parallel hatching.
parameter
description
polys
the polylines
angle
the angle of the original polylines
spacing
the spacing of the original polylines
len
the desired length of each segment after resampling
returnthe resampled polylines
void hatchRaster(PImage im, float x, float y)
Hatch a raster image with global user settings. Returns nothing because the result is directly pushed to the design.
parameter
description
im
a processing image, PGraphics also qualify
x
x coordinate of upper left corner to start drawing
y
y coordinate of upper left corner to start drawing
void hatchRaster(PImage im)
Hatch a raster image with global user settings. Returns nothing because the result is directly pushed to the design. Simplified version of hatchRaster(3), draws at 0,0
parameter
description
im
a processing image, PGraphics also qualify
void ellipse(float a, float b, float c, float d)
Draw a ellipse
parameter
description
a
the first parameter, the meaning of which depends on ellipseMode
b
the second parameter, the meaning of which depends on ellipseMode
c
the third parameter, the meaning of which depends on ellipseMode
d
the fourth parameter, the meaning of which depends on ellipseMode
void rect(float a, float b, float c, float d)
Draw a rectangle
parameter
description
a
the first parameter, the meaning of which depends on rectMode
b
the second parameter, the meaning of which depends on rectMode
c
the third parameter, the meaning of which depends on rectMode
d
the fourth parameter, the meaning of which depends on rectMode
Add a quintic bezier vertex to the current polygon/polyline. This must be preceded by beginShape() and at least a vertex()
parameter
description
x1
x coordinate of first control point
y1
y coordinate of first control point
x2
x coordinate of second control point
y2
y coordinate of second control point
x3
x coordinate of third control point
y3
y coordinate of third control point
x4
x coordinate of fourth control point
y4
y coordinate of fourth control point
x5
x coordinate of the end point
y5
y coordinate of the end point
void highBezierVertex(ArrayList< PVector > poly)
Add a higher-order bezier vertex to the current polygon/polyline. This must be preceded by beginShape() and at least a vertex()
parameter
description
poly
control points and end point
void endShape(boolean close)
End drawing a polygon. at this moment the polygon will be actually drawn to the design
parameter
description
close
whether or not to close the polyline (forming polygon)
void endShape()
Alias for endShape(bool) that does not close the shape
parameter
description
void endShape(int close)
Alias for endShape(bool) that closes the shape
parameter
description
close
pass anything, but use CLOSE for readability
void beginContour()
Begin a contour within the current polygon, if this contour has negative winding and is inside the current polygon or another contour defined between beginShape() and endShape() that is not a hole, this will be a hole
parameter
description
void endContour()
Done with adding a contour
parameter
description
void circle(float x, float y, float r)
Draw a circle, a.k.a ellipse with equal radius in each dimension
parameter
description
x
the first parameter, meaning of which depends on ellipseMode
y
the second parameter, meaning of which depends on ellipseMode
r
the third parameter, meaning of which depends on ellipseMode
void pushMatrix()
Save the current state of transformation
parameter
description
void popMatrix()
Restore previous state of transformatino
parameter
description
void translate(float x, float y)
Translate subsequent drawing calls
parameter
description
x
x offset to translate
y
y offset to translate
void rotate(float a)
Rotate subsequent drawing calls
parameter
description
a
angle in radians to rotate
void shearX(float x)
Shear subsequent drawing calls along x-axis
parameter
description
x
shear amount
void shearY(float x)
Shear subsequent drawing calls along y-axis
parameter
description
x
shear amount
void scale(float x)
Scale subsequent drawing calls proportionally
parameter
description
x
multiplier on both axes
void scale(float x, float y)
Scale subsequent drawing calls disproportionally
parameter
description
x
multiplier on x axis
y
multiplier on y axis
void visualize(boolean color, boolean stitches, boolean route, int nStitches)
Visualize the current design on the main Processing canvas
parameter
description
color
whether to visualize color, if false, will use random colors; if stitches argument is true, this will have no effect and black will always be used for visibility
stitches
whether to visualize stitches, i.e. little dots on end of segments
route
whether to visualize the path between polylines that will be taken by embroidery machine/plotter. To be able to not see a mess when enabling this option, try optimize()
void visualize()
Visualize the current design on the main Processing canvas, using default set of options
parameter
description
void beginDraw()
Supposed to initialize something, but as we currently don't need to, this is a NOP
the polygon that is supposed to contain the other one
poly1
the polygon that is supposed to be contained by the other one
returntrue for containment, false for not
float polygonArea(ArrayList< PVector > poly)
Compute area of polygon
parameter
description
poly
the polygon
returnthe area
void optimize(int trials, int maxIter)
Run TSP on polylines in the current design to optimize for connective path length
parameter
description
trials
number of trials. the more times you try, the higher chance you'll get a better result
maxIter
maximum number of iterations to run 2-Opt.
void optimize()
Simplified version of optimize(2) where the trial and maxIter is picked for you
parameter
description
void beginOptimize(int reorderColor, int trials, int maxIter)
Begin a block of stitch order optimization (TSP solver), to be paired with endOptimize()
parameter
description
reorderColor
number of seconds to try to reorder color to reduce number of color changes without modifying the final look of the design, 0 means no color reordering
trials
number of trials to run the TSP
maxIter
number of iterations for each trial of TSP
void beginOptimize()
Same as beginOptimize(3) with default parameters
parameter
description
void endOptimize()
Close a beginOptimize() block.
parameter
description
void textAlign(int align)
Change horizontal alignment of text
parameter
description
align
alignment mode, one of LEFT, CETER, RIGHT
void textAlign(int halign, int valign)
Change horizontal and vertical alignment of text
parameter
description
halign
horizontal alignment mode, one of LEFT, CETER, RIGHT
valign
vertical alignment mode, one of TOP, CENTER, BASELINE, BOTTOM
void textSize(float size)
Change size of text
parameter
description
size
the desired size of text
void textFont(int[] font)
Change font of text. Notice this function is overloaded with one version for PFont and one for hershey font, with identical API This one is for the hershey font
parameter
description
font
the desired hershey font
void textFont(PFont font)
Change font of text. Notice this function is overloaded with one version for PFont and one for hershey font, with identical API This one is for PFont
parameter
description
font
the desired PFont
void text(String str, float x, float y)
Draw some text
parameter
description
str
the string containing the text to be drawn
x
x coordinate, meaning of which depends on textAlign
y
y coordinate, meaning of which depends on textAlign
Intersect two segments in 3D, returns lerp params instead of actual points, because the latter can cheaply be derived from the former; more expensive the other way around. Also works for 2D.
parameter
description
p0
first endpoint of first segment
p1
second endpoint of first segment
q0
first endpoint of second segment
q1
second endpoint of second segment
returnvec where vec.x is the lerp param for first segment, and vec.y is the lerp param for the second segment
Draw an ellipse using global settings. The unambigous backend for user-facing ellipse(), the ambigous one which can be affected by ellipseMode(). Returns nothing because the result is directly pushed to the design.
parameter
description
cx
the x coordinate of the center
cy
the y coordinate of the center
rx
the radius in the x axis
ry
the radius in the y axis
void _rect(float x, float y, float w, float h)
Draw a rectangle using global settings. The unambigous backend for user-facing rect(), the ambigous one which can be affected by rectMode(). Returns nothing because the result is directly pushed to the design.
parameter
description
x
left
y
top
w
width
h
height
float calcAxisAngleForParallel(float ang)
Hatch a polygon with global user settings (using vector math). Returns nothing because the result is directly pushed to the design.