-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
266 lines (213 loc) · 7.62 KB
/
index.html
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<html lang="ru">
<head>
<link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="ru">
</head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="typed.js"> </script>
<link href="https://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet">
<body onClick="updateQuote(); WordShuffler();">
<article>
<h1 id="headline"></h1>
<div style="text-align: center;" id="myQuote"><p id="text">Moscow Rules</p></div>
</article>
</body>
<script>
var quotes = ["Vary your pattern and stay within your cover.", "Pick the time and place for action.", "Keep your options open.", "Maintain a natural pace", "Technology will always let you down", "Once is an accident. Twice is a coincidence. Three times is an enemy action.", "Avoid static lookouts; stay away from chokepoints where they can reacquire you.", "Select a meeting site so you can overlook the scene.", "Only approach the site when you are sure it is clean.", "Be aware of surveillance's time tolerance so they aren't forced to raise an alert.", "Let them believe they lost you; act innocent.", "There is no limit to a human being's ability to rationalize the truth.", "Use misdirection, illusion, and deception.", "Assume Nothing.","Never go against your gut.", "Everyone is potentially under opposition control.", "Do not look back; you are never completely alone.", "Go with the flow, blend in.", "Vary your pattern and stay within your cover.", "Lull them into a sense of complancency.", "Do not harass the opposition.", "Pick the time and place for action.", "Keep your options open.", "Murphy is right.", "Never go against your gut; it is your operational antenna."]
var index = 0;
function updateQuote() {
index = index + 1;
if(index == quotes.length) {
index = 0;
}
document.getElementById("myQuote").innerHTML = quotes[index];
}
function WordShuffler(holder,opt){
var that = this;
var time = 0;
this.now;
this.then = Date.now();
this.delta;
this.currentTimeOffset = 0;
this.word = null;
this.currentWord = null;
this.currentCharacter = 0;
this.currentWordLength = 0;
var options = {
fps : 10,
timeOffset : 5,
textColor : '#A8A292',
fontSize : "50px",
useCanvas : false,
mixCapital : false,
mixSpecialCharacters : false,
needUpdate : true,
colors : [
'#A8A292', '#A8A292'
]
}
if(typeof opt != "undefined"){
for(key in opt){
options[key] = opt[key];
}
}
this.needUpdate = true;
this.fps = options.fps;
this.interval = 1000/this.fps;
this.timeOffset = options.timeOffset;
this.textColor = options.textColor;
this.fontSize = options.fontSize;
this.mixCapital = options.mixCapital;
this.mixSpecialCharacters = options.mixSpecialCharacters;
this.colors = options.colors;
this.useCanvas = options.useCanvas;
this.chars = [
'A','B','C','D',
'E','F','G','H',
'I','J','K','L',
'M','N','O','P',
'Q','R','S','T',
'U','V','W','X',
'Y','Z'
];
this.specialCharacters = [
'!','§','$','%',
'&','/','(',')',
'=','?','_','<',
'>','^','°','*',
'#','-',':',';','~'
]
if(this.mixSpecialCharacters){
this.chars = this.chars.concat(this.specialCharacters);
}
this.getRandomColor = function () {
var randNum = Math.floor( Math.random() * this.colors.length );
return this.colors[randNum];
}
//if Canvas
this.position = {
x : 0,
y : 50
}
//if DOM
if(typeof holder != "undefined"){
this.holder = holder;
}
if(!this.useCanvas && typeof this.holder == "undefined"){
console.warn('Holder must be defined in DOM Mode. Use Canvas or define Holder');
}
this.getRandCharacter = function(characterToReplace){
if(characterToReplace == " "){
return ' ';
}
var randNum = Math.floor(Math.random() * this.chars.length);
var lowChoice = -.5 + Math.random();
var picketCharacter = this.chars[randNum];
var choosen = picketCharacter.toLowerCase();
if(this.mixCapital){
choosen = lowChoice < 0 ? picketCharacter.toLowerCase() : picketCharacter;
}
return choosen;
}
this.writeWord = function(word){
this.word = word;
this.currentWord = word.split('');
this.currentWordLength = this.currentWord.length;
}
this.generateSingleCharacter = function (color,character) {
var span = document.createElement('span');
span.style.color = color;
span.innerHTML = character;
return span;
}
this.updateCharacter = function (time) {
this.now = Date.now();
this.delta = this.now - this.then;
if (this.delta > this.interval) {
this.currentTimeOffset++;
var word = [];
if(this.currentTimeOffset === this.timeOffset && this.currentCharacter !== this.currentWordLength){
this.currentCharacter++;
this.currentTimeOffset = 0;
}
for(var k=0;k<this.currentCharacter;k++){
word.push(this.currentWord[k]);
}
for(var i=0;i<this.currentWordLength - this.currentCharacter;i++){
word.push(this.getRandCharacter(this.currentWord[this.currentCharacter+i]));
}
if(that.useCanvas){
c.clearRect(0,0,stage.x * stage.dpr , stage.y * stage.dpr);
c.font = that.fontSize + " sans-serif";
var spacing = 0;
word.forEach(function (w,index) {
if(index > that.currentCharacter){
c.fillStyle = that.getRandomColor();
}else{
c.fillStyle = that.textColor;
}
c.fillText(w, that.position.x + spacing, that.position.y);
spacing += c.measureText(w).width;
});
}else{
if(that.currentCharacter === that.currentWordLength){
that.needUpdate = false;
}
this.holder.innerHTML = '';
word.forEach(function (w,index) {
var color = null
if(index > that.currentCharacter){
color = that.getRandomColor();
}else{
color = that.textColor;
}
that.holder.appendChild(that.generateSingleCharacter(color, w));
});
}
this.then = this.now - (this.delta % this.interval);
}
}
this.restart = function () {
this.currentCharacter = 0;
this.needUpdate = true;
}
function update(time) {
time++;
if(that.needUpdate){
that.updateCharacter(time);
}
requestAnimationFrame(update);
}
this.writeWord(this.holder.innerHTML);
console.log(this.currentWord);
update(time);
}
var headline = document.getElementById('headline');
var shuffler = document.getElementById('shuffler');
var headText = new WordShuffler(headline,{
textColor : '#D9D4CE',
timeOffset : 18,
mixCapital : true,
mixSpecialCharacters : true
});
var pText = new WordShuffler(text,{
textColor : 'black',
timeOffset : 2
});
var buttonText = new WordShuffler(shuffler,{
textColor : 'black',
timeOffset : 10
});
shuffler.addEventListener('click',function () {
headText.restart();
pText.restart();
buttonText.restart();
});
</script>
<div style="width:20px;
height:10px;
position:absolute;
right:70px;
bottom:120px;"><h2><a href="https://github.com/dbateyko/Moscow-Rules">?</a></h2></div>
<!-- based on Random Text Shuffle. https://codepen.io/SaschaSigl/pen/woGYKJ -->