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();
}

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.

Parameters:
NameTypeDescription
filenameString

Output filename with extension

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

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');
}

mmToPixel(mm, dpiopt) → {Number}

Converts millimeters to pixels.

Parameters:
NameTypeAttributesDefaultDescription
mmNumber

Millimeters

dpiNumber<optional>
96

Dots per inch

Returns:

Pixels

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

pixelToMm(pixels, dpiopt) → {Number}

Converts pixels to millimeters.

Parameters:
NameTypeAttributesDefaultDescription
pixelsNumber

Pixels

dpiNumber<optional>
96

Dots per inch

Returns:

Millimeters

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

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

spacingnumber<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
}

setStrokeMode(mode)

Sets the stroke mode for embroidery stitches.

Parameters:
NameTypeDescription
modestring

The stroke mode to use ('zigzag', 'lines', 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);
}