-
Notifications
You must be signed in to change notification settings - Fork 27
/
flames.html
232 lines (207 loc) · 9.56 KB
/
flames.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
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta name="mainWindow" content="user-scalable=no">
<script src="easeljs-0.6.0.min.js"></script>
<script type="text/javascript">
var CJS_TICKER_FPS =27;
var FIRE_WIDTH = 320;
var FIRE_HEIGHT = 168
var palette = [];
// Palette based framebuffer. Coordinate system origin upper-left.
var firePixels = [];
var rgbs = [
0x07,0x07,0x07,
0x1F,0x07,0x07,
0x2F,0x0F,0x07,
0x47,0x0F,0x07,
0x57,0x17,0x07,
0x67,0x1F,0x07,
0x77,0x1F,0x07,
0x8F,0x27,0x07,
0x9F,0x2F,0x07,
0xAF,0x3F,0x07,
0xBF,0x47,0x07,
0xC7,0x47,0x07,
0xDF,0x4F,0x07,
0xDF,0x57,0x07,
0xDF,0x57,0x07,
0xD7,0x5F,0x07,
0xD7,0x5F,0x07,
0xD7,0x67,0x0F,
0xCF,0x6F,0x0F,
0xCF,0x77,0x0F,
0xCF,0x7F,0x0F,
0xCF,0x87,0x17,
0xC7,0x87,0x17,
0xC7,0x8F,0x17,
0xC7,0x97,0x1F,
0xBF,0x9F,0x1F,
0xBF,0x9F,0x1F,
0xBF,0xA7,0x27,
0xBF,0xA7,0x27,
0xBF,0xAF,0x2F,
0xB7,0xAF,0x2F,
0xB7,0xB7,0x2F,
0xB7,0xB7,0x37,
0xCF,0xCF,0x6F,
0xDF,0xDF,0x9F,
0xEF,0xEF,0xC7,
0xFF,0xFF,0xFF
];
// Populate pallete.
for(var i = 0; i < rgbs.length / 3; i++) {
palette[i] = {
r : rgbs[i * 3 + 0],
g : rgbs[i * 3 + 1],
b : rgbs[i * 3 + 2]
}
}
y_scrolling = 440;
function setup() {
// Set whole screen to 0 (color: 0x07,0x07,0x07)
for(var i = 0; i < FIRE_WIDTH*FIRE_HEIGHT; i++) {
firePixels[i] = 0;
}
// Set bottom line to 36 (color white: 0xFF,0xFF,0xFF)
for(var i = 0; i < FIRE_WIDTH; i++) {
firePixels[(FIRE_HEIGHT-1)*FIRE_WIDTH + i] = 36;
}
y_scrolling = 440;
}
function start() {
stage = new createjs.Stage("backbuffer");
createjs.Ticker.addEventListener("tick", hostFrame);
createjs.Ticker.setFPS(CJS_TICKER_FPS);
container = new createjs.Container();
stage.addChild(container);
setup();
}
/***********************************************/
/**************** MEAT STARTS HERE *************/
function spreadFire(src) {
var pixel = firePixels[src];
if(pixel == 0) {
firePixels[src - FIRE_WIDTH] = 0;
} else {
var randIdx = Math.round(Math.random() * 3.0);// & 3;
var dst = src - randIdx + 1;
firePixels[dst - FIRE_WIDTH ] = pixel - (randIdx & 1);
}
}
function doFire() {
for(x=0 ; x < FIRE_WIDTH; x++) {
for (y = 1; y < FIRE_HEIGHT; y++) {
spreadFire(y * FIRE_WIDTH + x);
}
}
}
/***********************************************/
/*************** MEAT ENDS HERE ****************/
/***********************************************/
y_scrolling = 540;
function hostFrame() {
// Update palette buffer
doFire();
canvas = document.getElementById('backbuffer')
color = canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height);
// Convert palette buffer to RGB and write it to ouput.
for(var y = 0; y < canvas.height; y++) {
for(var x = 0; x < canvas.width; x++) {
var index = firePixels[y * canvas.width + x];
var pixel = palette[index];
color.data[((canvas.width * y) + x) * 4 + 0] = pixel.r;
color.data[((canvas.width * y) + x) * 4 + 1] = pixel.g;
color.data[((canvas.width * y) + x) * 4 + 2] = pixel.b;
if (pixel.r == 0x07 && pixel.g == 0x07 && pixel.b == 0x07) {
color.data[((canvas.width * y) + x) * 4 + 3] = 0;
} else
// Black pixels need to be transparent to show DOOM logo
color.data[((canvas.width * y) + x) * 4 + 3] = 255;
}
}
canvas.getContext("2d").putImageData(color, 0, 0);
var frontbuffer = document.getElementById('frontbuffer');
frontbuffer.getContext("2d").fillStyle = 'black';
frontbuffer.getContext("2d").fillRect(0, 0, frontbuffer.width, frontbuffer.height);
frontbuffer.getContext("2d").imageSmoothingEnabled = false;
frontbuffer.getContext("2d").drawImage(document.getElementById('doom'), 50, y_scrolling, (frontbuffer.width - 100) , frontbuffer.height/2);
frontbuffer.getContext("2d").drawImage(canvas,0,0, frontbuffer.width, frontbuffer.height);
if (y_scrolling != 70)
y_scrolling-=2;
else {
// Stop fire
for(var y = 167; y > 160; y--) {
for(var x = 0; x < canvas.width; x++) {
if (firePixels[y * canvas.width + x] > 0)
firePixels[y * canvas.width + x]-= Math.round(Math.random()) & 3;
else {
// Stop animation altogether
//createjs.Ticker.setFPS(0);
}
}
}
}
// Swap buffer
stage.update();
}
</script>
</head>
<body onload="start();">
<canvas id="backbuffer" width="320" height="168" style="border: 1px solid black;" hidden=true></canvas>
<img id='doom' src="doom.png" width="379" height="260" hidden=1/>
<style>
td {
height: 15px;
font-size:0px;
border: 1px solid black;
}
table {
border-collapse: collapse;
}
</style>
<table>
<tr><td>
<canvas id="frontbuffer" width="640" height="509" style="border: 1px solid black;"></canvas>
</td>
<td>
<table width=40 border=1>
<tr><td style="background-color: #070707"> tabtabdssfsgsd</td></tr>
<tr><td style="background-color: #1f0707"> </td></tr>
<tr><td style="background-color: #2f0f07"> </td></tr>
<tr><td style="background-color: #571707"> </td></tr>
<tr><td style="background-color: #671f07"> </td></tr>
<tr><td style="background-color: #771f07"> </td></tr>
<tr><td style="background-color: #8f2707"> </td></tr>
<tr><td style="background-color: #9f2f07"> </td></tr>
<tr><td style="background-color: #af3f07"> </td></tr>
<tr><td style="background-color: #bf4707"> </td></tr>
<tr><td style="background-color: #c74707"> </td></tr>
<tr><td style="background-color: #df4f07"> </td></tr>
<tr><td style="background-color: #df5707"> </td></tr>
<tr><td style="background-color: #df5707"> </td></tr>
<tr><td style="background-color: #d7670f"> </td></tr>
<tr><td style="background-color: #cf6f0f"> </td></tr>
<tr><td style="background-color: #cf770f"> </td></tr>
<tr><td style="background-color: #cf7f0f"> </td></tr>
<tr><td style="background-color: #CF8717"> </td></tr>
<tr><td style="background-color: #C78717"> </td></tr>
<tr><td style="background-color: #C78F17"> </td></tr>
<tr><td style="background-color: #C7971F"> </td></tr>
<tr><td style="background-color: #BF9F1F"> </td></tr>
<tr><td style="background-color: #BF9F1F"> </td></tr>
<tr><td style="background-color: #BFA727"> </td></tr>
<tr><td style="background-color: #BFA727"> </td></tr>
<tr><td style="background-color: #BFAF2F"> </td></tr>
<tr><td style="background-color: #B7AF2F"> </td></tr>
<tr><td style="background-color: #B7B72F"> </td></tr>
<tr><td style="background-color: #B7B737"> </td></tr>
<tr><td style="background-color: #CFCF6F"> </td></tr>
<tr><td style="background-color: #DFDF9F"> </td></tr>
<tr><td style="background-color: #EFEFC7"> </td></tr>
<tr><td style="background-color: #FFFFFF"> </td></tr>
</table>
</td></tr></table>
</body>
</html>