-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubleBuff.html
More file actions
54 lines (50 loc) · 1.94 KB
/
Copy pathdoubleBuff.html
File metadata and controls
54 lines (50 loc) · 1.94 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
<!--
To change this template use Tools | Templates.
-->
<!DOCTYPE html>
<html>
<head>
<title>Double Buffering</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=1024" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<!--SCRIPTS-->
<script type="text/javascript">
function draw() {
var canvas1 = document.getElementById('frontBuffer');
var canvas2 = document.getElementById('backBuffer');
// Get a reference to the drawing contexts
var ctx1 = canvas1.getContext('2d');
var ctx2 = canvas2.getContext('2d');
var colors = [ "#01C001", "#0152D8", "#E46F0F", "#868686", "#850065", "#FF0000" ];
var colorIndex = 0;
(function drawFrame(time) {
if( colorIndex >= colors.length ){
colorIndex = 0;
}
//window.requestAnimationFrame(drawFrame);
ctx1.drawImage(canvas2,0,0);
ctx2.fillStyle = colors[ colorIndex ];
ctx2.fillRect(10,10,200,200);
ctx2.fillStyle = "#000";
ctx2.font = "italic 200 100px/2 Unknown Font, sans-serif"
ctx2.fillText(colorIndex, 80, 140);
colorIndex++;
window.setTimeout(drawFrame, 1000);
})();
}
</script>
</head>
<body onload="draw();">
<div style="width:600px">
<div id="back" style="width:50%;float:left;">
<h1>BACK BUFFER</h1>
<canvas id="backBuffer" width="300" height="300"></canvas>
</div>
<div id="front" style="width:50%;float:left;">
<h1>FRONT BUFFER</h1>
<canvas id="frontBuffer" width="300" height="300"></canvas>
</div>
</div>
</body>
</html>