Methods

beginRecord(p5Instance)

Begins recording embroidery data.

Parameters:
NameTypeDescription
p5Instancep5

The p5.js sketch instance

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns here
  endRecord();
}

embroideryOutline(offsetDistance, threadIndexopt, outlineTypeopt, cornerRadiusopt)

Adds an outline around the embroidery at a specified offset distance.

Parameters:
NameTypeAttributesDefaultDescription
offsetDistancenumber

Distance in mm to offset the outline from the embroidery

threadIndexnumber<optional>

Thread index to add the outline to (defaults to current stroke thread)

outlineTypestring<optional>
'convex'

Type of outline ('convex', 'bounding')

cornerRadiusnumber<optional>
0

Corner radius in mm for bounding box outlines (only applies to 'bounding' type)

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  circle(50, 50, 20);
  embroideryOutline(5); // Add 5mm outline around the embroidery
  embroideryOutline(10, 1, "bounding", 5); // Add 10mm bounding box outline with 5mm rounded corners
  endRecord();
}

embroideryOutlineFromPath(stitchDataArray, offsetDistance, threadIndexopt, outlineTypeopt, applyTransformopt, cornerRadiusopt) → {Array}

Creates an outline around specified stitch data at a specified offset distance.

Parameters:
NameTypeAttributesDefaultDescription
stitchDataArrayArray

Array of stitch data objects (each with x, y coordinates)

offsetDistancenumber

Distance in mm to offset the outline from the path

threadIndexnumber<optional>

Thread index to add the outline to (defaults to current stroke thread)

outlineTypestring<optional>
'convex'

Type of outline ('convex', 'bounding', 'scale')

applyTransformboolean<optional>
true

Whether to apply current transformation to the outline

cornerRadiusnumber<optional>
0

Corner radius in mm for bounding box outlines (only applies to 'bounding' type)

Returns:

Array of outline points {x, y}

Type: 
Array
Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Create some stitch data
  let pathData = [{x: 50, y: 50}, {x: 100, y: 50}, {x: 100, y: 100}];
  let outlinePoints = embroideryOutlineFromPath(pathData, 5); // Add 5mm outline
  let roundedOutline = embroideryOutlineFromPath(pathData, 8, 0, "bounding", true, 3); // 8mm bounding box with 3mm corners
  // Use the outline points for further processing
  endRecord();
}

endRecord()

Ends recording and prepares for export.

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  endRecord();
}

exportDST(filenameopt)

Exports the recorded embroidery data as a DST file.

Parameters:
NameTypeAttributesDefaultDescription
filenameString<optional>
'embroideryPattern.dst'

Output filename

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  endRecord();
  exportDST('pattern.dst');
}

exportEmbroidery(filename)

Exports the recorded embroidery data as a file. Supported formats: DST (.dst), SVG (.svg), PNG (.png), JSON (.json)

Parameters:
NameTypeDescription
filenameString

Output filename with extension (dst, svg, png, or json)

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns here
  circle(50, 50, 20);
  line(10, 10, 90, 90);
  endRecord();
  exportEmbroidery('pattern.dst');  // or .svg, .png, .json
}

exportGcode(filename)

Exports the recorded embroidery data as a G-code file.

Parameters:
NameTypeDescription
filenameString

Output filename

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  endRecord();
  exportGcode('pattern.gcode');
}

exportJSON(filenameopt, optionsopt)

Exports the recorded embroidery data as a JSON file with detailed stitch information organized by thread ID.

Parameters:
NameTypeAttributesDefaultDescription
filenamestring<optional>
'embroidery-pattern.json'

Output filename

optionsObject<optional>
{}

Export options

Properties
NameTypeAttributesDefaultDescription
includeBoundsboolean<optional>
true

Include pattern bounds information

includeMetadataboolean<optional>
true

Include metadata and statistics

precisionnumber<optional>
2

Decimal precision for coordinates

compactOutputboolean<optional>
false

Export in compact JSON format

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  circle(50, 50, 20);
  line(10, 10, 90, 90);
  endRecord();
  exportJSON('my-pattern.json', {
    precision: 3,
    includeMetadata: true
  });
}

exportOutline(threadIndex, offsetDistance, filename, outlineTypeopt) → {Promise.<boolean>}

Creates and exports an outline from a specified thread index with the given offset.

