Html
    Css
    Js
1
<canvas></canvas>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
body,html {
position:absolute;
margin:0;
padding:0;
width:100%;
height:100%;
overflow:hidden;
}
canvas {
position:absolute;
width:100%;
height:100%;
background:#000;
cursor:pointer;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
{
class Robot {
constructor(color, light, size, x, y, struct) {
this.x = x;
this.points = [];
this.links = [];
this.frame = 0;
this.dir = 1;
this.size = size;
this.color = Math.round(color);
this.light = light;
// ---- ----
for (const p of struct.points) {
this.points.push(new Robot.Point(size * p.x + x, size * p.y + y, p.f));
}
// ---- ----
for (const link of struct.links) {
const p0 = this.points[link.p0];
const p1 = this.points[link.p1];
const dx = p0.x - p1.x;
const dy = p0.y - p1.y;
this.links.push(
new Robot.Link(
this,
p0,
p1,
Math.sqrt(dx * dx + dy * dy),
link.size * size / 3,
link.lum,
link.force,
link.disk
)
);
}
}
update() {
if (++this.frame % 20 === 0) this.dir = -this.dir;
if (
dancerDrag &&
this === dancerDrag &&
this.size < 16 &&
this.frame > 600
) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
↑上面代码改变,会自动显示代码结果 jQuery调用版本:1.11.3
 立即下载

原生js实现的魔性机器人

1
      若,0
      2019/12/7 11:05:50
      哈哈哈哈,够魔性 回复