You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
"use strict";
|
|
class Star extends Decoration {
|
|
constructor(properties) {
|
|
super(properties);
|
|
this.createTriangles();
|
|
}
|
|
get properties() {
|
|
let obj = super.properties;
|
|
obj['raysCount'] = this.raysCount;
|
|
obj['innerRadius'] = this.innerRadius;
|
|
return obj;
|
|
}
|
|
createTriangles() {
|
|
this.triangles = [];
|
|
let increment = p.TWO_PI / this.raysCount / 2, firstOuter = true;
|
|
for (let i = 0; i < p.TWO_PI; i += increment) {
|
|
let x1 = p.sin(i), y1 = -p.cos(i), x2 = p.sin(i + increment), y2 = -p.cos(i + increment);
|
|
if (firstOuter) {
|
|
x1 *= this.radius,
|
|
y1 *= this.radius,
|
|
x2 *= this.innerRadius,
|
|
y2 *= this.innerRadius;
|
|
}
|
|
else {
|
|
x2 *= this.radius,
|
|
y2 *= this.radius,
|
|
x1 *= this.innerRadius,
|
|
y1 *= this.innerRadius;
|
|
}
|
|
firstOuter = !firstOuter;
|
|
this.triangles.push([
|
|
p.createVector(x1, y1),
|
|
p.createVector(x2, y2),
|
|
p.createVector(0, 0)
|
|
]);
|
|
}
|
|
}
|
|
brightness(value) {
|
|
this.triangles.forEach((t, i) => {
|
|
p.fill(0, 0, 0, value);
|
|
p.triangle(t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y);
|
|
});
|
|
}
|
|
display(pos, dim) {
|
|
super.display(pos, dim);
|
|
p.noStroke();
|
|
this.triangles.forEach((t, i) => {
|
|
let color = this.colors[i % this.colors.length];
|
|
p.fill(color);
|
|
p.triangle(t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y);
|
|
});
|
|
if (this.mouseIsOver) {
|
|
this.brightness(70);
|
|
}
|
|
p.pop();
|
|
}
|
|
update() {
|
|
super.update();
|
|
}
|
|
toJSON(index) {
|
|
let list = [
|
|
"raysCount",
|
|
"innerRadius"
|
|
];
|
|
let obj = super.toJSON(index);
|
|
for (let item of list) {
|
|
obj[item] = this[item];
|
|
}
|
|
return obj;
|
|
}
|
|
}
|
|
//# sourceMappingURL=star.js.map
|