-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
98 lines (88 loc) · 2.01 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>circle</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<style type="text/css">
body{
margin: 0;
}
#container{
height: 100vh;
width: 100vw;
}
#canvas{
background-color: #fad7d7;
}
</style>
</head>
<body>
<div id="container">
<canvas id="canvas"></canvas>
<div>
<p>other examples:</p>
<ul>
<li><a href="./circle-actions.html">reuse actions</a></li>
<li><a href="./circle-clone.html">clone</a></li>
<li><a href="./circle-composite.html">composite</a></li>
<li><a href="./circle-zoom.html">zoom</a></li>
</ul>
</div>
</div>
<script type="text/javascript" src="./lib/weRender.min.js"></script>
<script type="text/javascript">
var raf = window.requestAnimationFrame;
function replaceActions(actions, method, args){
return actions.reduce(function(acc, action){
if (action[1] == method) {
acc.push([
action[0],
method,
[args]
]);
} else {
acc.push(action);
}
return acc;
}, [])
}
var WeStage = weRender.WeStage;
var WeCanvas = weRender.WeCanvas;
var stage = new WeStage(document.querySelector("#canvas"));
stage.setSize(500, 500);
stage.setStyle("500px", "500px");
var yellowCircle = new WeCanvas({
width: 100,
height: 100,
})
.beginPath()
.fillStyle("yellow")
.arc(50, 50, 50, 0, 2 * Math.PI)
.fill()
.draw()
var purpleCircle = new WeCanvas({
actions: replaceActions(yellowCircle.getActions(), "fillStyle", "purple"),
width: 100,
height: 100,
}).draw()
var i = 10000;
function render(){
if (i == 0) return;
i --;
stage.addChild({
canvas: yellowCircle.canvas,
x: 100,
y: 100 + (i % 200) * 2,
});
stage.addChild({
canvas: purpleCircle.canvas,
x: 300,
y: 50 + (i % 300) * 1,
});
stage.update();
raf(render);
}
render();
</script>
</body>
</html>