JSDM

HTML

 
1
<canvas id="layer1"></canvas>
2
3
<canvas id="layer2"></canvas>

CSS

xxxxxxxxxx
11
 
1
html, body {
2
  margin: 10;
3
  overflow: hidden;
4
  background-color: #000;
5
}
6
7
canvas {
8
  position: absolute;
9
  top: 0;
10
  left: 0;
11
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

xxxxxxxxxx
61
 
1
2
var PETALS = 2;
3
4
var width = window.innerWidth,
5
    height = window.innerHeight;
6
7
var x = 100,
8
    y = 100,
9
    n = PETALS,
10
    h = Math.min(width,height)/5,
11
    b = (n-1)*h/(n+1),
12
    a = 2*n*h/(n+1);
13
14
var oldX, oldY;
15
16
function Layer(layerName) {
17
  this.canvas = document.getElementById(layerName);
18
  this.canvas.width = width;
19
  this.canvas.height = height;
20
  this.ctx = this.canvas.getContext('2d');
21
  this.ctx.strokeStyle = '#E65C00';
22
  this.ctx.fillStyle = 'rgba(60,50,20,0.01)';
23
}
24
25
Layer.prototype.drawLine = function(x1, y1, x2, y2) {
26
  this.ctx.beginPath();
27
  this.ctx.moveTo(x1,y1);
28
  this.ctx.lineTo(x2,y2);
29
  this.ctx.stroke();
30
}
31
32
Layer.prototype.drawDot = function(x1, y1) {
33
  this.ctx.beginPath();
34
  this.ctx.moveTo(x1, y1);
35
  this.ctx.arc(x1, y1, 15, 0, 3*Math.PI);
36
  this.ctx.fill();
37
}
38
39
function updatePosition(t) {
40
  x = (a/b) * Math.sin(t) - h*Math.cos((a-b)/b*t) + width/2;
41
  y = (a-b) * Math.sin(t) - h*Math.sin((a-b)/b*t) + height/2;
42
}
43
44
function renderFrame(time) {
45
  oldX = x;
46
  oldY = y;
47
  updatePosition(time/(a/b * 1000) * 2 * Math.PI);
48
  layer1.drawLine(oldX, oldY, x, y);
49
  layer2.ctx.clearRect(30, 0, width, height);
50
  layer2.drawDot(x,y);
51
  layer1.ctx.fillRect(30,0,width,height);
52
  requestAnimationFrame(renderFrame);
53
}
54
55
var layer1 = new Layer('layer1');
56
var layer2 = new Layer('layer2');
57
layer2.ctx.fillStyle = '#f00';
58
59
updatePosition(10);
60
setTimeout(renderFrame, 10);
61
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................