-
Notifications
You must be signed in to change notification settings - Fork 1
/
circle-composite.html
98 lines (86 loc) · 2.17 KB
/
circle-composite.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>
<script type="text/javascript" src="./lib/weRender.min.js"></script>
<script type="text/javascript">
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;
}, [])
}
function generateCircles(colors, width, height){
var actions;
return colors.reduce(function(circles, color, index){
if (index == 0 ) {
var circle = new WeCanvas({
width: width,
height: height,
})
.beginPath()
.fillStyle(color)
.arc(15, 15, 10, 0, 2 * Math.PI)
.fill()
.draw();
actions = circle.getActions();
circles.push(circle);
} else {
circles.push(new WeCanvas({
actions: replaceActions(actions, "fillStyle", color),
width: width,
height: height,
}).draw())
}
return circles;
}, []);
}
var WeStage = weRender.WeStage;
var WeCanvas = weRender.WeCanvas;
var stage = new WeStage(document.querySelector("#canvas"));
stage.setSize(500, 500);
stage.setStyle("500px", "500px");
var width = 30, height = 30;
var colors = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"];
var circles = generateCircles(colors, width, height);
var maxRow = Math.floor(500 / height);
var maxCol = Math.floor(500 / width);
for (var row = 0; row < maxRow; row ++){
for (var col = 0; col < maxCol; col ++) {
stage.addChild({
canvas: circles[ row * col % 7].canvas,
x: col * width + 10,
y: row * height + 10
})
}
}
stage.update();
</script>
</body>
</html>