-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain02_3.js
25 lines (25 loc) · 931 Bytes
/
main02_3.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
function main02_3() {
const func = arguments.callee.name || "anonymous";
cls();
println(`${func}`);
var canvas = document.getElementById('canvas');
const w = canvas.width;
const h = canvas.height;
if (canvas.getContext) {
var ctx = canvas.getContext('2d', { alpha: false });
image = ctx.getImageData(0, 0, w, h);
for (let j = 0; j < h; j++) {
println(`Scanlines remaining: ${h - j - 1}`);
for (let i = 0; i < w; i++) {
const r = parseFloat(i) / (w - 1);
const g = parseFloat(h - 1 - j) / (h - 1);
const b = 0.25;
image.data[(j * w + i) * 4 + 0] = 255.999 * r;
image.data[(j * w + i) * 4 + 1] = 255.999 * g;
image.data[(j * w + i) * 4 + 2] = 255.999 * b;
}
}
ctx.putImageData(image, 0, 0);
println(`Done. ${func}`);
}
}