Permalink
Sep 24, 2018
Aug 9, 2020
Sep 24, 2018
Sep 24, 2018
Sep 24, 2018
Aug 9, 2020
Oct 14, 2019
Oct 14, 2019
Aug 8, 2020
Oct 11, 2019
Oct 11, 2019
Oct 11, 2019
Oct 10, 2019
Oct 11, 2019
Oct 10, 2019
Sep 24, 2018
Newer
100644
249 lines (226 sloc)
6.94 KB
22
export default class Drawing {
23
constructor({ styles, ctx, width, height, iters, snowflakeIters, strokeColor, strokeWidth=2, bgColor, canOverlap=false }) {
26
{
29
},
31
);
32
34
35
Object.assign(this, {
36
ctx,
37
width,
38
height,
39
iters,
40
bgColor,
41
snowflakeIters,
42
canOverlap
43
})
66
kochTessel3(center, radius, depth = 1, iters = 1, i = 2) {
67
const childRad = radius / 2;
68
if (depth == 0) {
69
this.kochSnowflake({
70
center,
71
radius,
72
offsetRot: Math.PI / 6,
73
iters
74
});
75
} else {
76
for (let i = 0; i < 6; i++) {
78
const spoke = radius;
79
const pos = translate(
80
{
81
x: spoke * Math.sin(theta),
82
y: spoke * Math.cos(theta)
83
},
84
center
85
);
86
this.kochTessel3(pos, childRad, depth - 1, iters, i);
87
}
88
}
89
}
90
142
translate(center, { x: 1, y: 0 }),
143
translate(center, { x: -1, y: 0 }),
144
translate(center, { x: 0, y: 1 }),
145
translate(center, { x: 0, y: -1 }),
146
translate(center, { x: 1, y: 1 }),
147
translate(center, { x: 1, y: -1 }),
148
translate(center, { x: -1, y: -1 }),
149
translate(center, { x: -1, y: 1 })
150
];
151
return (
152
possNeibs.filter(neib => this.cache.has(this.getCacheId(neib)))
153
.length > 0
154
);
167
points.push(
168
translate(
169
{
170
x: radius * Math.sin(theta),
171
y: radius * Math.cos(theta)
172
},
173
center
174
)
175
);
178
points.forEach((start, i) => {
179
const end = points[i + 1 > points.length - 1 ? 0 : i + 1];
186
const len = {
187
x: (end.x - start.x) / 3,
188
y: (end.y - start.y) / 3
189
};
190
191
const { ctx } = this;
192
if (iters == 0) {
193
this.thiccLine(start.x, start.y, end.x, end.y, lineWidth);
194
} else {
231
const vec = normalize(rotate({ x: sx - ex, y: sy - ey }, Math.PI / 2));
232
for (let i = 0; i < lineWidth; i++) {
233
const offset = mult(vec, i - Math.floor(lineWidth / 2));
234
const st = translate({ x: sx, y: sy }, offset);
235
const en = translate({ x: ex, y: ey }, offset);
240
thiccDot(x, y, size) {
241
for (let i = 0; i < size; i++) {
242
this.ctx.ellipse(i, i, x, y);
249
}