function generateKochFractal(context, levels) {
let lines = [];
let m = 150;
let ww = width - m - m;
let uu = ww / 4;
lines.push(new KochLine(context, [m + uu * 2, m], [m + uu, m]));
lines.push(new KochLine(context, [m + uu * 3, m + uu], [m + uu * 2, m]));
lines.push(
new KochLine(context, [m + uu * 3, m + uu * 2], [m + uu * 3, m + uu])
);
lines.push(
new KochLine(context, [m + uu * 2, m + uu * 3], [m + uu * 3, m + uu * 2])
);
for (let i = 0; i < levels; i++) {
let next_lines = [];
for (let line of lines) {
const a = line.kochA(),
b = line.kochB(),
c = line.kochC(),
d = line.kochD(),
e = line.kochE();
next_lines.push(new KochLine(context, a, b));
next_lines.push(new KochLine(context, b, c));
next_lines.push(new KochLine(context, c, d));
next_lines.push(new KochLine(context, d, e));
}
lines = next_lines;
}
return lines;
}