-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6199409
commit 5cfd0fa
Showing
4 changed files
with
87 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { StarLayer } from 'ngx-parallax-stars'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class LayerRandomizerService { | ||
generateRandomLayers(): StarLayer[] { | ||
const layerCount = this.generateRandomInteger(3, 4); | ||
|
||
const layers = []; | ||
|
||
for (let i = 1; i <= layerCount; i++) { | ||
layers.push(this.generateRandomLayer()); | ||
} | ||
|
||
return layers; | ||
} | ||
|
||
private generateRandomLayer(): StarLayer { | ||
return { | ||
color: '#ffffff', | ||
blur: this.generateRandomInteger(0, 5), | ||
density: this.generateRandomInteger(1, 5), | ||
glow: this.generateRandomInteger(0, 5), | ||
size: this.generateRandomInteger(1, 6), | ||
speed: this.generateRandomInteger(5, 20), | ||
isRound: this.getRandomBoolean(), | ||
direction: this.getRandomItem(['up', 'down', 'left', 'right']), | ||
}; | ||
} | ||
|
||
private generateRandomInteger(min: number, max: number) { | ||
return Math.floor(min + Math.random() * (max - min + 1)); | ||
} | ||
|
||
private getRandomItem<T>(array: T[]): T { | ||
return array[Math.floor(Math.random() * array.length)]; | ||
} | ||
|
||
private getRandomBoolean(): boolean { | ||
return Math.random() < 0.5; | ||
} | ||
} |