sparklier sparkles

This commit is contained in:
Mononaut 2024-08-11 20:52:26 +00:00
parent b8cfeb579b
commit 021f0b32a1
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -41,23 +41,25 @@ export class AccelerationSparklesComponent implements OnChanges {
doSparkle(): void {
if (this.run) {
const now = performance.now();
if (now - this.lastSparkle > 30) {
if (now - this.lastSparkle > 20) {
this.lastSparkle = now;
if (this.arrow?.nativeElement && this.sparkleAnchor?.nativeElement) {
const anchor = this.sparkleAnchor.nativeElement.getBoundingClientRect().right;
const right = this.arrow.nativeElement.getBoundingClientRect().right;
const dx = (anchor - right) + 37.5;
this.sparkles.push({
style: {
right: dx + 'px',
top: (Math.random() * 30) + 'px',
animationDelay: (Math.random() * 50) + 'ms',
},
rotation: {
transform: `rotate(${Math.random() * 360}deg)`,
}
});
while (this.sparkles.length > 100) {
const dx = (anchor - right) + 30;
const numSparkles = Math.ceil(Math.random() * 3);
for (let i = 0; i < numSparkles; i++) {
this.sparkles.push({
style: {
right: (dx + (Math.random() * 10)) + 'px',
top: (15 + (Math.random() * 30)) + 'px',
},
rotation: {
transform: `rotate(${Math.random() * 360}deg)`,
}
});
}
while (this.sparkles.length > 200) {
this.sparkles.shift();
}
this.cd.markForCheck();