-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-perf.html
225 lines (206 loc) · 12.1 KB
/
test-perf.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
<html>
<head>
<meta charset="utf-8">
<title>GifMinitel demonstration</title>
<!-- Some styling -->
<style>
article {
margin: 0 auto;
padding: 2em;
max-width: 50em;
background: repeating-linear-gradient(
45deg, #EEEEEE, #EEEEEE 1em, #FFFFFF 1em, #FFFFFF 2em
);
text-align: center;
}
h1, h2 { font-family: sans-serif; }
h1 {
margin-top: 0;
font-size: 300%;
}
h2 { font-size: 200%; }
</style>
</head>
<body>
<article>
<h1>GifMinitel demonstration</h1>
<h2>Canvas</h2>
<!-- Frames will be drawn on this canvas. -->
<canvas id="test-canvas" width="320" height="250"></canvas>
<h2>Animated GIF based on the canvas</h2>
<!-- Animated GIF will be installed in this image. -->
<img id="test-img" width="320" height="250">
<h2>About GifMinitel</h2>
<p>
<a href="https://github.com/zigazou/gifminitel">
GifMinitel on Github
</a>
</p>
</article>
<!-- Only one script to import. -->
<script src="gifminitel.js"></script>
<!-- Do the magic. -->
<script>
// Create a new GIF with a delay of 20 milliseconds between frames.
const gifm = new GifMinitel(320, 250, 20)
// Get the canvas on which we will draw each frame.
const canvas = document.getElementById("test-canvas")
// Get the context to draw.
const ctx = canvas.getContext("2d")
// The first frame will be the empty canvas.
gifm.add(ctx.getImageData(0, 0, 320, 250))
// Minitel color palette for random selection.
const colors = ["#FF0000", "#00FF00", "#0000FF", "#000000",
"#FFFF00", "#00FFFF", "#FF00FF", "#FFFFFF"]
// Pre-calculated random numbers to ensure the profiler measures
// really measure the same thing.
const boxes = [
[1, 132, 156], [5, 116, 118], [5, 232, 223], [0, 25, 136],
[0, 218, 195], [3, 5, 10], [0, 103, 229], [6, 147, 217],
[3, 288, 95], [3, 87, 117], [7, 66, 182], [2, 24, 26],
[7, 58, 109], [6, 218, 116], [5, 205, 129], [7, 31, 211],
[4, 233, 136], [2, 180, 225], [3, 211, 242], [7, 7, 226],
[1, 110, 57], [0, 218, 133], [2, 19, 6], [6, 135, 24],
[2, 270, 227], [3, 245, 236], [5, 220, 241], [7, 179, 162],
[2, 233, 69], [3, 227, 226], [7, 82, 240], [2, 194, 98],
[0, 195, 119], [4, 24, 83], [4, 141, 103], [4, 209, 236],
[7, 170, 40], [2, 267, 27], [1, 116, 165], [0, 242, 51],
[7, 32, 166], [6, 185, 244], [4, 127, 224], [0, 269, 95],
[0, 162, 34], [1, 243, 141], [4, 92, 141], [5, 218, 106],
[1, 107, 31], [1, 241, 107], [2, 174, 78], [4, 287, 94],
[7, 224, 179], [6, 76, 75], [7, 201, 79], [2, 28, 24],
[2, 143, 214], [4, 318, 80], [5, 173, 198], [4, 179, 6],
[5, 135, 246], [7, 24, 75], [3, 207, 61], [4, 105, 124],
[0, 223, 220], [7, 126, 67], [3, 0, 145], [2, 153, 180],
[4, 149, 51], [5, 221, 180], [0, 267, 155], [5, 42, 28],
[1, 44, 196], [5, 67, 138], [7, 40, 149], [2, 203, 44],
[1, 279, 14], [3, 113, 243], [1, 236, 172], [2, 316, 164],
[5, 130, 225], [1, 22, 110], [3, 209, 2], [7, 31, 146],
[5, 66, 151], [5, 86, 197], [6, 255, 122], [1, 140, 99],
[4, 73, 44], [1, 189, 202], [7, 279, 121], [7, 202, 215],
[5, 157, 34], [1, 304, 5], [3, 67, 94], [6, 227, 51],
[2, 34, 158], [5, 287, 191], [3, 126, 208], [7, 74, 133],
[4, 54, 187], [2, 203, 124], [1, 149, 220], [6, 130, 163],
[2, 269, 195], [1, 211, 128], [6, 293, 9], [2, 91, 229],
[3, 255, 193], [7, 59, 35], [6, 264, 7], [3, 100, 234],
[6, 19, 209], [0, 125, 24], [5, 277, 40], [6, 183, 56],
[2, 34, 31], [1, 147, 248], [1, 302, 202], [1, 100, 86],
[7, 85, 29], [0, 293, 114], [5, 29, 141], [4, 7, 13],
[3, 196, 230], [1, 247, 88], [7, 80, 180], [4, 100, 25],
[5, 5, 137], [3, 108, 30], [7, 70, 143], [4, 60, 80],
[1, 96, 21], [0, 108, 130], [1, 128, 19], [6, 219, 103],
[1, 200, 95], [4, 178, 141], [5, 196, 116], [6, 124, 8],
[1, 136, 60], [1, 258, 198], [4, 207, 127], [6, 65, 171],
[3, 310, 28], [0, 310, 72], [2, 152, 25], [7, 304, 40],
[7, 175, 165], [2, 213, 110], [3, 281, 132], [1, 294, 211],
[2, 65, 48], [5, 226, 3], [4, 37, 62], [3, 25, 201],
[7, 111, 43], [0, 297, 201], [0, 55, 103], [1, 0, 155],
[3, 70, 31], [5, 21, 120], [1, 50, 23], [4, 284, 206],
[6, 110, 125], [3, 18, 118], [7, 316, 58], [6, 244, 210],
[6, 303, 13], [2, 67, 216], [3, 171, 91], [6, 284, 106],
[0, 80, 30], [1, 183, 165], [7, 187, 24], [1, 79, 203],
[2, 228, 129], [1, 7, 42], [3, 181, 165], [5, 227, 181],
[7, 124, 31], [0, 58, 89], [0, 235, 129], [7, 308, 93],
[5, 105, 57], [5, 277, 111], [4, 89, 9], [4, 178, 114],
[3, 132, 157], [4, 314, 224], [7, 178, 239], [0, 231, 244],
[0, 216, 102], [7, 151, 151], [4, 253, 24], [6, 12, 235],
[1, 30, 156], [1, 257, 59], [5, 78, 211], [0, 108, 118],
[0, 197, 68], [0, 291, 133], [0, 121, 25], [3, 304, 31],
[0, 79, 86], [5, 195, 140], [3, 116, 7], [2, 99, 193],
[0, 282, 188], [6, 288, 133], [7, 202, 219], [2, 299, 247],
[4, 17, 199], [0, 84, 21], [4, 167, 124], [1, 315, 202],
[1, 275, 160], [4, 126, 56], [4, 32, 11], [5, 48, 48],
[0, 231, 215], [0, 94, 82], [6, 18, 228], [0, 115, 51],
[5, 25, 184], [6, 301, 28], [6, 21, 79], [7, 119, 94],
[5, 143, 248], [5, 174, 54], [3, 54, 220], [2, 258, 191],
[6, 273, 182], [0, 214, 38], [4, 277, 39], [7, 110, 128],
[2, 220, 72], [4, 156, 85], [4, 150, 63], [7, 178, 220],
[2, 49, 59], [2, 312, 62], [0, 80, 178], [0, 134, 168],
[6, 83, 120], [5, 32, 50], [3, 82, 175], [6, 191, 87],
[5, 26, 115], [6, 149, 82], [1, 117, 33], [0, 211, 157],
[7, 8, 111], [3, 295, 182], [3, 293, 219], [4, 233, 154],
[4, 121, 216], [4, 137, 123], [2, 217, 89], [6, 244, 125],
[7, 49, 198], [2, 11, 19], [6, 52, 178], [1, 316, 244],
[0, 278, 94], [2, 126, 24], [6, 34, 122], [6, 29, 41],
[3, 94, 117], [3, 209, 48], [1, 188, 167], [2, 247, 167],
[0, 146, 65], [1, 125, 238], [6, 139, 30], [4, 211, 200],
[2, 108, 148], [2, 205, 94], [1, 134, 120], [3, 223, 249],
[2, 168, 21], [5, 142, 241], [4, 301, 79], [1, 290, 64],
[2, 137, 151], [0, 213, 20], [1, 200, 115], [1, 289, 97],
[0, 289, 13], [6, 257, 32], [1, 292, 4], [1, 212, 23],
[4, 253, 235], [4, 137, 101], [1, 226, 205], [3, 306, 25],
[0, 206, 235], [4, 29, 6], [5, 86, 138], [4, 280, 206],
[6, 54, 111], [5, 268, 204], [6, 182, 191], [0, 216, 246],
[0, 258, 133], [3, 3, 84], [2, 180, 38], [6, 11, 10],
[7, 176, 154], [2, 226, 218], [6, 18, 45], [3, 203, 177],
[4, 281, 93], [5, 143, 167], [3, 164, 249], [0, 137, 62],
[2, 87, 157], [7, 211, 227], [4, 296, 155], [3, 131, 145],
[6, 141, 40], [5, 113, 9], [2, 266, 145], [2, 243, 98],
[1, 224, 94], [2, 123, 107], [7, 258, 195], [4, 284, 221],
[5, 174, 172], [0, 6, 2], [1, 283, 227], [0, 19, 238],
[2, 244, 113], [6, 169, 80], [2, 218, 239], [1, 229, 242],
[4, 271, 108], [0, 55, 172], [7, 53, 124], [2, 26, 97],
[5, 297, 67], [4, 97, 152], [3, 261, 195], [0, 93, 203],
[3, 241, 180], [4, 0, 84], [6, 160, 16], [7, 30, 180],
[7, 179, 94], [1, 111, 34], [0, 77, 29], [3, 51, 196],
[6, 32, 92], [1, 160, 153], [6, 142, 76], [4, 246, 121],
[3, 25, 246], [4, 44, 189], [1, 28, 247], [7, 137, 179],
[6, 56, 203], [4, 219, 129], [2, 263, 81], [7, 231, 136],
[1, 238, 136], [3, 27, 220], [7, 49, 23], [0, 194, 16],
[4, 293, 189], [4, 227, 118], [6, 283, 145], [2, 305, 69],
[7, 115, 128], [3, 278, 124], [5, 99, 76], [7, 265, 146],
[0, 181, 75], [7, 158, 137], [5, 6, 88], [4, 240, 159],
[0, 106, 11], [4, 86, 76], [5, 52, 49], [3, 96, 31],
[1, 289, 83], [0, 30, 192], [0, 306, 117], [3, 53, 193],
[2, 23, 227], [4, 228, 154], [6, 82, 156], [1, 28, 137],
[6, 92, 40], [7, 193, 190], [4, 310, 99], [6, 285, 19],
[3, 59, 62], [7, 117, 142], [1, 274, 190], [0, 194, 7],
[1, 120, 3], [2, 117, 158], [5, 162, 173], [3, 196, 17],
[7, 127, 7], [3, 63, 201], [5, 3, 235], [2, 262, 22],
[2, 112, 53], [7, 244, 232], [4, 251, 120], [4, 119, 119],
[7, 304, 88], [5, 121, 98], [2, 272, 150], [2, 159, 129],
[2, 317, 54], [7, 1, 46], [0, 100, 245], [5, 52, 142],
[5, 204, 181], [7, 212, 93], [0, 182, 33], [6, 152, 82],
[1, 32, 215], [7, 224, 144], [5, 22, 80], [6, 124, 249],
[1, 294, 41], [6, 304, 144], [5, 26, 111], [2, 176, 86],
[5, 272, 86], [4, 63, 182], [7, 276, 181], [4, 101, 85],
[7, 13, 157], [1, 314, 243], [3, 86, 184], [1, 255, 179],
[6, 272, 115], [1, 135, 18], [5, 244, 34], [1, 67, 58],
[4, 186, 0], [5, 143, 189], [3, 207, 159], [1, 91, 97],
[3, 146, 133], [6, 208, 119], [0, 220, 13], [1, 273, 236],
[3, 235, 100], [0, 14, 187], [2, 280, 23], [6, 166, 4],
[3, 251, 88], [1, 296, 48], [2, 249, 180], [2, 117, 238],
[6, 146, 33], [1, 188, 198], [4, 285, 108], [1, 171, 237],
[5, 238, 88], [1, 25, 67], [2, 85, 110], [1, 55, 212],
[7, 25, 142], [0, 203, 243], [4, 51, 209], [0, 211, 25],
[5, 307, 93], [2, 211, 140], [6, 58, 230], [6, 140, 167],
[4, 156, 204], [6, 284, 121], [6, 29, 85], [0, 244, 53],
[0, 244, 195], [1, 134, 209], [6, 212, 72], [4, 23, 209],
[3, 267, 200], [7, 191, 103], [0, 219, 62], [6, 80, 159],
[1, 150, 219], [5, 25, 41], [3, 257, 66], [4, 285, 191],
[6, 298, 80], [7, 168, 37], [0, 216, 65], [3, 48, 111],
[0, 60, 238], [3, 261, 119], [4, 25, 187], [6, 178, 148]
]
// Draw 500 frames (500 × 20ms = 10s).
console.time("A")
console.profile("B")
boxes.forEach(([color, x, y]) => {
// Fill with a random color.
ctx.fillStyle = colors[color]
// Draw a 64×64 filled square at a random position.
ctx.fillRect(x, y, 64, 64)
// Add the frame to the animated GIF.
gifm.add(ctx.getImageData(0, 0, 320, 250))
})
// Generate the animated GIF.
const data = gifm.save()
setTimeout(() => console.profileEnd("B"), 10)
console.timeEnd("A")
// Create an object URL from the animated GIF.
const blob = new Blob([data], {type: "image/gif"});
const url = URL.createObjectURL(blob, {type: "image/gif"})
// Show the animated GIF below the canvas.
document.getElementById("test-img").src = url
</script>
</body>
</html>