How to draw chiseled lines in processing?

I wish to draw chiseled lines in processing. I tried to use strokeCap() and strokeJoin() functions but they didn’t give me the behaviour I wanted. I have attached a sketch(made using Autodesk SketchBook) of the effect that I want.

tl;dr How to draw chiseled lines in processing?

Thank you

If all else fails, you could always draw the shapes yourself. Take a look at the beginShape() function and its friends in the reference.

1 Like

Hi Kevin,
Thanks for replying.

I did take your advice and use beginShape() in conjunction with PShape and was able to produce chiseled lines. Once I had the primary coordinates created of PShape created, it was easy to draw new chiseled lines by passing PShape’s reference to shape() function.

However as the vertices info is hard-coded in beginShape() - endShape(), I cannot specify the length of lines that I wish to create.

How might I overcome this particular nuance ?

https://screenshotscdn.firefoxusercontent.com/images/f69121ed-9620-41b1-8093-d0996e513790.png

Don’t create one specific PShape for all your lines!
Instead, draw each dynamically with vertex() calls.

void setup(){
  size(400,400);
  noStroke();
}

void draw(){
  background(255);
  
  fill(200,0,0);
  beginShape();
  vertex(20,20); vertex(25,25);vertex(115,25); vertex(120,20);
  endShape(CLOSE);
  
  fill(128);
  beginShape();
  vertex(20,20); vertex(25,25);vertex(25,195); vertex(20,200);
  endShape(CLOSE);

}

You might even consider writing a function that take the endpoints (and information about which way the caps need to slant) and draws it for you.

1 Like

Thanks. I took your advice and created two functions(one for vertical lines and one for horizontal lines):



void setup() {
  size(400, 400);
  noStroke();
  noLoop();
}

void draw() {

  fill(200, 0, 244);
  drawChiseledHLine(20, 200, 120, 200, 0,12);
  drawChiseledHLine(20, 20, 120, 20, 1,12);

  fill(128);
  drawChiseledVLine(120,20, 120, 200, 0, 12);
  drawChiseledVLine(20, 20, 20, 200, 1,12);
      
  
}
void drawChiseledHLine(int sX, int sY, int eX, int eY, int i, int thick) {
  if (i==0) {
    beginShape();
    vertex(sX, sY); vertex(sX+thick, sY-thick); vertex(eX-thick, eY-thick); vertex(eX, eY);
    endShape(CLOSE);
  } else {
    beginShape();
    vertex(sX, sY); vertex(sX+thick, sY+thick); vertex(eX-thick, eY+thick); vertex(eX, eY);
    endShape(CLOSE);
  }
}
void drawChiseledVLine(int sX, int sY, int eX, int eY, int i, int thick) {
  if (i==0) { 
    beginShape();
    vertex(sX, sY); vertex(sX-thick, sY+thick); vertex(eX-thick, eY-thick); vertex(eX, eY);
    endShape(CLOSE);
  } else {
    beginShape();
    vertex(sX, sY); vertex(sX+thick, sY+thick); vertex(eX+thick, eY-thick); vertex(eX, eY);
    endShape(CLOSE);
  }
}