Add induction lines
This commit is contained in:
parent
a2eae95e5b
commit
480d9b899d
|
@ -83,6 +83,19 @@ class Line {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the sum of a slice of this `Line`'s [LineSegment]s.
|
||||||
|
*
|
||||||
|
* @param start the start of the slice to sum over
|
||||||
|
* @param end the end of the slice to sum over
|
||||||
|
* @return the sum of a slice of this `Line`'s [LineSegment]s
|
||||||
|
*/
|
||||||
|
sumSegmentsSlice(start?: number, end?: number): LineSegment {
|
||||||
|
const slice = this.segments.slice(start, end);
|
||||||
|
return new LineSegment(slice.reduce((acc, it) => acc + it.x, 0), slice.reduce((acc, it) => acc + it.y, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if and only if this `Line` is exactly the same as `other`.
|
* Returns `true` if and only if this `Line` is exactly the same as `other`.
|
||||||
*
|
*
|
||||||
|
@ -104,12 +117,39 @@ doAfterLoad(() => {
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
// State
|
// State
|
||||||
const lines: Line[] = [];
|
const lines: Line[] = [new Line(1), new Line(2)];
|
||||||
lines.push(new Line(10));
|
|
||||||
|
let step = 0;
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
const stepLine = Math.floor(step / 25);
|
||||||
|
const inductionLine = stepLine + 1;
|
||||||
|
const superInductionLine = stepLine + 2;
|
||||||
|
|
||||||
|
// Add new low-level segment
|
||||||
|
const length = 5 ** (2 + stepLine);
|
||||||
const angle = (random_normal() - 0.5) * Math.PI * 2;
|
const angle = (random_normal() - 0.5) * Math.PI * 2;
|
||||||
lines[0].segments.push(new LineSegment(Math.cos(angle) * 25, Math.sin(angle) * 25));
|
lines[stepLine].segments.push(new LineSegment(Math.cos(angle) * length, Math.sin(angle) * length));
|
||||||
}, 1000);
|
|
||||||
|
// Add first-level induction line
|
||||||
|
if ((step + 1) % 5 === 0) {
|
||||||
|
if (lines.length <= inductionLine) {
|
||||||
|
lines[inductionLine] = new Line(inductionLine + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lines[inductionLine].segments.push(lines[stepLine].sumSegmentsSlice(-5));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add second-level induction line
|
||||||
|
if ((step + 1) % 25 === 0) {
|
||||||
|
if (lines.length <= superInductionLine) {
|
||||||
|
lines[superInductionLine] = new Line(superInductionLine + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lines[superInductionLine].segments.push(lines[inductionLine].sumSegmentsSlice(-5));
|
||||||
|
}
|
||||||
|
|
||||||
|
step++;
|
||||||
|
}, 250);
|
||||||
|
|
||||||
// Resize
|
// Resize
|
||||||
const resize = () => {
|
const resize = () => {
|
||||||
|
@ -136,6 +176,7 @@ doAfterLoad(() => {
|
||||||
// Lines
|
// Lines
|
||||||
ctx.strokeStyle = "#ffffff";
|
ctx.strokeStyle = "#ffffff";
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
|
ctx.lineWidth = line.thickness;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(center.x, center.y);
|
ctx.moveTo(center.x, center.y);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue