Planar kirigami ver2

Draw planar kirigami pattern. The stiffness of the sheet can vary with the spacing, the length (l) and the number of cuts (n).

Log in to post a comment.

Canvas.setpenopacity(1);

const turtle = new Turtle();

// ----------------------
// PARAMETERS
// ----------------------

// scaling factor
let scale = 1; // min=0, max=10, step=0.1 

// distance between columns
let spacing = 2; // min=1, max=50, step=1

// rectangle length (horizontal)
let Length = 180; // min=1, max=400, step=1

// rectangle width (vertical)
let Width = 100; // min=1, max=400, step=1

// number of segments in full column
let number_col = 4; // min=1, max=50, step=1

// length of each vertical segment
let cut_length = 20; // min=1, max=50, step=1

// length of left and right clamps
let left_clamp = 25; // min=1, max=200, step=1 

let right_clamp = 25; // min=1, max=200, step=1 

let line_thickness = 0.1; // min=0.1, max=5, step=0.1

// ----------------------
// DERIVED VALUES
// ---------------en-------
const d = (scale * Width - number_col*scale * cut_length)/(number_col-1); // Overlapping length
const e = (d + scale * cut_length) / 2       // Offset of the second raw of cuts

// bottom-left corner of centered rectangle
const x0 = -scale * Length / 2;
const y0 = -scale * Width / 2;

// ----------------------
// DRAW RECTANGLE
// ----------------------
turtle.penup();
turtle.goto(x0, y0);
turtle.setheading(0);
turtle.pendown();

turtle.forward(scale * Length);
turtle.right(90);
turtle.forward(scale * Width);
turtle.right(90);
turtle.forward(scale * Length);
turtle.right(90);
turtle.forward(scale * Width);
turtle.right(90);

// ----------------------
// DRAW COLUMN FUNCTION
// ----------------------
function drawSegment(x, y, length) {
  const h = scale * length;
  const r = line_thickness / 2;

  if (line_thickness <= 0) return;

  turtle.penup();
  turtle.goto(x - r, y);
  turtle.setheading(90);
  turtle.pendown();

  turtle.forward(h);
  turtle.right(90);
  turtle.forward(line_thickness);
  turtle.right(90);
  turtle.forward(h);
  turtle.right(90);
  turtle.forward(line_thickness);
  turtle.right(90);

  turtle.penup();
}

function drawColumn(x, yStart, count) {
  for (let i = 0; i < count; i++) {
    const y = yStart + i * (scale * cut_length + d);
    drawSegment(x, y, cut_length);
  }
}

// ----------------------
// DRAW PATTERN
// ----------------------
let x = x0 + scale * left_clamp;

while (x <= x0 + scale * Length - scale * right_clamp) {

  // full column (n segments) starting at y =  -W/2
  drawColumn(x, -scale * Width/2, number_col);

  // offset column (n-1 segments) at x + spacing, starting at y = e  -W/2
  const x2 = x + scale * spacing;
  if (x2 <= x0 + scale * Length - scale * right_clamp) {
    drawColumn(x2, e - scale * Width/2, number_col - 1);
  }

  // move to next pair
  x += scale * spacing * 2;
}