Digital Embroidery

We have a Brother Innov-is V3 Embroidery Machine which can be programmed to create custom embroidered pieces using your own Processing sketch or using the Brother software.

Using the Brother Innov-is V3 Embroidery Machine

To use this machine, you must have had an induction from one of the technical staff. This guide is to serve as a resource for students who have already had this induction, as a reminder of setup steps and as a troubleshooting guide.

Overview

The Brother Innovis V3 is a top-end domestic embroidery machine that can be used to produce high-quality digital embroidery on a range of fabrics.

A photograph of the Brother Innovis V3 machine, showing the mounted embroidery hoop.

Embroidery machines work by moving a piece of fabric (fixed within a hoop) in the x-y direction, beneath a needle that stitches by moving up and down. In this sense, they have a lot in common with many other 2-axis CAD machines (like laser cutters, routers, plotters), though because of the paticular qualities of working with stitches as opposed to straight toolpaths, embroidery software weirdness, and working with different fabrics, there's some practice involved in getting consistent results.

This guide is a condensed overview of the machine operation -- if you'd like a more detailed reference, see the Brother Innovis V3 User Manual.

Producing embroidery files

In order to embroider your design, you must first create a file in the .PES format (there are other embroidery file formats, but they are not typically compatible with Brother machines). These are then loaded onto the machine via memory stick. At CCI, there are 2 main ways that this can be done:

Both approaches have their advantages and disadvantages depending on the kind of design you want to make. In general, PEmbroider gives you a huge amount of control over how the design is stitched, whereas PE Design auto-generates stitches for you, allowing you to choose from a few different presets, and has a lot of features. As such, the learning curve with PEmbroider is a bit steeper, and generally requires a bit more tinkering to achieve a result, but is programmable, so can make generative designs, and can produce things that can't be made using PE Design.

As PEMBroider is just an extension of Processing, it can be run on your computer. PE Design is a piece of proprietary Windows software, for which we have one license, so it must be used on the dedicated Windows machine next to the embroidery machine. There is a Windows-only trial version available here.

Machine Setup

Changing the top thread

While this machine is threaded using a similar approach to most domestic sewing machines, it has some specific features that are a little less common. This is the thread that will be on the top side of your fabric, and must be machine embroidery thread (for how to tell, see 'my top thread keeps breaking' in troubleshooting).

The diagram below shows how the top thread should look when properly threaded through the machine. For a full step-by-step instruction, the guide in the manual is very thorough (page 38), though if you are unsure then please ask for a refresher.

A diagram showing the correct position of the top thread in the machine, going from right to left

