-
Notifications
You must be signed in to change notification settings - Fork 0
/
rndSVG.js
26 lines (26 loc) · 1.16 KB
/
rndSVG.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
// Random CSS values
const bgcolor = '#' + Math.floor(Math.random()*16777215).toString(16)
document.documentElement.style.setProperty('--rnd-bgcolor', bgcolor)
const fill = '#' + Math.floor(Math.random()*16777215).toString(16)
document.documentElement.style.setProperty('--rnd-fill', fill)
const dash = Math.floor(Math.random()*8192)
document.documentElement.style.setProperty('--rnd-dash', dash)
const time = 'very-long-draw ' + Math.floor(Math.random()*16) + 's linear infinite'
document.documentElement.style.setProperty('--rnd-time', time)
// Random path generator
let path = document.getElementById('path')
path.setAttribute('d', randomSVG())
function randomSVG() {
const lNum = 8192
let path = 'm16 16'
for (let i = 0; i <= lNum; i++) {
const ax = Math.floor(Math.random() * 32 - 15.5) / 8
const ay = Math.floor(Math.random() * 32 - 15.5) / 8
const bx = Math.floor(Math.random() * 32 - 15.5) / 8
const by = Math.floor(Math.random() * 32 - 15.5) / 8
const cx = Math.floor(Math.random() * 32 - 15.5) / 8
const cy = Math.floor(Math.random() * 32 - 15.5) / 8
path += 'c' + ax + ' ' + ay + ' ' + bx + ' ' + by + ' ' + cx + ' ' + cy
}
return path
}