generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-star-svg.js
55 lines (47 loc) · 1.51 KB
/
generate-star-svg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const fs = require('fs');
/**
* Generate the SVGs used for the background images for the star layers
* execute this generator with
* node generate-star-svg.js
*/
function generateStarSVGs() {
const starsLayerConfigurations = [
{
density: 0.25, // how dense / how many stars there are in this layer
starSize: '1', // the size of a singe star
},
{
density: 0.2,
starSize: '1.5',
},
{
density: 0.15,
starSize: '2',
},
{
density: 0.1,
starSize: '2.5',
},
{
density: 0.05,
starSize: '3',
},
];
const offsetHeight = 500;
const offsetWidth = 500;
starsLayerConfigurations.forEach((starsLayerConfiguration, index) => {
// calculate stars for each starsLayer based on content height
const starsInLayer = Math.floor(offsetHeight * starsLayerConfiguration.density);
let starSvg = '<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">';
// const { blur } = starsLayerConfiguration;
for (let starCount = 0; starCount < starsInLayer; starCount += 1) {
const xPosition = Math.floor(Math.random() * offsetWidth);
const yPosition = Math.floor(Math.random() * offsetHeight);
const opacity = Math.floor(Math.random() * 100);
starSvg += `<circle cx="${xPosition}" fill="white" cy="${yPosition}" opacity="${opacity}%" r="${starsLayerConfiguration.starSize / 2}px" />`;
}
starSvg += '</svg>';
fs.writeFileSync(`images/stars/layer${index}.svg`, starSvg);
});
}
generateStarSVGs();