The final step of threading the top thread is shown below -- pull the thread through the thread cutter, and then press the 'auto thread' button for the machine to automatically thread the needle. (it's also possible to do this by hand but much less efficient).

A diagram showing someone pulling the thread into the thread cutter on the right of the machine A diagram showing someone pressing the 'needle threading' button, which is located a couple of inches to the right of the 3 middle buttons at the top of the machine

Changing the bobbin thread

The bobbin thread is what binds the top thread to the fabric, and sits on what's know as the 'wrong side'. Typically, this thread is either black or white -- if you are sewing with dark-coloured thread, you might want to consider using black bobbin thread, but otherwise white thread is fine for most purposes.

This part can be slow the first time you do it, but precision is important -- if your bobbin is not set up properly you will spend a lot longer trying to figure out why your design hasn't come out right!

For a full step-by-step instruction, the guide in the manual is very thorough (page 36, or 31 if you want to wind the bobbin on the machine), though if you are unsure then please ask for a refresher.

Before you start:

  1. check you have the correct kind of bobbin (it's approx 11.5mm high, and should have part code SA156 somewhere)
  2. check that the bobbin thread is tightly wound. loose thread will ruin your tension later on
  3. check that the bobbin thread is actually bobbin thread (compare to the spools of bobbin thread on the desk)

Start by sliding the bobbin cover latch to the right, then gently lifting the bobbin from the machine.

a diagram showing a finger sliding the latch next to the bobbin cover to the right

Replace the bobbin, making sure that the direction the thread unwinds in the correct direction (clockwise!). As shown in the diagram below, pull out and around the thread cutter.

a diagram showing someone loading the bobbin in so that the thread unwinds in a clockwise direction, then pulling the thread around the thread cutter.

Be sure to replace the bobbin cover -- it should click when pressed in.

Tip: When about to embroider a large design, it's worth checking that there's a fair amount of thread left on the bobbin, to avoid having to change it midway (it's not an issue, just annoying).

IMPORTANT: make sure the bobbin thread is the correct way round (it will be the source of endless mystery issues if not). It has a little picture of the correct thread direction on the bobbin case,

Hoop Setup

In order to embroider fabric, it must be stretched taut in an embroidery hoop, which is tightened using one or two adjustable screws, then mounted on the arm of the machine. It is this arm that moves the fabric relative to the needle. This is low-key one of the most crucial bits of getting a design to work, and if you're having issues with distortion it's probably going to be here.

There are currently 3 hoop sizes available to use at CCI. In general, try and use the smallest possible hoop that will fit your design -- the larger the hoop, the less supported the fabric is, and the more likely you are to encounter distortion. This is particularly relevant if you are using a thin or stretchy fabric. The largest hoop is not a challenge!!

a comparison chart of hoops. The largest is 30cmx18cm, the middle is 18cmx13cm, the smallest is 10cmx10cm

If you don't know what hoops you can use, the machine will tell you -- just look for the hoop icon in the top while browsing designs. Designs too big for the hoop will be greyed out and you will not be able to stitch with them. The machine knows what hoop you have mounted and will adjust this accordingly.

It is strongly recommended that you use iron-on fabric stabiliser when embroidering -- it will keep the fabric stiffly fixed in one place, and is especially important when working with delicate fabrics. Iron this onto the fabric before putting it into the machine.

a diagram showing 2 hands pulling fabric taut at the sides of a tightened embroidery hoop

Tip: If you are using a stretchy or delicate fabric, take care not to over-stretch when putting the fabric into the hoop (or the design will pucker when you come to remove the fabric from the hoop). I would strongly suggest using the stock canvas we have at the CCI to test designs, especially when you are learning to use the machine.

You can also use the iron on stabiliser to 'float' very small pieces of fabric, ribbons or corners.

a diagram showing a small square of fabric that has been affixed to a larger piece of stabiliser, with the stabiliser fixed tight within a large hoop

Alignment

Aligning your fabric properly is really important, and the hoops all come with special alignment sheets that can help you line things up. This is by far the most annoying part of the whole process, but it's worth getting right.

IMPORTANT: be gentle when loading the hoop in and out of the machine. This is the part of the machine that is easiest to break through careless handling. Always make sure the hoop lock is off when pulling it out, and pull straight, not diagonally. Also make sure you put the bobbin in first.

Embroidering designs

Before you start:

a diagram showing the needle positioning menu

While embroidering:

If the top thread breaks during embroidery

This is not uncommon, and can cause some stitches to be skipped. Luckily, it's also easy to resolve. If this happens multiple times in the same design, however, there might be something wrong (see 'my top thread keeps breaking' in the troubleshooting section).

Enter the stitch counting menu (indicated below), then modify the stitch number using the needle icons. The machine's needle will move as you adjust, allowing you to see what's going on.

a picture of the machine interface, showing the location of the stitch counter menu in the middle row, second from bottom a photo of the open stitch counter menu, showing the selected options that will reduce the number stitch that the machine is currently on

For most cases (unless a lot of stitches were skipped), I'd recommend going back 10 at a time, then using +-1 stitch to line up the needle with the last proper stitches (go a couple in to ensure they can't come loose). The handwheel can be used to lower the needle toward the fabric and check alignment.

Skipping colours

To skip out (or, converesely, to redo) an entire coloured section, you can use the same menu used above to recover stitches, but press the button with the spool icon instead of the needle icon. This means 'go on to the next thread colour'. This can be a really quick way of experimenting with multiple versions of a design, with optional parts coded by colour, without needing to produce multiple separate files.

coming soon: using conductive thread

This part is yet to come as we need to do some tests! To do this, we will get hold of some conductive embroidery thread to do this -- the generic conductive thread is too thick to use on the machine.

Troubleshooting

My design is distorted/puckered

This issue is almost certainly to do with hooping. If you're trying larger and more complex designs, I would recommend watching this hooping tutorial which gives a lot of detail on proper technique.

Before you change anything in your design, check:

  1. is the fabric properly stretched on the hoop
  2. have you ironed on stabiliser to the back of the fabric (and is it properly bonded).

If the answer to both these questions is yes, this is likely not down to a single issue, and instead part of a set of different trade-offs:

Tip: Before you tear up your design, try ironing it: sometimes even pretty bumpy designs look a lot better after a bit of ironing.

a triangle with 3 corners. The top corner is labelled 'large design' the right is labelled 'thin fabric' and the left is labelled 'dense fill'. In the center it reads 'choose 2'

The bobbin thread is coming through the top of the fabric

This is a really common and very annoying issue, and may have a few root causes. A very common mistake when starting to use the machine is putting in the bobbin thread the wrong way round: if you have anything more than 1mm thread showing on top I would suggest addressing that first.

The machine says my design will take over an hour to stitch

In my experience, the machine is rarely lying here, and what you probably have is a large, complex design with a lot of filled areas, that will genuinely take that long. This kind of design will also use a lot of thread. If this is your first or second time using the machine, or you don't have 2 hours, I'd advise trying out a different design for now.

The design is blank in the machine's selection menu

This is a bug with patterns made using PEmbroider, and only applies to the first menu -> if you click into it, the design should show up. You can use the machine to save a copy of the file, which will be recognisable: I would recommend either doing this or giving your files distinctive names to prevent confusion.

The top thread keeps breaking

Firstly, check that you are using the correct thread (you cannot use this machine with regular sewing thread). All of the CCI embroidery threads are Brother brand, which will appear on the top of the spool.

If you have brought your own embroidery thread, that does not necessarily mean that it will work well on this machine. Check first that the thread is suitable for machine embroidery. Cheap embroidery threads (even if they are the correct type) can sometimes be poor quality and break easily on the machine. To test this, if you can fairly easily break the thread with your hands, it's probably too weak to avoid this issue. If you do want to buy your own thread, I would personally recommend Madeira thread (it's a bit more economical than Brother, and they have a great range).

If you are using the CCI Brother thread, then check that the top thread is threaded correctly, either by referring to the manual, or asking one of the technical staff. Check in particular that thread is unwinding in the correct direction, and that the 'notch' on the spool points away from the unwinding direction (or it can get caught).

I broke a needle

Alas. First of all, make sure you remove all the loose bits of needle and put them in the sharps bin. It's also worth checking at this point that the top thread isn't caught on anything, and that the bobbin thread isn't caught/bunched. If you're unsure about this, try to gently remove the hoop and loosen any caught threads.

To replace the needle, you will need a new embroidery needle, and the small, stubby screwdriver, both of which should be in the parts bin near the machine. Press the needle button to move the needle stump all the way up. Using the screwdriver, gently loosen the old needle stump, put it in the sharps bin, then put in a new needle. Make sure:

  1. It is a machine embroidery needle (if you're not sure then ask). For almost all purposes we use 75/11 needles.
  2. You push the needle all the way up
  3. The flat side faces away from you and the screw is properly tightened using the screwdriver

a diagram showing a hand pushing a needle firmly into the socket, while a screwdriver tightens the screw by rotating to the right

The User Manual has more diagrams of this process on page 45.

Once the needle is replaced, re-thread the top thread and bobbin thread before starting again. If you break a needle more than once in quick succession, there is probably an issue with your design.

If you don't feel confident replacing a needle, grab one of us (or if out of hours, leave the hoop in the machine, put a note on it, send us an email and turn the machine off).

Creating Digital Embroidery Designs with PEmbroider

PEmbroider is an open-source library for embroidery design, maintained by CMU's Studio for Creative Enquiry. Designs are created using Processing code, particularly the Processing Drawing API which can be used to generate embroidery designs computationally. PEmbroider is well-documented online -- this tutorial page is here to point you to existing resources, and explain a couple of foibles with the software.

A piece of embroidered textile, decorated with the pembroider logo and small smiling creatures.

Setup

Setup instructions are here. When running an example sketch, if you would like to use the design, make sure that it exports in the .PES file format, as this is the form used by the machine.

In the PEmbroider example files, the file format is always declared in the variable outputFilePath, normally in the setup() section of the code. So, to change this (e.g. in the example file PEmbroider_shape_hatching_experimental), from:

    ...
    E = new PEmbroiderGraphics(this, width, height);
    String outputFilePath = sketchPath("PEmbroider_shapes_hatching_experimental.vp3");
    ...

to:

    ...
    E = new PEmbroiderGraphics(this, width, height);
    String outputFilePath = sketchPath("PEmbroider_shapes_hatching_experimental.pes");
    ...

If you create a file in the wrong format, you can always re-run the code, but it is also possible to convert between different embroidery file formats online here.

Using PEmbroider

The full API for PEmbroider is documented here.

Stitch size and spacing

Because of how Processing generates images, measurements are in pixels, not in mm -- this can make it a bit trickier to compare with other pieces of software.

In my experience, the default stitches used in PEmbroider are very small and very dense, much moreso than the defaults used by Brother software. Partly, this is a matter of taste, however, when using finer or stretchier fabrics, such tight and dense stitches can cause puckering (and these designs also take a lot longer).

This is something that's best to test out yourself and adjust, but I have included the presets I use below as a guide:

PEmbroiderGraphics E;
...

void setup() {
    ...
    E.strokeSpacing(2.0)    // this spaces the stroke (outline) stitches by 2 pixels
    E.hatchSpacing(3.0);    // this spaces hatch (fill) stitches by 3 pixels
    E.setStitch(5, 15, 0.0) // this sets minimum stitch to be 5px
                            // desirable stitch length to be 15px
                            // resample noise to be 0.0
    ...
}

(note: you set both the minimum and desired stitch length, as when embroidering curved shapes not all stitches will be the same length).

Examples

PEmbroider comes with a wide range of examples, that give a good idea of a number of different features of the machine. These are also good things to modify if you want to test out different stitch lengths and densities. Once you have installed PEmbroider, these may be accessed through the Processing examples menu. Many of these have already been stitched on the Brother machine as demos, and can be found behind the machine.

A screenshot that shows how to navigate to the examples folder -> first select examples in the 'file' menu of processing, then navigate to the 'contributed libraries/PEmbroider' subfolder

I've included some additional examples below that make use of some of the affordances of programmatic stitch generation.

Creating pixellated designs

One thing that programs like PEmbroider are particularly well adapted for is designs where the stitches need to be very precisely laid-out. It's much harder to get stitches to do what you want in software like PE Design, where you can control the parameters but not the actual stitch placement.

One such use-case is creating pixellated designs -- below is an example image and code that I have used in the past, that demonstrates how to manipulate stitches on a grid basis.

// PEmbroider script to stitch pixellated images
// author: Agnes Cameron

import processing.embroider.*;
PEmbroiderGraphics E;

void setup() {
  size(1000, 1000); 
  noLoop(); 

  // Load the bitmap image to embroider. 
  // Should consist of white shapes on a black background. 
  PImage myImage = loadImage("ken.gif");

  // Create and configure the PEmbroider object, E
  E = new PEmbroiderGraphics(this, 1000, 1000);
  String outputFilePath = sketchPath("ken.pes");
  E.setPath(outputFilePath); 

  // Initial setup of PEmbroider object.
  E.beginDraw(); 
  E.clear();
  E.fill(0, 0, 0); // start the design at 0
  E.noStroke();

  // Parallel hatch 
  E.setStitch(5, 30, 0); //set the stitch to be the same size as the 'pixels'
  E.hatchMode(PEmbroiderGraphics.PARALLEL); 
  E.hatchAngleDeg(0);   // you want to set this to 0 for a 'pixel' effect -- default is angled
  E.hatchSpacing(3.0);  // this is nice and not overly dense
  E.image(myImage, 0, 0);
  
  // finishes the file and shows
  E.optimize();    
  E.visualize();  // show the file
  E.endDraw();    // write out the embroidery file
}

This code is created to run with a 1000x1000 .gif image, with a 'pixel' size (e.g. white squares) of

To run this code, create a folder called 'data' in the same folder as the processing file, and then save this image as 'ken.gif'. You can test this out with your own images, too.

A black and white pixellated image of the computer engineer Ken Thompson, to be downloaded for use with the script

The output should look something like this:

A screenshot of the embroidery pattern produced from the imahe of ken thompson

Warnings and errors

Stitches are out of bounds

A common warning is this one: it occurs when you have a design that goes right to the edge of the canvas. In my experience, so long as the design looks OK to you, this is normally fine to ignore, but it's worth making sure that the the design looks right before embroidering.

A screenshot of a dialog box that starts with the line "Some stitches are out of bounds!", with an option to 'ignore', as well as options to 'crop' or 'abort'

Designs don't display on the Brother embroidery machine selection menu

This only applies to the selection menu: if you click into the file, the design should show up, and the information the machine gives you about the design's size (and corresponding hoops) should be correct. If this is an issue, you can use the machine to save a copy of the file, which will be recognisable: if you are embroidering multiple designs in one session, I would recommend either doing this or giving your files distinctive names to prevent confusion.

Creating Digital Embroidery Designs with PE Design 11

coming soon :)

Workshop: Generative Embroidery with PEmbroider

This is the written version of an embroidery workshop in the CCI, and can either accompany the live workshop or be worked through by itself. As we go through the exercises, it's a good idea to have the PEmbroider Cheat Sheet open in a tab for reference. These notes are also heavily adapted from the cheat sheet. This workshop is based on Carpentries format, which means that participants should code alongside whoever is running it.

Copies of the files used for each of the exercises that can be downloaded here, but I'd recommend trying to generate the files yourself where possible.

1. Hello World: Drawing a Line

Follow the instructions here to set up PEmbroider on your computer. You will need Processing 4. The first thing we will do in PEMbroider is draw a single line, which we can also use to test everything is working correctly.

Template File

All files in PEmbroider have a similar structure, and the cheat sheet helpfully provides a template, which I've adapted slightly to match the file format we use in the CCI. We'll be using this as the basis for all the files in the workshop. This file draws a single line, but we can change that to anything we like.

// Example PEmbroider program
import processing.embroider.*;
PEmbroiderGraphics E;

void setup() {

  // Starting up:
  noLoop();
  size(600, 600); // 100 is 1cm
  E = new PEmbroiderGraphics(this, width, height);
  
  // change this line you want a different file type
  String outputFilePath = sketchPath("filename.pes"); 
  E.setPath(outputFilePath); 
  E.beginDraw();
  E.clear();

  //-------
  // Content goes here:
  E.line(0, 0, 600, 600); 

  //----------  
  // Visualization and export:
  // NOTE: Leave optimize() and endDraw() commented out,
  // until you are ready to export the embroidery file! 
  // Don't forget to un-comment them when you want to export!
  //
  // E.optimize(); // VERY SLOW, but essential for file output! 
  E.visualize(true, true, false);   // Display the embroidery path on-screen.
  // E.endDraw();  // Actually writes out the embroidery file.
}

In order, this file:

There are some other lines that are 'commented out' (have slashes in front of them) and don't run. These we might use later but for now we don't need to use them.

When you run this file, you should see an output that looks like this (if you don't see this, you will want to check over the setup steps again):

The pink dots represent the ends of stitches, where the needle enters the fabric. Shortly we will experiment with different stitch types and lengths, but for now we are using the default settings.

The first thing we will look at is the structure of the canvas. If you like, you can also try 'commenting out' the content line, to just see a plain canvas.

Exercise 1.1

Drawing lines

The PEmbroider code for drawing a line is:

E.line(x1, y1, x2, y2);

This means that (x1, y1) is the coordinates of the point where the line starts, and (x2, y2) is the point where the line ends. The E.line() part means "use the line function that belongs to PEmbroider, which is represented in our code by the letter E". We call this a 'method' In our code, we get a diagonal line because we draw from the point (0, 0) to the point (600, 600) (the edge of the canvas).

Exercise 1.2

You might find these notes on coordinate grids in Processing helpful here!

2. Playing with shapes

From now on, unless we're changing more of the file, I'm going to list just the 'content' code that we're changing, using ... to represent the rest of the file. In our last exercise, the content was a single line -- the E.line() method -- but it can be more -- the important part is that it goes in the same place in the file each time.

Try changing out the line for a circle:

...
E.circle(200, 200, 200);
...

You should see a slightly off-center circle. In the documentation, the E.circle() method is listed as:

E.circle(x, y, r);

Exercise 2.1

Composite Shapes

PEmbroider also allows us to merge outlines to make composite shapes. This can quickly allow us to create more complex drawings. In this example, we merge together 2 circles:

...
E.beginComposite();
  E.composite.circle(320, 250, 200);
  E.composite.circle(420, 250, 200);
E.endComposite();
...

Exercise 2.2

here's one I made earlier:

3. Fills and Hatching

Up until now, all the shapes we've been drawing have been outlines. PEmbroider supports several kinds of fills, which we will experiment with now. The way settings work in PEmbroider (and in Processing!) is that you set a bunch of settings, then draw the thing you want the settings to apply to, and then if you want to draw something with different settings, you change the settings and then draw the thing. For example, the order you'd do things if you wanted to draw a red square and a blue square would be:

> set fill to red
> draw square
> set fill to blue
> draw square

In our case, what this means is that if we add some code that adjusts the fill settings, this needs to go before the part where we draw our shape. Let's try drawing a filled circle:

...
E.hatchMode(E.PARALLEL);
E.fill(0,0,0);
E.circle(300, 300, 200);
...

Fill Types

There are 6 different fill types in total in PEmbroider. These can each be set using the following lines of code:

    E.hatchMode(E.CONCENTRIC);
    E.hatchMode(E.PARALLEL);
    E.hatchMode(E.SATIN);
    E.hatchMode(E.SPIRAL); 
    E.hatchMode(E.PERLIN);
    E.hatchMode(E.CROSS);

Exercise 3.1

Fill Settings

As well as being able to change the type of fill, it's also possible to change the fill settings, namely the spacing of the fill lines, the colour of the fill, and the angle of the fill lines (for satin and parallel fills, where the lines have a prevailing angle).

We can do this using the same principles as before (e.g. putting the settings before the thing we want them to apply to). The methods to adjust the settings are listed below (note that we always need to specify a fill colour, even if it's just black):

E.hatchSpacing(spacing); // sets the density of adjacent runs (in machine units)
E.hatchAngleDeg(angle);  // sets the orientation for SATIN & PARALLEL (in degrees)
E.fill(R, G, B);         // sets your thread color (numbers between 0-255)

Exercise 3.2

Another really important line is the setStitch() property. This sets the length of the stitch. Unlike hatch spacing, setStitch takes 3 arguments:

E.setStitch(minLength, desiredLength, noise);

Exercise 3.3

4. Stroke and Stitch Settings

The final group of settings we're going to look at is modifying the stroke (line) style. Similarly to fills, you need to modify the settings before drawing your line.

There are 2 stroke types in PEmbroider; tangent is the one we've been using by default, but perpendicular can be used to get a thicker, more defined outline.

E.strokeMode(E.PERPENDICULAR);  // Stitches are perpendicular to the stroke
E.strokeMode(E.TANGENT);         // Stitches go in the same direction as stroke

As before, stroke color can be set using RGB values. The other settings are the thickness of the line (stroke weight) and the stroke spacing (e.g. for perpendicular strokes).

E.stroke(R, G, B);         // sets the stroke color, just like Processing.
E.strokeWeight(width);     // sets the thickness of the stroke (in machine units)
E.strokeSpacing(spacing);  // sets the density of the hatching within the stroke

Exercise 4.1

5. Loops and Randomness

Now we have a good idea of what you can do with PEmbroider's API, we can try out some generative code.

For loops

For loops are structures that allow the same piece of code to be repeated multiple times with different inputs. We will have a go with them here, but for a full tutorial it's worth going through this page on for loops in Processing.

We're going to try out a for loop that repeatedly draws lines on the canvas, changing the position of the line each time it draws.

...
for (int i = 1; i < 10; i++) {
	E.line(50, i*50, 550, i*50);
}
...

In this code, we create a number, i, that will go from 1 to 10, increasing every time. The first time the code runs, i is equal to 1, and so i*50=50. The next time, i=2, so i*50=100, and so on, up till i reaches 9. i cannot reach 10 (as the code will only run for i<10) and so the for loop ends.

Exercise 5.1

Random numbers

Another very useful tool for making generative patterns is randomness. Unlike the code we were using before (which used scaled variations where we could predict what the outcome would be), randomness adds an element of chance. In Processing, the function random(50) will return a random number between 0-50. This number will be a decimal (float) rather than a whole number (int), so if we want to use it like a whole number we also need to use the int() method.

...
for (int i = 1; i < 10; i++) {
	E.circle(50 + i*50, 100, int(random(50)));
}
...

Exercise 5.2

Nesting for loops

The last thing we will look at is using 2 nested for loops to create 2D designs. This isn't the only way to achieve this -- remember the grids from exercise 5.1 -- but this will help us a lot.

Before we get there, we could also look at what happens when we nest for loops inside other things, in this case, the composite shapes code from before.

...
  E.beginComposite();
  for (int i = 1; i < 10; i++) {
    E.composite.circle(50 + i*50, 100, 50 + int(random(50)));
  }
  E.endComposite(); 
...

By putting the for loop inside E.beginComposite(); and E.endComposite();, it's the same (from the point of view of the computer) as writing 10 separate composite circle lines, but for us it's a whole lot quicker.

and look! A beautiful worm:

We can use the same principle to put one for loop inside another:

  for (int i = 1; i < 10; i++) {
  	for (int j = 1; j < 10; j++) {
    E.circle(i*50, j*50, 50 + int(random(50)));
    }
  }

Now we get a whole grid of circles!

Exercise 5.3

Here's one I made earlier:

6. Polylines and curves

As well as having preset shapes, PEmbroider (like Processing) supports making custom shapes by defining a set of points along a line. To start one of these shapes, you need to bookend the line with:

E.beginShape();
	// ...points
E.endShape();

If the final co-ordinate matches the first co-ordinate, we can also fill the shape: if not, it's just a stroke. Polylines are also great as within the line the machine doesn't need to make a jump; this is helpful for avoiding too many floats later on.

Each point on the line is given by E.vertex(x, y), a single point in space. To draw a spiky shape, we can draw a bunch of points:

E.beginShape();
	E.vertex(10,10);
	E.vertex(500,50);
	E.vertex(450,250);
	E.vertex(350,140);
	E.vertex(200,300);
	E.vertex(10,10);
E.endShape();

Exercise 6.1

Curves

There are a number of different ways to render curves in Processing, which inherit from the different curve-drawing techniques in computer graphics. These are: arcs, splines and Bézier curves. The Processing curves tutorial has a good summary of this:

The tutorial gives a great overview of the different types and I'd recommend experimenting with all of them.

7. Generating embroidery from data

Processing allows data to be loaded in CSV and JSON formats. For this exercise, we're going to use NASA's Land Ocean Surface Temperature dataset, which gives the mean global temperature since 1880 till present-day. To do this task, I have created a folder called datasets within the processing sketch folder, and created a file inside that called temp.csv.

First, make an empty sketch and try to read in the data from the .csv file:

Table table;

void setup() {
  
  table = loadTable("datasets/temp.csv", "header");
  println(table.getRowCount() + " total rows in table");

  for (TableRow row : table.rows()) {
    
    int year = row.getInt("year");
    float temp = row.getFloat("unsmoothed");
    println("year " + year + " temp " + temp);
  }
}

You should see the data from the csv printed to the terminal.

The for loop that starts for (TableRow row : table.rows()) is where we're going to use our values. First, we can try a simple example of drawing circles for each entry in the table, with the radius proportional to the temperature. As some temperature values are negative, we will need to adjust these up.

We want to add the embroidery template setup before the table is created (and also E.optimize()) after! To draw our circle, we can add directly to the for loop:

...
  for (TableRow row : table.rows()) {
    
    int year = row.getInt("year");
    float temp = row.getFloat("unsmoothed");
    float radius = (temp + 1.0)*45;
    E.circle(100, 100, radius);
  }

...

This code will create all the circles drawn in the same place. Ideally we'd like to space them out! We can do this by adding a counter:

...
  int counter = 0;

  for (TableRow row : table.rows()) {
    
    int year = row.getInt("year");
    float temp = row.getFloat("unsmoothed");
    float radius = (temp + 1.0)*45;
    E.circle(100, counter*20, radius);
    counter = counter + 1;
  }

...

7.1 Creating a grid from linear data

An issue we have here is that the data comes as one long list, which makes it hard to generate a tractable embroidery file. There are a number of ways around this, one of which is to use the modulo operator. This gives you the remainder when a number is divided by another number. This means, we can define a row length and count along our dataset in rows.

  ...
  int counter=0;
  int rowLength = 13;
  int spacing = round(900/(rowLength));
  
  for (TableRow row : table.rows()) {
    int i = counter % rowLength;
    int j = floor(num/rowLength);
    
    int year = row.getInt("year");
    float temp = row.getFloat("unsmoothed");
    float radius = (temp + 1.0)*45;
    
    E.circle((i+1)*spacing, (j+1)*spacing, radius);

    counter=counter+1;
  }
  ...

8. Tips, notes, further reading and extension exercises

We've scratched the surface of PEmbroider's full capabilities, which include things like image imports, interpolation, clipping and more.

8.1 Saving files + naming

To save the file as an embroidery file, you need to

  String outputFilePath = sketchPath("triangles" + str(int(random(0, 100))) + ".pes"); 

8.2 Scale, density and stitch sizing

I personally find PEmbroider's presets a bit dense, and think they make for quite tough-feeling embroidery. My main recommendation is to make a sample sheet where you experiment with different fill densities, stitch lengths and stroke widths till you find some you like, but failing that, my defaults are:

    E.strokeSpacing(2.0)    // this spaces the stroke (outline) stitches by 2 pixels
    E.hatchSpacing(3.0);    // this spaces hatch (fill) stitches by 3 pixels
    E.setStitch(5, 30, 0.0) // this sets minimum stitch to be 5px

If you want to use these throughout, just stick this above the 'content' section of your file.

Extension exercises