-
Notifications
You must be signed in to change notification settings - Fork 2
/
canvas.html
44 lines (37 loc) · 1.13 KB
/
canvas.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
<!-- vim: sw=2 ts=2 expandtab smartindent ft=javascript
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WebGL Demo</title>
<style> document, body { margin: 0px; padding: 0px; overflow: hidden; } </style>
</head>
<body>
<canvas id="glcanvas"></canvas>
<script>"use strict";
const canvas = document.getElementById("glcanvas");
const ctx = canvas.getContext('2d');
(window.onresize = () => {
canvas.width = window.innerWidth*window.devicePixelRatio,
canvas.height = window.innerHeight*window.devicePixelRatio
canvas.style.width = window.innerWidth + 'px';
canvas.style.height = window.innerHeight + 'px';
})();
requestAnimationFrame(function render(now) {
requestAnimationFrame(render);
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.save();
{
ctx.translate(canvas.width/2, canvas.height/2);
ctx.fillStyle = "red";
ctx.fillRect(-50, -50, 100, 100);
}
ctx.restore();
})
function lerp(v0, v1, t) { return (1 - t) * v0 + t * v1; }
function inv_lerp(min, max, p) { return (p - min) / (max - min); }
</script>
</body>
</html>