CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
465 stars 27 forks source link

Potentially helpful sizing function #110

Open anneschoonmaker opened 1 year ago

anneschoonmaker commented 1 year ago

Hi! I have been using this library for my thesis and have really loved it! One thing I built out that helped me was a function allowing the user to dictate the hoop size in inches so that when I transfer my designs to my machine, less resizing is needed. However, I have only tested it on the PE800 embroidery machine, so not sure how it would work for other brands. For it to show up as the right size, I had to use the settings function to call the hoop function created since you cannot set size() with variables regularly. Hope this can help some people with their art as well! Here is an example below:

import processing.embroider.*;
PEmbroiderGraphics E;
 int[] xy = new int[2];
 int x = 0;
 int y = 0;

//need to use the settings function so that the hoop function can be called and have 
//size width and height be a variable not hard coded
void settings(){
  int[] xy = hoop(4,4, "in"); 
  x= xy[0];
  y= xy[1];
  size(x,y);
}

void setup(){
  noLoop();  
  String outputFilePath = sketchPath("hoopdemo.pes");

  //the space for the embroidery is the same size as the gray window
  E = new PEmbroiderGraphics(this, x, y);
  E.setPath(outputFilePath);  
  E.beginDraw(); 
  E.clear();
  E.textSize(4); 
  E.text("Hello World! :)", 50, 100); 
  E.beginRepeatEnd(2);
  //E.optimize(); // VERY SLOW -- can take MINUTES -- but ESSENTIAL!!!
  E.visualize(true, false,false);
  E.endDraw(); // write out the file
  save("hoopdemo.png");

}

int[] hoop(int width, int height, String type){

  //width and height is the value of the hoop size so if you want it to be 4*4 inches it will create
  //a boundary of roughly that size  
  int tandb = 0;
  int landr = 0;
  if(type.equals("in")){
  float inch = 25.4*10; 
  tandb = int(width * inch);
  landr = int(height * inch);    
  }
  int[] xy = new int[2]; 
  xy[0] = tandb; 
  xy[1] = landr; 
  return xy;
}

hoopdemo