0

Is there any way to repeat a pattern in KonvaJS through a user input? I have this (DEMO). However,I am having difficulties wrapping my head around this next step. Is it possible?

Edit: I would like to programmatically clone/repeat the arc's peaks per span based on the user input and tile it along the x axis.

Яхья
  • 17
  • 1
  • 7

1 Answers1

1

You can just do this:

const lines = [];
  for (var i = 0; i < numArchPeaks; i++) {
    const single = [0, 0, 90, -50, 180, 0];
    const perSpan = single.map((x) => x / numArchPeaks);
    lines.push(
      <Line x={x + i * 180 / numArchPeaks} y={y} points={perSpan} tension={1} stroke="black" />
    );
  }

// then in render:
<Layer>{lines}</Layer>

https://codesandbox.io/s/stupefied-fermi-vz9z7?file=/src/KonvaExample.js

lavrton
  • 18,973
  • 4
  • 30
  • 63