-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathascii.js
More file actions
89 lines (75 loc) · 2.72 KB
/
ascii.js
File metadata and controls
89 lines (75 loc) · 2.72 KB
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
/*
This file powers ascii.html, displaying animations according to user input.
Animations are loaded from animations.js and myanimation.js.
*/
"use strict";
(function () {
var timer;
var initialAscii;
/* begins timer and displays current animation, triggered by "Start" Play Control */
function startAscii() {
/* correctly keep track of button displays */
document.getElementById("start").disabled = true;
document.getElementById("stop").disabled = false;
/* setup animation */
var textarea = document.getElementById("asciiarea");
initialAscii = textarea.value; /* reflect any user changes */
var allFrames = textarea.value.split("=====\n");
var frameSpeed;
var count = 0;
var userSpeed = document.getElementsByName("speed");
var speeds = userSpeed.length;
for (var i = 0; i < speeds; i++) {
if (userSpeed[i].checked) {
frameSpeed = userSpeed[i].value;
}
}
timer = setInterval(updateAscii, frameSpeed);
/* used by the timer to update animation on each timestep */
function updateAscii() {
for (var i = 0; i < speeds; i++) {
if (userSpeed[i].checked && frameSpeed != userSpeed[i].value) {
frameSpeed = userSpeed[i].value;
clearInterval(timer);
timer = setInterval(updateAscii, frameSpeed);
}
}
textarea.value = allFrames[count];
count++;
if (count > allFrames.length - 1) {
count = 0;
}
}
}
/* ceases the current animation, triggered by "Stop" Play Control */
function stopAscii() {
document.getElementById("start").disabled = false;
document.getElementById("stop").disabled = true;
clearInterval(timer);
document.getElementById("asciiarea").value = initialAscii;
}
/* loads the initial ASCII art into the text area */
function drawAscii() {
var animation = document.getElementById("animation");
var animationChoice = animation.options[animation.selectedIndex].innerHTML;
document.getElementById("asciiarea").value = ANIMATIONS[animationChoice];
}
/* changes font size of the ASCII art in text area, triggered by Size drop-down list */
function sizeChange() {
var size = document.getElementById("size");
var newSize = size.options[size.selectedIndex].value;
document.getElementById("asciiarea").style.fontSize = newSize + "pt";
}
/* setup event listeners when window loads */
window.onload = function() {
var start = document.getElementById("start");
start.onclick = startAscii;
var stop = document.getElementById("stop");
stop.onclick = stopAscii;
stop.disabled = true;
var animation = document.getElementById("animation");
animation.onchange = drawAscii;
var size = document.getElementById("size");
size.onchange = sizeChange;
}
})();