Parameters:
NameTypeAttributesDefaultDescription
threadIndexnumber

Index of the thread to create outline from

offsetDistancenumber

Distance in mm to offset the outline

filenamestring

Output filename with extension (supports .png, .svg, .gcode, .dst)

outlineTypestring<optional>
'convex'

Type of outline ('convex', 'bounding', 'scale')

Returns:

Promise that resolves to true if export was successful

Type: 
Promise.<boolean>
Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  circle(50, 50, 20);
  endRecord();

  // Export outline of thread 0 with 5mm offset as SVG
  exportOutline(0, 5, "outline.svg");

  // Export outline with bounding box type as G-code
  exportOutline(0, 10, "cut-outline.gcode", "bounding");
}

exportPNG(filename, optionsopt)

Exports embroidery pattern as PNG for printing templates.

Parameters:
NameTypeAttributesDefaultDescription
filenamestring

Output filename

optionsObject<optional>
{}

Export options

Properties
NameTypeAttributesDefaultDescription
paperSizestring<optional>
'A4'

Paper size (A4, A3, A2, A1)

dpinumber<optional>
300

Print resolution in DPI

hoopSizeObject<optional>

Hoop size in mm {width, height}

marginsObject<optional>

Margins in mm {top, right, bottom, left}

showGuidesboolean<optional>
true

Show hoop guides and center marks

lifeSizeboolean<optional>
true

Export at life-size scale

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns
  circle(50, 50, 20);
  endRecord();
  exportPNG('my-pattern.png', {
    paperSize: 'A4',
    hoopSize: {width: 100, height: 100}
  });
}

exportSVG(filename, optionsopt)

Exports embroidery pattern as SVG for printing templates.

Parameters:
NameTypeAttributesDefaultDescription
filenamestring

Output filename

optionsObject<optional>
{}

Export options

Properties
NameTypeAttributesDefaultDescription
paperSizestring<optional>
'A4'

Paper size (A4, A3, A2, A1)

dpinumber<optional>
300

Print resolution in DPI

hoopSizeObject<optional>

Hoop size in mm {width, height}

marginsObject<optional>

Margins in mm {top, right, bottom, left}

showGuidesboolean<optional>
true

Show hoop guides and center marks

centerPatternboolean<optional>
false

Center pattern in hoop (false = use original coordinates)

lifeSizeboolean<optional>
true

Export at life-size scale

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  // Draw embroidery patterns at specific coordinates
  translate(100, 25); // Position at 100mm, 25mm
  circle(0, 0, 20);
  endRecord();

  // Export at original coordinates (recommended)
  exportSVG('my-pattern.svg', {
    paperSize: 'A4',
    hoopSize: {width: 200, height: 200},
    centerPattern: false // Preserves your coordinate positioning
  });
}

exportSVGFromPath(threadIndex, filename, optionsopt) → {Promise.<boolean>}

Exports only the specified thread path as SVG without creating an outline.

Parameters:
NameTypeAttributesDefaultDescription
threadIndexnumber

Index of the thread to export

filenamestring

Output filename with .svg extension

optionsObject<optional>
{}

Export options

Deprecated
  • Use exportSVG() with threads option instead
Returns:

Promise that resolves to true if export was successful

Type: 
Promise.<boolean>
Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);

  // Thread 0 - Red circle
  stroke(255, 0, 0);
  circle(50, 50, 20);

  // Thread 1 - Blue square
  stroke(0, 0, 255);
  rect(30, 30, 40, 40);

  endRecord();

  // Old way (deprecated):
  exportSVGFromPath(0, "thread0-path.svg");

  // New way (recommended):
  exportSVG("thread0-path.svg", { threads: [0] });
}

mm2px(mm, dpi) → {Number}

Alias for mmToPixel - converts millimeters to pixels.

Parameters:
NameTypeDescription
mmNumber

Millimeters

dpiNumber

Dots per inch (default: 96)

Returns:

Pixels

Type: 
Number

mmToPixel(mm, dpi) → {Number}

Converts millimeters to pixels.

Parameters:
NameTypeDescription
mmNumber

Millimeters

dpiNumber

Dots per inch (default: 96)

Returns:

Pixels

Type: 
Number
Example
function setup() {
  let pixels = mmToPixel(10); // Convert 10mm to pixels
  if(_DEBUG) console.log(pixels);
}

