-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogo.js
146 lines (115 loc) Β· 3.12 KB
/
logo.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// get the text nodes in the logo
var nodes = []
var walker = document.createTreeWalker(h, NodeFilter.SHOW_TEXT)
while(walker.nextNode()) nodes.push(walker.currentNode)
// pull out letters, and wrap in <span>
var letters = nodes.reduce( (letters, node) => {
while(node.nodeValue) {
let next = node.splitText(1)
let span = document.createElement('span')
span.appendChild(node.cloneNode())
node.parentElement.replaceChild(span, node)
letters.push(span)
node = next
}
return letters
}, [])
// to fill (?) - rAF * performance
function play(timeline) {
var start = performance.now(),
i = 0, s = 0
function show(t, index, letter, colour) {
if(letter) letters[index].textContent = letter
if(colour) letters[index].style.color = colour
}
function render(t) {
while(timeline[i] && timeline[i][0] <= (t - start - s)) {
show.apply(null, timeline[i])
s += timeline[i][0]
i++
}
if(i < timeline.length)
requestAnimationFrame(render)
// else
// console.log("done")
}
requestAnimationFrame(render)
}
// sweep letters from top left to bottom right
function transitionA(letters, colour) {
return [
[ 0, 0, letters[0], colour],
[ 40, 1, letters[1], colour],
[ 0, 4, letters[4], colour],
[ 40, 2, letters[2], colour],
[ 0, 5, letters[5], colour],
[ 40, 3, letters[3], colour],
[ 0, 6, letters[6], colour],
[ 40, 7, letters[7], colour]
]
}
function fill(n, str) {
// Array.from({length:n}, _ => str)
var arr = new Array(n)
for (var i = 0; i < arr.length; i++) {
arr[i] = str
}
return arr
}
// sweep from top left to bottom right
var animation1 = 'jsoxconf'.split('')
.reduce((timeline, letter, i) => {
var c = i % 2 ? 'aquamarine' : '#f08'
return timeline
.concat(transitionA(fill(8, letter), c))
.concat([[100]])
}, [])
.concat(
transitionA('jsoxconf'.split(''), '#000')
)
// side by side blocky thing
var animation2 = ['jjss','ooxx','conf']
.map(s => s.split(''))
.reduce( (timeline, letters, i) => {
var c = i % 2 ? 'aquamarine' : '#f08'
var c2 = !(i % 2) ? 'aquamarine' : '#f08'
return timeline.concat([
[0, 0, letters[0], c],
[0, 4, letters[0], c],
[0, 1, letters[1], c],
[0, 5, letters[1], c],
[0, 3, letters[3], c2],
[0, 7, letters[3], c2],
[0, 2, letters[2], c2],
[0, 6, letters[2], c2],
[800],
])
}, [])
.concat(
transitionA('jsoxconf'.split(''), '#000')
)
// random
var animation3 = Array.from({length:40}, _ => [
Math.random() * 20,
Math.floor(Math.random() * 8),
Math.random().toString(32)[2],
Math.random() > 0.5 ? 'aquamarine' : '#f08'
])
.concat(
transitionA('jsoxconf'.split(''), '#000')
)
// emoji (doesn't work well)
var animation4 = Array.from({length:40}, (_,i) => [
Math.random() * 120,
i % 8,
random(['π','π','π―','π','π₯'])
])
.concat(
transitionA('jsoxconf'.split(''), '#000')
)
function random(arr) {
return arr[Math.floor(Math.random() * arr.length)]
}
setInterval(function() {
play(random([animation1, animation2, animation3, animation4]))
}, 5000)