jmgraph 3.2.5 → 3.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/gulpfile.js +143 -0
- package/build/package-lock.json +19282 -0
- package/build/package.json +71 -0
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +31 -6
- package/dist/jmgraph.min.js +1 -1
- package/docs/_config.yml +1 -0
- package/docs/about.html +41 -0
- package/docs/api/jmGraph.md +2302 -0
- package/docs/css/index.css +131 -0
- package/docs/images/ball.gif +0 -0
- package/docs/images/bezier.gif +0 -0
- package/docs/images/cell.gif +0 -0
- package/docs/images/chart.gif +0 -0
- package/docs/images/editor.gif +0 -0
- package/docs/images/sort.gif +0 -0
- package/docs/index.html +80 -0
- package/docs/js/helper.js +89 -0
- package/docs/js/jquery.min.js +6 -0
- package/example/ball.html +223 -0
- package/example/base.html +112 -0
- package/example/canvas.html +54 -0
- package/example/cell.html +284 -0
- package/example/controls/arc.html +126 -0
- package/example/controls/arrowline.html +77 -0
- package/example/controls/bezier.html +223 -0
- package/example/controls/img.html +90 -0
- package/example/controls/label.html +85 -0
- package/example/controls/line.html +170 -0
- package/example/controls/prismatic.html +63 -0
- package/example/controls/rect.html +64 -0
- package/example/controls/resize.html +75 -0
- package/example/controls/test.html +136 -0
- package/example/es.html +70 -0
- package/example/es5module.html +64 -0
- package/example/heartarc.html +116 -0
- package/example/index.html +46 -0
- package/example/js/require.js +5 -0
- package/example/love/img/bling/bling.tps +265 -0
- package/example/love/img/bling.json +87 -0
- package/example/love/img/bling.tps +295 -0
- package/example/love/img/doc/bling.gif +0 -0
- package/example/love/img/love.json +95 -0
- package/example/love/img/love.tps +315 -0
- package/example/love/img/music/bg.mp3 +0 -0
- package/example/love/img/music/bg_2019130144035.mp3 +0 -0
- package/example/love/img/music/f.mp3 +0 -0
- package/example/love/img/music/fail.mp3 +0 -0
- package/example/love/img/music/s.mp3 +0 -0
- package/example/love/img/music/s_201913014415.mp3 +0 -0
- package/example/love/img/qq/qq.tps +399 -0
- package/example/love/img/qq.json +242 -0
- package/example/love/index.html +40 -0
- package/example/love/js/game.js +558 -0
- package/example/music.html +192 -0
- package/example/node/test.js +138 -0
- package/example/pdf.html +187 -0
- package/example/progress.html +173 -0
- package/example/pso.html +148 -0
- package/example/sort.html +816 -0
- package/example/tweenjs.html +84 -0
- package/example/webgl.html +255 -0
- package/example/xfj/img/dr_die.gif +0 -0
- package/example/xfj/index.html +332 -0
- package/example/xfj/shake.js +49 -0
- package/example/xfj/testori.html +76 -0
- package/package.json +1 -1
- package/src/core/jmControl.js +3 -2
- package/src/core/jmGradient.js +4 -0
- package/src/core/jmGraph.js +6 -4
- package/src/shapes/jmImage.js +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<!--<script type="text/javascript" src="../index.js"></script>
|
|
7
|
+
<script type="text/javascript" src="../dist/jmGraph.min.js"></script> -->
|
|
8
|
+
<style>
|
|
9
|
+
html,body {
|
|
10
|
+
margin:0;
|
|
11
|
+
padding:0;
|
|
12
|
+
width:100%;
|
|
13
|
+
height:100%;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
#mycanvas {
|
|
17
|
+
background-color:#000;
|
|
18
|
+
position: absolute;
|
|
19
|
+
width:100%;
|
|
20
|
+
height:100%;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<div id="mycanvas">
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
31
|
+
|
|
32
|
+
<script type="module">
|
|
33
|
+
import jmGraph from "../index.js";
|
|
34
|
+
var graph = new jmGraph('mycanvas', {
|
|
35
|
+
mode: '2d'
|
|
36
|
+
});
|
|
37
|
+
//初始化jmgraph
|
|
38
|
+
/*jmGraph('mycanvas').then((g)=>{
|
|
39
|
+
graph = g;
|
|
40
|
+
jmUtils.bindEvent(window,'resize',resize);
|
|
41
|
+
refreshBall(g);
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
}); */
|
|
45
|
+
|
|
46
|
+
refreshBall(graph);
|
|
47
|
+
|
|
48
|
+
//实时更新画布
|
|
49
|
+
function update() {
|
|
50
|
+
if(graph && graph.needUpdate) graph.redraw();
|
|
51
|
+
graph.utils.requestAnimationFrame(update);
|
|
52
|
+
}
|
|
53
|
+
update();
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function refreshBall(g) {
|
|
57
|
+
resize();
|
|
58
|
+
|
|
59
|
+
var style = {
|
|
60
|
+
lineWidth: 1.2,
|
|
61
|
+
close:true,
|
|
62
|
+
stroke:'#fff',
|
|
63
|
+
fill:'#05a2e2'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
var balls = [];
|
|
68
|
+
function createPosition(radius,i) {
|
|
69
|
+
var x = Math.random() * graph.width + radius;
|
|
70
|
+
var y = Math.random() * graph.height + radius;
|
|
71
|
+
|
|
72
|
+
for(var j=i+1;j<balls.length;j++) {
|
|
73
|
+
var b2= balls[j];
|
|
74
|
+
var lx = Math.abs(x - b2.x());
|
|
75
|
+
var ly = Math.abs(y - b2.y());
|
|
76
|
+
var l = Math.sqrt(lx * lx + ly * ly);
|
|
77
|
+
//如果二个球重叠则放 弃当前球
|
|
78
|
+
if(l < radius + b2.radius) {
|
|
79
|
+
return createPosition(radius);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {x:x,y:y};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for(var i=0;i<10;i++) {
|
|
86
|
+
var radius = Math.random() * 10 + 8;
|
|
87
|
+
var styletmp = graph.util.clone(style);
|
|
88
|
+
styletmp.fill = graph.createRadialGradient(radius,radius,0,radius,radius,radius);
|
|
89
|
+
var rr1 = Math.floor(Math.random() * 255);
|
|
90
|
+
var gg1 = Math.floor(Math.random() * 255);
|
|
91
|
+
var bb1 = Math.floor(Math.random() * 255);
|
|
92
|
+
var rr2 = Math.floor(Math.random() * 255);
|
|
93
|
+
var gg2 = Math.floor(Math.random() * 255);
|
|
94
|
+
var bb2 = Math.floor(Math.random() * 255);
|
|
95
|
+
styletmp.fill.addStop(0,graph.util.toColor(rr1,gg1,bb1));
|
|
96
|
+
styletmp.fill.addStop(1,graph.util.toColor(rr2,gg2,bb2));
|
|
97
|
+
//styletmp.fill = 'r(0.5,0.1)#ccc-#ccc';
|
|
98
|
+
var p = createPosition(radius);
|
|
99
|
+
var b = new ball(graph,p.x,p.y,radius,styletmp);
|
|
100
|
+
b.vx = 0;//Math.random() * 20 - 10;
|
|
101
|
+
b.vy = 0;//Math.random() * 20 - 10;
|
|
102
|
+
//b.ax = 0;
|
|
103
|
+
//b.ay = 0.4;
|
|
104
|
+
balls.push(b);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
var radius = Math.random() * 10 + 6;
|
|
108
|
+
var styletmp = graph.util.clone(style);
|
|
109
|
+
styletmp.fill = graph.createRadialGradient(radius,radius,0,radius,radius,radius);
|
|
110
|
+
styletmp.fill.addStop(0,'#fff');
|
|
111
|
+
styletmp.fill.addStop(1, graph.util.toColor(255,149,255));
|
|
112
|
+
var p = createPosition(radius,0);
|
|
113
|
+
var b = new ball(graph,p.x,p.y,radius,styletmp);
|
|
114
|
+
b.vx = 6;
|
|
115
|
+
b.vy = 4;
|
|
116
|
+
balls.push(b);
|
|
117
|
+
|
|
118
|
+
function animate() {
|
|
119
|
+
var bs = balls;
|
|
120
|
+
var len = bs.length;
|
|
121
|
+
//var mvx = 0;
|
|
122
|
+
//var mvy = 0;
|
|
123
|
+
for(var i=0;i<len;i++) {
|
|
124
|
+
var b1 = bs[i];
|
|
125
|
+
b1.vx += b1.ax;
|
|
126
|
+
b1.vy += b1.ay;
|
|
127
|
+
for(var j=i+1;j<len;j++) {
|
|
128
|
+
var b2= bs[j];
|
|
129
|
+
var lx = b1.x() - b2.x();
|
|
130
|
+
var ly = b1.y() - b2.y();
|
|
131
|
+
var l = Math.sqrt(lx * lx + ly * ly);
|
|
132
|
+
if(l <= b1.radius + b2.radius) {
|
|
133
|
+
var vx = b1.vx;
|
|
134
|
+
var vy = b1.vy;
|
|
135
|
+
var vxb = b2.vx;
|
|
136
|
+
var vyb = b2.vy;
|
|
137
|
+
|
|
138
|
+
var angle = Math.atan2(ly,lx);
|
|
139
|
+
var sine = Math.sin(angle);
|
|
140
|
+
var cosine = Math.cos(angle);
|
|
141
|
+
|
|
142
|
+
var x = 0;
|
|
143
|
+
var y = 0;
|
|
144
|
+
|
|
145
|
+
var xb = lx * cosine + ly * sine;
|
|
146
|
+
var yb = ly * cosine - lx * sine;
|
|
147
|
+
|
|
148
|
+
var vx = b1.vx * cosine + b1.vy * sine;
|
|
149
|
+
var vy = b1.vy * cosine - b1.vx * sine;
|
|
150
|
+
var vxb = b2.vx * cosine + b2.vy * sine;
|
|
151
|
+
var vyb = b2.vy * cosine - b2.vx * sine;
|
|
152
|
+
|
|
153
|
+
var vtotal = vx - vxb;
|
|
154
|
+
|
|
155
|
+
vx = ((b1.radius - b2.radius) * vx + 2 * b2.radius * vxb) / (b1.radius + b2.radius);
|
|
156
|
+
vxb = vtotal + vx;
|
|
157
|
+
|
|
158
|
+
var vx1 = vx * cosine - vy * sine;
|
|
159
|
+
var vy1 = vy * cosine + vx * sine;
|
|
160
|
+
|
|
161
|
+
var vx2 = vxb * cosine - vyb * sine;
|
|
162
|
+
var vy2 = vyb * cosine + vxb * sine;
|
|
163
|
+
|
|
164
|
+
b1.vx = vx1;
|
|
165
|
+
b1.vy = vy1;
|
|
166
|
+
b2.vx = vx2;
|
|
167
|
+
b2.vy = vy2;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
var x = b1.x() + b1.vx;
|
|
171
|
+
var maxX = b1.graph.width - b1.radius ;
|
|
172
|
+
if(x <= b1.radius || x >= maxX) {
|
|
173
|
+
//b1.vy -= 0.4;
|
|
174
|
+
b1.vx *= -1;
|
|
175
|
+
}
|
|
176
|
+
x = Math.max(x,b1.radius);
|
|
177
|
+
x = Math.min(maxX,x);
|
|
178
|
+
b1.x(x);
|
|
179
|
+
var y = b1.y() + b1.vy;
|
|
180
|
+
var maxY = b1.graph.height - b1.radius;
|
|
181
|
+
if(y <= b1.radius || y >= maxY) {
|
|
182
|
+
//if(y >= maxY && b1.vy > 0) {b1.vy -= 1;b1.vx -= 0.4;}
|
|
183
|
+
b1.vy *= -1;
|
|
184
|
+
}
|
|
185
|
+
y = Math.max(y,b1.radius);
|
|
186
|
+
y = Math.min(maxY,y);
|
|
187
|
+
b1.y(y);
|
|
188
|
+
}
|
|
189
|
+
graph.needUpdate = true;
|
|
190
|
+
g.utils.requestAnimationFrame(animate);
|
|
191
|
+
};
|
|
192
|
+
animate();
|
|
193
|
+
}
|
|
194
|
+
function resize() {
|
|
195
|
+
if(graph) {
|
|
196
|
+
graph.width = window.innerWidth - 10;
|
|
197
|
+
graph.height = window.innerHeight - 10;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function ball(graph,x,y,radius,style) {
|
|
202
|
+
this.graph = graph;
|
|
203
|
+
this.radius = radius;
|
|
204
|
+
this.center = {x:x,y:y};
|
|
205
|
+
this.shape = graph.createShape('arc',{style:style,center:this.center,radius:this.radius,anticlockwise:true});
|
|
206
|
+
graph.children.add(this.shape);
|
|
207
|
+
this.shape.canMove(true);
|
|
208
|
+
this.vx = 0;
|
|
209
|
+
this.vy = 0;
|
|
210
|
+
this.ax = 0;
|
|
211
|
+
this.ay = 0;
|
|
212
|
+
|
|
213
|
+
this.x = function(x) {
|
|
214
|
+
if(typeof x !== 'undefined') this.center.x = x;
|
|
215
|
+
return this.center.x;
|
|
216
|
+
}
|
|
217
|
+
this.y = function(y) {
|
|
218
|
+
if(typeof y !== 'undefined') this.center.y = y;
|
|
219
|
+
return this.center.y;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
</script>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
html,body{
|
|
8
|
+
margin:0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
}
|
|
11
|
+
#mycanvas_container{
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
|
|
16
|
+
<script type="text/javascript" src="../dist/jmGraph.min.js"></script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<div id="mycanvas_container"></div>
|
|
20
|
+
</body>
|
|
21
|
+
<script type="text/javascript">
|
|
22
|
+
//import jmGraph from "../index.js";
|
|
23
|
+
|
|
24
|
+
var container = document.getElementById('mycanvas_container');
|
|
25
|
+
|
|
26
|
+
var g = jmGraph.create(container, {
|
|
27
|
+
width: 800,
|
|
28
|
+
height: 600,
|
|
29
|
+
mode: '2d',
|
|
30
|
+
style: {
|
|
31
|
+
fill: '#000'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
init(g);
|
|
35
|
+
|
|
36
|
+
function init(g){
|
|
37
|
+
g.style.fill = '#000'; //画布背景
|
|
38
|
+
var style = {
|
|
39
|
+
stroke:'#46BF86',
|
|
40
|
+
fill: '#556662',
|
|
41
|
+
lineWidth: 1.5
|
|
42
|
+
};
|
|
43
|
+
style.shadow = '0,0,10,#fff';
|
|
44
|
+
style.opacity = 0.2;
|
|
45
|
+
//style.lineCap = 'round';
|
|
46
|
+
|
|
47
|
+
//创建一个方块
|
|
48
|
+
|
|
49
|
+
var rect = g.createShape('rect',{
|
|
50
|
+
style:style,
|
|
51
|
+
position: {x:300,y:100},
|
|
52
|
+
width:100,
|
|
53
|
+
height:100
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
var rect2 = g.createShape('rect',{
|
|
57
|
+
style:style,
|
|
58
|
+
position: {x:'50%',y:'50%'},
|
|
59
|
+
width:50,
|
|
60
|
+
height:50
|
|
61
|
+
});
|
|
62
|
+
rect.children.add(rect2);
|
|
63
|
+
|
|
64
|
+
g.children.add(rect);
|
|
65
|
+
rect.canMove(true);
|
|
66
|
+
|
|
67
|
+
// 画二个五角星
|
|
68
|
+
var coordinates = [
|
|
69
|
+
{x:50,y:100},
|
|
70
|
+
{x:250,y:100},
|
|
71
|
+
{x:250,y:50},
|
|
72
|
+
{x:300,y:200},
|
|
73
|
+
{x:200,y:200},
|
|
74
|
+
{x:50,y:300},
|
|
75
|
+
];
|
|
76
|
+
style = g.utils.clone(style);
|
|
77
|
+
var star1 = g.createShape('path',{
|
|
78
|
+
style:style,
|
|
79
|
+
points: coordinates
|
|
80
|
+
});
|
|
81
|
+
g.children.add(star1);
|
|
82
|
+
star1.canMove(true);
|
|
83
|
+
|
|
84
|
+
var coordinates2 = [
|
|
85
|
+
{x:50,y:300},
|
|
86
|
+
{x:250,y:300},
|
|
87
|
+
{x:100,y:350},
|
|
88
|
+
{x:150,y:250},
|
|
89
|
+
{x:200,y:350},
|
|
90
|
+
{x:50,y:300},
|
|
91
|
+
];
|
|
92
|
+
style = g.utils.clone(style);
|
|
93
|
+
delete style.fill;
|
|
94
|
+
var star2 = g.createShape('path',{
|
|
95
|
+
style:style,
|
|
96
|
+
points: coordinates2
|
|
97
|
+
});
|
|
98
|
+
g.children.add(star2);
|
|
99
|
+
star2.canMove(true);
|
|
100
|
+
|
|
101
|
+
function update() {
|
|
102
|
+
if(g.needUpdate) {
|
|
103
|
+
console.log(coordinates);
|
|
104
|
+
g.redraw();
|
|
105
|
+
}
|
|
106
|
+
requestAnimationFrame(update);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
update();
|
|
110
|
+
}
|
|
111
|
+
</script>
|
|
112
|
+
</html>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<!--<script type="text/javascript" src="../index.js"></script>
|
|
7
|
+
<script type="text/javascript" src="../dist/jmGraph.min.js"></script> -->
|
|
8
|
+
<style>
|
|
9
|
+
html,body {
|
|
10
|
+
margin:0;
|
|
11
|
+
padding:0;
|
|
12
|
+
width:100%;
|
|
13
|
+
height:100%;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
#mycanvas {
|
|
17
|
+
background-color:#000;
|
|
18
|
+
position: absolute;
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
21
|
+
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<canvas id="mycanvas" width="300" height="200">
|
|
25
|
+
</canvas>
|
|
26
|
+
<script>
|
|
27
|
+
var mycanvas = document.getElementById('mycanvas');
|
|
28
|
+
var w = mycanvas.width;
|
|
29
|
+
var h = mycanvas.height;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var ctx = mycanvas.getContext('2d');
|
|
33
|
+
function resize(w, h) {
|
|
34
|
+
var size = 3;
|
|
35
|
+
mycanvas.width = w * size;
|
|
36
|
+
mycanvas.height = h * size;
|
|
37
|
+
|
|
38
|
+
mycanvas.style.width = w + 'px';
|
|
39
|
+
mycanvas.style.height = h + 'px';
|
|
40
|
+
ctx.scale(size, size);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
resize(w, h); resize(w, h); resize(w, h); resize(w, h); resize(w, h);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
ctx.fillStyle = "rgb(200,0,0)";
|
|
47
|
+
//绘制矩形
|
|
48
|
+
ctx.fillRect (100, 50, 55, 50);
|
|
49
|
+
|
|
50
|
+
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
|
|
51
|
+
ctx.fillRect (150, 80, 55, 50);
|
|
52
|
+
</script>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<!--<script type="text/javascript" src="../src/jmGraph.js"></script>
|
|
7
|
+
<script type="text/javascript" src="../dist/jmGraph.min.js"></script> -->
|
|
8
|
+
<style>
|
|
9
|
+
html,body {
|
|
10
|
+
margin:0;
|
|
11
|
+
padding:0;
|
|
12
|
+
width:100%;
|
|
13
|
+
height:100%;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
#mycanvas {
|
|
17
|
+
background-color:#000;
|
|
18
|
+
position: absolute;
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: 100%;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
|
|
24
|
+
</head>
|
|
25
|
+
<body >
|
|
26
|
+
<div id="mycanvas">
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
31
|
+
|
|
32
|
+
<script type="module">
|
|
33
|
+
import jmGraph from "../index.js";
|
|
34
|
+
var graph;
|
|
35
|
+
var balls = [];
|
|
36
|
+
//初始化jmgraph
|
|
37
|
+
var graph = new jmGraph('mycanvas', {
|
|
38
|
+
mode: '2d'
|
|
39
|
+
});
|
|
40
|
+
graph.util.bindEvent(window,'resize',resize);
|
|
41
|
+
|
|
42
|
+
refreshBall(graph);
|
|
43
|
+
|
|
44
|
+
//实时更新画布
|
|
45
|
+
function update() {
|
|
46
|
+
if(graph.needUpdate) graph.redraw();
|
|
47
|
+
graph.requestAnimationFrame(update);
|
|
48
|
+
}
|
|
49
|
+
update();
|
|
50
|
+
|
|
51
|
+
function createPosition(radius,i) {
|
|
52
|
+
var canvas = document.getElementById('mycanvas');
|
|
53
|
+
var x = Math.random() * graph.width + radius;
|
|
54
|
+
var y = Math.random() * graph.height + radius;
|
|
55
|
+
|
|
56
|
+
for(var j=i+1;j<balls.length;j++) {
|
|
57
|
+
var b2= balls[j];
|
|
58
|
+
var lx = Math.abs(x - b2.x());
|
|
59
|
+
var ly = Math.abs(y - b2.y());
|
|
60
|
+
var l = Math.sqrt(lx * lx + ly * ly);
|
|
61
|
+
//如果二个球重叠则放 弃当前球
|
|
62
|
+
if(l < radius + b2.radius) {
|
|
63
|
+
return createPosition(radius);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {x:x,y:y};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createCell(x,y,r,style) {
|
|
70
|
+
var c = new cell(graph,x,y,r,style);
|
|
71
|
+
balls.push(c);
|
|
72
|
+
return c;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function refreshBall(g) {
|
|
76
|
+
|
|
77
|
+
var style = {
|
|
78
|
+
lineWidth:1,
|
|
79
|
+
close:true
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
resize();
|
|
83
|
+
|
|
84
|
+
style.shadow = graph.createShadow(0,0,20,'#000');
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
style.fill = graph.createRadialGradient('50%','50%',0,'50%','50%','50%');
|
|
89
|
+
//var rr1 = Math.floor(Math.random() * 255);
|
|
90
|
+
//var gg1 = Math.floor(Math.random() * 255);
|
|
91
|
+
//var bb1 = Math.floor(Math.random() * 255);
|
|
92
|
+
//var rr2 = Math.floor(Math.random() * 255);
|
|
93
|
+
//var gg2 = Math.floor(Math.random() * 255);
|
|
94
|
+
//var bb2 = Math.floor(Math.random() * 255);
|
|
95
|
+
style.fill.addStop(0,'rgb(112,154,22)');
|
|
96
|
+
style.fill.addStop(1,'rgb(49,95,118)');
|
|
97
|
+
|
|
98
|
+
var count = 100;
|
|
99
|
+
|
|
100
|
+
for(var i=0; i<count; i++) {
|
|
101
|
+
var radius = Math.random() * 10 + 4;
|
|
102
|
+
|
|
103
|
+
var p = createPosition(radius);
|
|
104
|
+
var b = createCell(p.x, p.y, radius, style);
|
|
105
|
+
b.vx = Math.random() - Math.random();
|
|
106
|
+
b.vy = Math.random() - Math.random();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
//var radius = Math.random() * 10 + 6;
|
|
111
|
+
var styletmp = graph.util.clone(style);
|
|
112
|
+
styletmp.fill = graph.createRadialGradient('50%','50%',0,'50%','50%','50%');
|
|
113
|
+
styletmp.fill.addStop(0,'rgb(255,255,255)');
|
|
114
|
+
styletmp.fill.addStop(1,'rgb(255,149,255)');
|
|
115
|
+
|
|
116
|
+
//主体细胞
|
|
117
|
+
var myCell = createCell(graph.width / 2,graph.height / 2,14,styletmp);//new cell(graph,graph.width() / 2,graph.height() / 2,10,styletmp);
|
|
118
|
+
|
|
119
|
+
//balls.push(myCell);
|
|
120
|
+
|
|
121
|
+
graph.bind('click',function(evt) {
|
|
122
|
+
var x = evt.position.x;
|
|
123
|
+
var y = evt.position.y;
|
|
124
|
+
myCell.go(x,y);
|
|
125
|
+
return false;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
function animate() {
|
|
129
|
+
var bs = balls;
|
|
130
|
+
var len = bs.length;
|
|
131
|
+
//var mvx = 0;
|
|
132
|
+
//var mvy = 0;
|
|
133
|
+
for(var i=0;i<len;i++) {
|
|
134
|
+
var b1 = bs[i];
|
|
135
|
+
if(!b1 || !b1.visible) continue;
|
|
136
|
+
b1.vx += b1.ax;
|
|
137
|
+
b1.vy += b1.ay;
|
|
138
|
+
for(var j=i+1;j<len;j++) {
|
|
139
|
+
var b2= bs[j];
|
|
140
|
+
if(!b2 || !b2.visible) continue;
|
|
141
|
+
var lx = b1.x() - b2.x();
|
|
142
|
+
var ly = b1.y() - b2.y();
|
|
143
|
+
var l = Math.sqrt(lx * lx + ly * ly);
|
|
144
|
+
var lr = b1.radius() + b2.radius();
|
|
145
|
+
var dr = (lr - l) / 2;
|
|
146
|
+
if(dr > 0) {
|
|
147
|
+
var vx = b1.vx;
|
|
148
|
+
var vy = b1.vy;
|
|
149
|
+
var vxb = b2.vx;
|
|
150
|
+
var vyb = b2.vy;
|
|
151
|
+
|
|
152
|
+
var bigB,smallB;
|
|
153
|
+
var smallindex = i;
|
|
154
|
+
if(b1.radius() > b2.radius()) {
|
|
155
|
+
bigB = b1;
|
|
156
|
+
smallB = b2;
|
|
157
|
+
smallindex = j;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
bigB = b2;
|
|
161
|
+
smallB = b1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
var smr = smallB.radius() - dr;
|
|
165
|
+
var darea = 0;
|
|
166
|
+
if(smr > 0) {
|
|
167
|
+
darea = smallB.radius() * smallB.radius() - smr * smr;
|
|
168
|
+
smallB.radius(smr);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
darea = smallB.radius() * smallB.radius();
|
|
172
|
+
dr = smallB.radius();
|
|
173
|
+
smallB.visible(false);
|
|
174
|
+
balls.splice(smallindex,1);
|
|
175
|
+
}
|
|
176
|
+
var bigr = Math.sqrt(bigB.radius() * bigB.radius() + darea);
|
|
177
|
+
|
|
178
|
+
bigB.vx = (bigB.radius() * bigB.vx + dr * smallB.vx) / bigr;
|
|
179
|
+
bigB.vy = (bigB.radius() * bigB.vy + dr * smallB.vy) / bigr;
|
|
180
|
+
bigB.radius(bigr);
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if(!b1.visible) continue;
|
|
186
|
+
var x = b1.x() + b1.vx;
|
|
187
|
+
var maxX = b1.graph.width - b1.radius();
|
|
188
|
+
if(x <= b1.radius() || x >= maxX) {
|
|
189
|
+
//b1.vy -= 0.4;
|
|
190
|
+
b1.vx *= -1;
|
|
191
|
+
}
|
|
192
|
+
x = Math.max(x,b1.radius());
|
|
193
|
+
x = Math.min(maxX,x);
|
|
194
|
+
b1.x(x);
|
|
195
|
+
var y = b1.y() + b1.vy;
|
|
196
|
+
var maxY = b1.graph.height - b1.radius();
|
|
197
|
+
if(y <= b1.radius() || y >= maxY) {
|
|
198
|
+
//if(y >= maxY && b1.vy > 0) {b1.vy -= 1;b1.vx -= 0.4;}
|
|
199
|
+
b1.vy *= -1;
|
|
200
|
+
}
|
|
201
|
+
y = Math.max(y,b1.radius());
|
|
202
|
+
y = Math.min(maxY,y);
|
|
203
|
+
b1.y(y);
|
|
204
|
+
}
|
|
205
|
+
graph.needUpdate = true;
|
|
206
|
+
setTimeout(animate,20);
|
|
207
|
+
};
|
|
208
|
+
animate();
|
|
209
|
+
}
|
|
210
|
+
function resize() {
|
|
211
|
+
//canvas.width = window.innerWidth;
|
|
212
|
+
//canvas.height = window.innerHeight;
|
|
213
|
+
|
|
214
|
+
if(graph) {
|
|
215
|
+
graph.width = document.getElementById('mycanvas').clientWidth;
|
|
216
|
+
graph.height = document.getElementById('mycanvas').clientHeight;
|
|
217
|
+
graph.needUpdate = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function cell(graph, x, y, radius, style) {
|
|
222
|
+
this.graph = graph;
|
|
223
|
+
|
|
224
|
+
this.center = {x:x,y:y};
|
|
225
|
+
this.shape = graph.createShape('circle',{style:style,center:this.center,radius:radius,anticlockwise:true});
|
|
226
|
+
graph.children.add(this.shape);
|
|
227
|
+
|
|
228
|
+
this.vx = 0;
|
|
229
|
+
this.vy = 0;
|
|
230
|
+
this.ax = 0;
|
|
231
|
+
this.ay = 0;
|
|
232
|
+
|
|
233
|
+
this.go = function(x,y) {
|
|
234
|
+
var r = this.radius();
|
|
235
|
+
if(r <= 4) return;
|
|
236
|
+
|
|
237
|
+
var myx = this.x();
|
|
238
|
+
var myy = this.y();
|
|
239
|
+
|
|
240
|
+
var dx = x - myx;
|
|
241
|
+
var dy = y - myy;
|
|
242
|
+
var dp = Math.sqrt(dx * dx + dy * dy);
|
|
243
|
+
var vx = dx / dp * 1;
|
|
244
|
+
var vy = dy / dp * 1;
|
|
245
|
+
var px = myx + vx * (r + 4);
|
|
246
|
+
var py = myy + vy * (r + 4);
|
|
247
|
+
|
|
248
|
+
var mc = createCell(px,py,1,style);
|
|
249
|
+
mc.vx = vx;
|
|
250
|
+
mc.vy = vy;
|
|
251
|
+
|
|
252
|
+
var radius = Math.sqrt(r * r - mc.radius() * mc.radius());
|
|
253
|
+
this.radius(radius);
|
|
254
|
+
|
|
255
|
+
this.vx = (this.vx * r - mc.vx * mc.radius()) / this.radius();
|
|
256
|
+
this.vy = (this.vy * r - mc.vy * mc.radius()) / this.radius();
|
|
257
|
+
|
|
258
|
+
this.graph.needUpdate = true;
|
|
259
|
+
}
|
|
260
|
+
this.x = function(x) {
|
|
261
|
+
if(typeof x !== 'undefined') this.center.x = x;
|
|
262
|
+
return this.center.x;
|
|
263
|
+
}
|
|
264
|
+
this.y = function(y) {
|
|
265
|
+
if(typeof y !== 'undefined') this.center.y = y;
|
|
266
|
+
return this.center.y;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
this.radius = function(r) {
|
|
270
|
+
if(typeof r == 'undefined') return this.shape.radius;
|
|
271
|
+
return this.shape.radius = r;
|
|
272
|
+
}
|
|
273
|
+
this.visible = function(v) {
|
|
274
|
+
if(typeof v !== 'undefined') {
|
|
275
|
+
this.shape.visible = v;
|
|
276
|
+
if(!v) {
|
|
277
|
+
this.graph.children.remove(this.shape);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return this.shape.visible;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
</script>
|