aahdee – Hatching

There’s two svgs as I used PEmbroider

I used PEmbroider for the last one. This assignment was one of the easiest and the most fun for me. For the second one, I used some tiling techniques to ensure that I didn’t draw the same line twice. I also wrote the best switch statement of my life for that one. I used the techniques of ordered randomness for the third one to ensure that the crosses are balanced and gives an effect of increasing shading.

The code is below the continue reading.

import processing.embroider.*;
import processing.svg.*;
PEmbroiderGraphics E;

int canvasSizeW = 1150;
int canvasSizeH = 900;

void settings() {
  size(canvasSizeW, canvasSizeH);
}

void setup() {
  noLoop();
  surface.setLocation(50, 50);
  E = new PEmbroiderGraphics(this, width, height);
  //beginRecord(SVG, "hatch.svg");
  //noFill();

  String filePath = sketchPath("embroiderc.svg");
  E.setPath(filePath);
  E.beginDraw();
  E.clear();
  E.strokeWeight(1);
  E.fill(0, 0, 0);
  E.noStroke();

  E.toggleConnectingLines(false);
  E.toggleResample(false);
  //E.rect(50,50,960,192);

  MyVecField f = new MyVecField(); 
  E.HATCH_MODE = PEmbroiderGraphics.VECFIELD;
  E.HATCH_VECFIELD = f;
  //E.HATCH_ANGLE = radians(90); 
  //E.HATCH_ANGLE2 = radians(75); 
  int ew = 192;
  for (int i = 0; i< 5; i++) {
    E.HATCH_SPACING = 25-i*5;
    E.rect((ew)*i+50, 50, ew, ew);
  }
  


  E.optimize(); // slow, but good and important
  E.visualize();
  E.endDraw(); // write out the file
  //background(220);
  
}

class MyVecField implements PEmbroiderGraphics.VectorField {
  public PVector get(float x, float y) {
    x*=0.05;
    return new PVector(.5, 0.2*tan(2*x + 3));
  }
}

void draw() {
  ////hatch2(50, 50, 192);
  //hatch2(50, 50, 192);
  //rect(50, 50, 960,192);
  //hatch3(50, 262, 192);
  //rect(50, 262, 960,192);
  //hatch1(50, 474, 192);
  //rect(50, 474, 960,192);
  
  //endRecord();
  ;
}

// ----- HATCH 1 -----

void hatch1(int x1, int y1, float w) {
  int crossW = 3;
  for (int i = 0; i < 5; i++) {
    float startX = (w)*i+x1;
    float startY = y1;

    //square(startX, startY, w);
    float fillPercent = 7*(10+ 20*i)/10;
    float fillSec = w/fillPercent;

    for (int j = 0; j < fillPercent; j++) {
      float row = j*(fillSec);
      float rowOff = fillSec-crossW/2;
      for (int k = 0; k < fillPercent; k++) {
        float col = k*(fillSec);
        float colOff = fillSec-crossW/2;
        float x = random(startX+row+(crossW/2), startX+row+rowOff);
        float y = random(startY+col+(crossW/2), startY+col+colOff);
        cross(x, y, crossW);
      }
    }
  }
}


void cross(float x, float y, float size) {
  line(x-size/2, y-size/2, x+size/2, y+size/2);
  line(x-size/2, y+size/2, x+size/2, y-size/2);
}

// ----- HATCH 2 -----

void hatch2(int x1, int y1, float w) {
  for (int i = 0; i < 5; i++) {
    float startX = (w)*i+x1;
    float startY = y1;

    //square(startX, startY, w);
    float fillPercent = (10+ 20*i)/2;
    float fillSec = w/fillPercent;
    //float partition = 
    for (int j = 0; j <= fillPercent; j++) {
      float row = j*(fillSec);
      line(startX, startY+row, startX+row, startY);
    }
    for (int j = 0; j < fillPercent; j++) {
      float row = j*(fillSec);

      line(startX+row, startY+w, startX+(row/2), startY+w-(row/2));
    }
    for (int j = 0; j <= fillPercent; j++) {
      float row = j*(fillSec);

      line(startX+w, startY+row, startX+w-(row/2), startY+(row/2));
    }
    print(startX+w);
    print("\n");
  }
}

// ----- HATCH 3 -----


void hatch3(int x1, int y1, float w) {
  for (int i = 0; i < 5; i++) {
    float startX = (w)*i+x1;
    float startY = y1;

    //square(startX, startY, w);
    float fillPercent = 10;
    float fillSec = w/fillPercent;

    for (int j = 0; j < fillPercent; j++) {
      float row = j*(fillSec);

      for (int k = 0; k < fillPercent; k++) {
        float col = k*(fillSec);
        pattern(startX+row, startY+col, fillSec, i);
      }
    }
  }
}

// okay i ATE right here 
void pattern(float x, float y, float size, int percent) {
  beginShape();
  noFill();
  switch (percent) {
  case 4:
    vertex(x+size, y);
  case 3:
    vertex(x, y);
  case 2:
    vertex(x+(size/2), y+(size/2));
  case 1: 
    vertex(x+size, y);
  case 0:
    vertex(x+size, y+size);
    vertex(x+(size/2), y+(size/2));
    vertex(x, y+size);
  }
  endShape();
}