pixelToMm(pixels, dpi) → {Number}

Converts pixels to millimeters.

Parameters:
NameTypeDescription
pixelsNumber

Pixels

dpiNumber

Dots per inch (default: 96)

Returns:

Millimeters

Type: 
Number
Example
function setup() {
  let mm = pixelToMm(100); // Convert 100 pixels to mm
  if(_DEBUG) console.log(mm);
}

px2mm(pixels, dpi) → {Number}

Alias for pixelToMm - converts pixels to millimeters.

Parameters:
NameTypeDescription
pixelsNumber

Pixels

dpiNumber

Dots per inch (default: 96)

Returns:

Millimeters

Type: 
Number

setDrawMode(mode)

Sets the draw mode for embroidery.

Parameters:
NameTypeDescription
modeString

The draw mode to set ('stitch', 'p5', 'realistic')

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  setDrawMode('stitch'); // Show stitch points and lines
  // Draw embroidery patterns
}

setFillMode(mode)

Sets the fill mode for embroidery fills.

Parameters:
NameTypeDescription
modestring

The fill mode to use ('tatami', 'satin', or 'spiral')

setFillSettings(settings)

Sets the fill settings for embroidery.

Parameters:
NameTypeDescription
settingsObject

Fill settings object

Properties
NameTypeAttributesDescription
stitchLengthnumber<optional>

Length of each stitch in mm

stitchWidthnumber<optional>

Width of each stitch in mm

minStitchLengthnumber<optional>

Minimum stitch length in mm

resampleNoisenumber<optional>

Amount of random variation (0-1)

anglenumber<optional>

Fill angle in degrees

rowSpacingnumber<optional>

Space between rows in mm

tieDistancenumber<optional>

Distance between tie-down stitches in mm

alternateAngleboolean<optional>

Whether to alternate angles between shapes

setFillSettings(settings)

Sets the fill settings for embroidery.

Parameters:
NameTypeDescription
settingsObject

The settings for the fill

setStitch(minLength, desiredLength, noise)

Sets the stitch parameters for embroidery.

Parameters:
NameTypeDescription
minLengthNumber

Minimum stitch length in millimeters

desiredLengthNumber

Desired stitch length in millimeters

noiseNumber

Amount of random variation in stitch length (0-1)

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  setStitch(1, 3, 0.2); // min 1mm, desired 3mm, 20% noise
  // Draw embroidery patterns
}

setStitchInterpolate(enabled)

Sets whether zigzag stitches should interpolate smoothly around corners.

Parameters:
NameTypeDescription
enabledboolean

false = follow path normals with sharp corners (default), true = interpolate for smooth corners

setStitchWidth(width)

Sets the stitch width parameters for embroidery.

Parameters:
NameTypeDescription
widthNumber

Width of the stitch in millimeters

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  setStitchWidth(0.2); // width 0.2mm
  // Draw embroidery patterns
}

setStrokeEntryExit(entry, exit)

Sets the stroke chirality for embroidery stitches.

Parameters:
NameTypeDescription
entrystring

The entry direction to use ('right' or 'left')

exitstring

The exit direction to use ('right' or 'left')

setStrokeJoin(join)

Sets the stroke join mode for embroidery stitches.

Parameters:
NameTypeDescription
joinstring

The stroke join mode to use ('round', 'miter', or 'bevel')

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  setStrokeJoin('miter');
  beginShape();
  vertex(20, 20);
  vertex(50, 20);
  vertex(50, 50);
  endShape();
}

setStrokeMode(mode)

Sets the stroke mode for embroidery stitches.

Parameters:
NameTypeDescription
modestring

The stroke mode to use ('zigzag', 'parallel', or 'sashiko')

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  setStrokeMode('zigzag');
  line(10, 10, 50, 50); // Will use zigzag stitch pattern
}

setStrokeSettings(settings)

Sets the stroke settings for embroidery.

Parameters:
NameTypeDescription
settingsObject

The settings for the stroke

trimThread()

Inserts a thread trim command at the current position.

Example
function setup() {
  createCanvas(400, 400);
  beginRecord(this);
  line(10, 10, 50, 50);
  trimThread(); // Cut thread at current position
  line(60, 60, 100, 100);
}