The itch of perfecting the stitch
in
Programming Questions
•
2 years ago
I managed to come up with five stitching patterns that I was able to transform into drawing tools.
I am not entirely happy with the line stitch and double stitch but I like the dot stitch and the cross stitch.
Does anyone have an improvement to suggest for these two last ones? If you run my code, press the A key and drag the mouse for the first pattern; the B key and drag the mouse for the second pattern; the C key and drag the mouse for the third pattern; and the D key and drag the mouse for the fourth pattern.
Also, I'll need to make sure that they work against any colored backgrounds which means I'll need to get the pixel color of where they are at each moment.
Note: With the wavy stitch, I left it in the code but gave up altogether because the wave moves in draw() and I can't possibly see how it could be turned into a drawing tool anyway. It seems mathematically impossible to me.
Here is my code:
RandomColorPalette myRandomColorPalette;
Stitches myFlatStitches;
Stitches myDoubleFlatStitches;
Stitches myCrossStitches;
Stitches myDottedStitches;
/*Stitches myWavyStitches;*/
void setup() { // call the setup function to define initial enviroment properties
size(900, 700); // set the canvas size at 800 pixels by 800 pixels
background(230); // set background color to light gray
myRandomColorPalette=new RandomColorPalette (color(255, 255, 255), 100, 0, 0);
myFlatStitches=new Stitches (color(250, 100, 90), 100, 200, 0, 10, 6.6);
myDoubleFlatStitches=new Stitches (color(250, 100, 90), 100, 400, 0, 10, 5.0, 6.6);
myDottedStitches=new Stitches (color(227, 208, 140), 100, 600, 0, 10, 4);
myCrossStitches=new Stitches (color(227, 101, 221), 100, 800, 0, 10);
/* myWavyStitches=new Stitches (color(125, 225, 30), 100, 800, 0, 40.0, 3.0);*/
} // end the setup function
void draw () { // call the draw function
myRandomColorPalette.display();
myFlatStitches.display(10, 6.6);
myDoubleFlatStitches.display (10, 5.0, 6.6);
myCrossStitches.display(10);
myDottedStitches.display(10, 4);
/*myWavyStitches.display(40.0, 3.0);*/
myFlatStitches.drawFlatStitch(10, 6.6);
myDoubleFlatStitches.drawDoubleFlatStitch (10, 5.0, 6.6);
myCrossStitches.drawCrossStitch (10);
myDottedStitches.drawDottedStitch(10, 4);
} // end the draw function
abstract class Grid {
float sizeOfSquares;
color gridClr;
float boxPosX;
float boxPosY;
Grid(color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY) {
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
} // end of the constructor
void display () {
// initialization of quilt patterns (from Shiffman page 261)
for (int i=0;i<width;i+=sizeOfSquares) {
for (int j=0;j<height;j+=sizeOfSquares) {
fill(gridClr);
rect(i, j, sizeOfSquares, sizeOfSquares);
}
}
} // end of the display function
boolean mouseClickOverBox () {
if (mousePressed && ((mouseX>boxPosX) && (mouseX<boxPosX+sizeOfSquares) && (mouseY>boxPosY) && (mouseY<boxPosY+sizeOfSquares))) {
return true;
}
else {
return false;
}
}
}
class RandomColorPalette extends Grid {
RandomColorPalette(color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
}
void display () {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
if (mouseClickOverBox()) {
gridClr=(color(random(1, 255), random(1, 255), random(1, 255)));
fill (gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
}
}
}
class Stitches extends RandomColorPalette {
float clrLine;
float strokeClr;
int stitchLength;
float halfStitchLength;
float spacing;
int dotSize;
float stitchOffset;
float stitchSpeed;
float stitchScalar;
float stitchAngle;
float stitchX;
// Constructor overloading for different stitch patterns
// constructor for flat stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempStitchLength, float tempSpacing) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchLength= constrain (tempStitchLength, 8, 12);
tempSpacing= constrain (tempSpacing, tempStitchLength/5, tempStitchLength*4/5);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
spacing=tempSpacing;
stitchLength=tempStitchLength;
stitchX=boxPosX+sizeOfSquares/2;
}
// constructor for double flat stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempStitchLength, float tempHalfStitchLength, float tempSpacing) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchLength= constrain (tempStitchLength, 8, 12);
tempSpacing= constrain (tempSpacing, tempStitchLength/5, tempStitchLength*4/5);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
spacing=tempSpacing;
stitchLength=tempStitchLength;
halfStitchLength=tempHalfStitchLength;
// halfStitchLength=stitchLength/2;
stitchX=boxPosX+sizeOfSquares/2;
}
// constructor for cross stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempStitchLength) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchLength= constrain (tempStitchLength, 8, 12);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
stitchLength=tempStitchLength;
stitchX=boxPosX+sizeOfSquares/2;
}
// constructor for dotted stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempSpacing, int tempDotSize) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempSpacing= constrain (tempSpacing, 8, 12);
tempDotSize=constrain(tempDotSize, 1, 4);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
dotSize=tempDotSize;
spacing=tempSpacing;
stitchX=boxPosX+sizeOfSquares/2;
}
/* // constructor for the wavy stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, float tempStitchSpeed, float tempStitchScalar) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchSpeed=constrain(tempStitchSpeed, 20, 60);
tempStitchScalar=constrain(tempStitchScalar, 3, 6);
stitchAngle=0.0;
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
stitchSpeed=tempStitchSpeed;
stitchScalar= tempStitchScalar;
stitchX=boxPosX+sizeOfSquares/2;
} */
// Method overloading for display function of different stitch patterns
// display () flat stitch
void display (int stitchLength, float spacing) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke(0);
line (stitchX, i, stitchX, sizeOfSquares);
stroke (gridClr);
line (stitchX, i+spacing, stitchX, sizeOfSquares);
}
} // end the display () function
// display () double flat stitch
void display (int stitchLength, float halfStitchLength, float spacing) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke(0);
line (stitchX, i, stitchX, sizeOfSquares);
line (stitchX+stitchLength/2, i, stitchX+stitchLength/2, sizeOfSquares);
stroke (gridClr);
line (stitchX, i+spacing, stitchX, sizeOfSquares);
line (stitchX+stitchLength/2, i+spacing, stitchX+stitchLength/2, sizeOfSquares);
}
} // end the display () function
// display () cross stitch
void display (int stitchLength) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke(0);
line (stitchX, i, stitchX+stitchLength, i+stitchLength);
line (stitchX, i+stitchLength, stitchX+stitchLength, i);
}
}
// display () dotted stitch
void display (int stitchLength, int dotSize) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke (strokeClr);
fill (clrLine);
ellipse (stitchX, i, dotSize, dotSize);
}
}
/* // display () wavy stitch
void display (float stitchSpeed, float stitchScalar) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchScalar) {
float waveStitch=cos(radians(stitchAngle))*stitchScalar;
stitchAngle+=stitchSpeed;
stroke(0);
strokeWeight (3);
fill (0);
point (stitchX+waveStitch, i);
} // end the for loop
} // end the display () function */
// Method overloading for drawing tool of different stitch patterns
// drawFlatStitch ()
void drawFlatStitch (int stitchLength, float spacing) {
if ((keyPressed) && (key == 'a' || key == 'A') && mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke(0);
stroke(0);
line (pmouseX, pmouseY, mouseX, mouseY);
stroke (230);
line (pmouseX+spacing/3, pmouseY+spacing/3, mouseX, mouseY);
}
} // end the drawFlatStitch () function
// drawDoubleFlatStitch ()
void drawDoubleFlatStitch (int stitchLength, float halfStitchLength, float spacing) {
if ((keyPressed) && (key == 'b' || key == 'B') && mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke(0);
line (pmouseX, pmouseY, mouseX+spacing, mouseY+spacing);
stroke (230);
line (pmouseX+spacing, pmouseY+spacing, mouseX, mouseY);
}
} // end the doubleFlatStitch () function
// drawCrossStitch ()
void drawCrossStitch (int stitchLength) {
if ((keyPressed) && (key == 'c' || key == 'C') && mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke (0); // determine the color of the stroke of the ellipses that form the dotted line as purple
line (mouseX, mouseY, mouseX+stitchLength*3/4, mouseY+stitchLength*3/4);
line (mouseX, mouseY+stitchLength*3/4, mouseX+stitchLength*3/4, mouseY);
} // end the if condition block of code
} // end the drawDottedStitch () function
// drawDottedStitch ()
void drawDottedStitch (int stitchLength, int dotSize) {
if ((keyPressed) && (key == 'd' || key == 'D')&& mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke (0); // determine the color of the stroke of the ellipses that form the dotted line as purple
fill (0); // fill with purple the ellipses that form the dotted lines
ellipse (mouseX, mouseY, dotSize, dotSize); // draw little ellipses every n pixels
} // end the if condition block of code
} // end the drawDottedStitch () function
} // end Stitches class
I am not entirely happy with the line stitch and double stitch but I like the dot stitch and the cross stitch.
Does anyone have an improvement to suggest for these two last ones? If you run my code, press the A key and drag the mouse for the first pattern; the B key and drag the mouse for the second pattern; the C key and drag the mouse for the third pattern; and the D key and drag the mouse for the fourth pattern.
Also, I'll need to make sure that they work against any colored backgrounds which means I'll need to get the pixel color of where they are at each moment.
Note: With the wavy stitch, I left it in the code but gave up altogether because the wave moves in draw() and I can't possibly see how it could be turned into a drawing tool anyway. It seems mathematically impossible to me.
Here is my code:
RandomColorPalette myRandomColorPalette;
Stitches myFlatStitches;
Stitches myDoubleFlatStitches;
Stitches myCrossStitches;
Stitches myDottedStitches;
/*Stitches myWavyStitches;*/
void setup() { // call the setup function to define initial enviroment properties
size(900, 700); // set the canvas size at 800 pixels by 800 pixels
background(230); // set background color to light gray
myRandomColorPalette=new RandomColorPalette (color(255, 255, 255), 100, 0, 0);
myFlatStitches=new Stitches (color(250, 100, 90), 100, 200, 0, 10, 6.6);
myDoubleFlatStitches=new Stitches (color(250, 100, 90), 100, 400, 0, 10, 5.0, 6.6);
myDottedStitches=new Stitches (color(227, 208, 140), 100, 600, 0, 10, 4);
myCrossStitches=new Stitches (color(227, 101, 221), 100, 800, 0, 10);
/* myWavyStitches=new Stitches (color(125, 225, 30), 100, 800, 0, 40.0, 3.0);*/
} // end the setup function
void draw () { // call the draw function
myRandomColorPalette.display();
myFlatStitches.display(10, 6.6);
myDoubleFlatStitches.display (10, 5.0, 6.6);
myCrossStitches.display(10);
myDottedStitches.display(10, 4);
/*myWavyStitches.display(40.0, 3.0);*/
myFlatStitches.drawFlatStitch(10, 6.6);
myDoubleFlatStitches.drawDoubleFlatStitch (10, 5.0, 6.6);
myCrossStitches.drawCrossStitch (10);
myDottedStitches.drawDottedStitch(10, 4);
} // end the draw function
abstract class Grid {
float sizeOfSquares;
color gridClr;
float boxPosX;
float boxPosY;
Grid(color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY) {
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
} // end of the constructor
void display () {
// initialization of quilt patterns (from Shiffman page 261)
for (int i=0;i<width;i+=sizeOfSquares) {
for (int j=0;j<height;j+=sizeOfSquares) {
fill(gridClr);
rect(i, j, sizeOfSquares, sizeOfSquares);
}
}
} // end of the display function
boolean mouseClickOverBox () {
if (mousePressed && ((mouseX>boxPosX) && (mouseX<boxPosX+sizeOfSquares) && (mouseY>boxPosY) && (mouseY<boxPosY+sizeOfSquares))) {
return true;
}
else {
return false;
}
}
}
class RandomColorPalette extends Grid {
RandomColorPalette(color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
}
void display () {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
if (mouseClickOverBox()) {
gridClr=(color(random(1, 255), random(1, 255), random(1, 255)));
fill (gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
}
}
}
class Stitches extends RandomColorPalette {
float clrLine;
float strokeClr;
int stitchLength;
float halfStitchLength;
float spacing;
int dotSize;
float stitchOffset;
float stitchSpeed;
float stitchScalar;
float stitchAngle;
float stitchX;
// Constructor overloading for different stitch patterns
// constructor for flat stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempStitchLength, float tempSpacing) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchLength= constrain (tempStitchLength, 8, 12);
tempSpacing= constrain (tempSpacing, tempStitchLength/5, tempStitchLength*4/5);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
spacing=tempSpacing;
stitchLength=tempStitchLength;
stitchX=boxPosX+sizeOfSquares/2;
}
// constructor for double flat stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempStitchLength, float tempHalfStitchLength, float tempSpacing) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchLength= constrain (tempStitchLength, 8, 12);
tempSpacing= constrain (tempSpacing, tempStitchLength/5, tempStitchLength*4/5);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
spacing=tempSpacing;
stitchLength=tempStitchLength;
halfStitchLength=tempHalfStitchLength;
// halfStitchLength=stitchLength/2;
stitchX=boxPosX+sizeOfSquares/2;
}
// constructor for cross stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempStitchLength) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchLength= constrain (tempStitchLength, 8, 12);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
stitchLength=tempStitchLength;
stitchX=boxPosX+sizeOfSquares/2;
}
// constructor for dotted stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, int tempSpacing, int tempDotSize) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempSpacing= constrain (tempSpacing, 8, 12);
tempDotSize=constrain(tempDotSize, 1, 4);
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
dotSize=tempDotSize;
spacing=tempSpacing;
stitchX=boxPosX+sizeOfSquares/2;
}
/* // constructor for the wavy stitch
Stitches (color tempgridClr, float tempsizeOfSquares, float tempBoxPosX, float tempBoxPosY, float tempStitchSpeed, float tempStitchScalar) {
super (tempgridClr, tempsizeOfSquares, tempBoxPosX, tempBoxPosY);
tempStitchSpeed=constrain(tempStitchSpeed, 20, 60);
tempStitchScalar=constrain(tempStitchScalar, 3, 6);
stitchAngle=0.0;
gridClr=tempgridClr;
sizeOfSquares=tempsizeOfSquares;
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
stitchSpeed=tempStitchSpeed;
stitchScalar= tempStitchScalar;
stitchX=boxPosX+sizeOfSquares/2;
} */
// Method overloading for display function of different stitch patterns
// display () flat stitch
void display (int stitchLength, float spacing) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke(0);
line (stitchX, i, stitchX, sizeOfSquares);
stroke (gridClr);
line (stitchX, i+spacing, stitchX, sizeOfSquares);
}
} // end the display () function
// display () double flat stitch
void display (int stitchLength, float halfStitchLength, float spacing) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke(0);
line (stitchX, i, stitchX, sizeOfSquares);
line (stitchX+stitchLength/2, i, stitchX+stitchLength/2, sizeOfSquares);
stroke (gridClr);
line (stitchX, i+spacing, stitchX, sizeOfSquares);
line (stitchX+stitchLength/2, i+spacing, stitchX+stitchLength/2, sizeOfSquares);
}
} // end the display () function
// display () cross stitch
void display (int stitchLength) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke(0);
line (stitchX, i, stitchX+stitchLength, i+stitchLength);
line (stitchX, i+stitchLength, stitchX+stitchLength, i);
}
}
// display () dotted stitch
void display (int stitchLength, int dotSize) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchLength) {
stroke (strokeClr);
fill (clrLine);
ellipse (stitchX, i, dotSize, dotSize);
}
}
/* // display () wavy stitch
void display (float stitchSpeed, float stitchScalar) {
stroke(0);
fill(gridClr);
rect (boxPosX, boxPosY, sizeOfSquares, sizeOfSquares);
for (float i=boxPosY; i<sizeOfSquares; i+=stitchScalar) {
float waveStitch=cos(radians(stitchAngle))*stitchScalar;
stitchAngle+=stitchSpeed;
stroke(0);
strokeWeight (3);
fill (0);
point (stitchX+waveStitch, i);
} // end the for loop
} // end the display () function */
// Method overloading for drawing tool of different stitch patterns
// drawFlatStitch ()
void drawFlatStitch (int stitchLength, float spacing) {
if ((keyPressed) && (key == 'a' || key == 'A') && mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke(0);
stroke(0);
line (pmouseX, pmouseY, mouseX, mouseY);
stroke (230);
line (pmouseX+spacing/3, pmouseY+spacing/3, mouseX, mouseY);
}
} // end the drawFlatStitch () function
// drawDoubleFlatStitch ()
void drawDoubleFlatStitch (int stitchLength, float halfStitchLength, float spacing) {
if ((keyPressed) && (key == 'b' || key == 'B') && mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke(0);
line (pmouseX, pmouseY, mouseX+spacing, mouseY+spacing);
stroke (230);
line (pmouseX+spacing, pmouseY+spacing, mouseX, mouseY);
}
} // end the doubleFlatStitch () function
// drawCrossStitch ()
void drawCrossStitch (int stitchLength) {
if ((keyPressed) && (key == 'c' || key == 'C') && mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke (0); // determine the color of the stroke of the ellipses that form the dotted line as purple
line (mouseX, mouseY, mouseX+stitchLength*3/4, mouseY+stitchLength*3/4);
line (mouseX, mouseY+stitchLength*3/4, mouseX+stitchLength*3/4, mouseY);
} // end the if condition block of code
} // end the drawDottedStitch () function
// drawDottedStitch ()
void drawDottedStitch (int stitchLength, int dotSize) {
if ((keyPressed) && (key == 'd' || key == 'D')&& mousePressed && (dist(pmouseX, pmouseY, mouseX, mouseY) >= stitchLength)) {
stroke (0); // determine the color of the stroke of the ellipses that form the dotted line as purple
fill (0); // fill with purple the ellipses that form the dotted lines
ellipse (mouseX, mouseY, dotSize, dotSize); // draw little ellipses every n pixels
} // end the if condition block of code
} // end the drawDottedStitch () function
} // end Stitches class
1