JSDM

HTML

 
1
<canvas id="canvas"></canvas>

CSS

xxxxxxxxxx
6
 
1
body {
2
  margin: 0;
3
  padding: 0;
4
  overflow: hidden;
5
  background-color: rgb(44, 62, 80);
6
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

x
 
1
var canvas = document.getElementById('canvas');
2
var ctx = canvas.getContext('2d');
3
4
'floor|random|round|abs|sqrt|PI|atan2|sin|cos|pow|max|min'
5
  .split('|')
6
  .forEach(function(p) { window[p] = Math[p]; });
7
8
var TAU = PI*2;
9
10
function r(n) { return random()*n; }
11
function rint(lo, hi) {
12
  return lo + floor(r(hi - lo + 1))
13
}
14
function choose() {
15
  return arguments[rint(0, arguments.length-1)];
16
}
17
18
/*---------------------------------------------------------------------------*/
19
20
var W, H, frame, t0, time;
21
22
function resize() {  
23
  W = canvas.width = innerWidth;
24
  H = canvas.height = innerHeight;
25
}
26
27
function loop(t) {
28
  frame = requestAnimationFrame(loop);
29
  draw();
30
  time++;
31
}
32
33
function pause() {
34
  cancelAnimationFrame(frame);
35
  frame = frame ? null : requestAnimationFrame(loop);
36
}
37
38
function reset() {
39
  cancelAnimationFrame(frame);
40
  resize();
41
  ctx.clearRect(0, 0, W, H);
42
  init();
43
  time = 0;
44
  frame = requestAnimationFrame(loop);
45
}
46
47
/*---------------------------------------------------------------------------*/
48
49
function circle(x, y, r) {
50
  ctx.beginPath();
51
  ctx.arc(x, y, r, 0, TAU);
52
  ctx.fill();
53
}
54
55
function line(x1, y1, x2, y2, w) {
56
  if (!w) return;
57
  ctx.lineWidth = w;
58
  ctx.beginPath();
59
  ctx.moveTo(x1, y1);
60
  ctx.lineTo(x2, y2);
61
  ctx.stroke();
62
}
63
64
function concentrics(x, y, radius, step) {
65
  while (y += step, radius -= step, radius > 0)
66
    circle(x, y, radius);
67
}
68
69
function dot(r, t) {
70
  t = t < 0 ? 0 : t > 1 ? 1 : ease(t);
71
  var y = r*(t*2 - 1);
72
  circle(0, y, 5);
73
  line(0, 0, 0, y, 5 * (1 - abs(y)/r));
74
}
75
76
function ease(t) {
77
  return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1
78
}
79
80
/*---------------------------------------------------------------------------*/
81
82
var t, dt;
83
var Radius;
84
var dots;
85
86
function init() {
87
  ctx.setTransform(1, 0, 0, 1, 0, 0);
88
  ctx.translate(W/2, H/2);
89
  
90
  Radius = floor(min(W, H) / 2.5);
91
  dots = [];
92
  initDots();
93
  
94
  t = 0;
95
  dt = 0.01;
96
  
97
  ctx.fillStyle = 'white';
98
  ctx.strokeStyle = 'rgba(255, 255, 255, 0.5)';
99
}
100
101
function initDots() {
102
  for (var i = 0; i < 64; i++) dots[i] = - i/64;
103
}
104
105
function draw() {
106
  ctx.clearRect(-W/2, -H/2, W, H);
107
  ctx.save();
108
  ctx.rotate(t * PI);
109
  for (var i = 0; i < dots.length; i++) {
110
    ctx.save();
111
    ctx.rotate(i * TAU / dots.length);
112
    dot(Radius, dots[i]);
113
    dots[i] += dt;
114
    ctx.restore();
115
  }
116
  ctx.restore();
117
  if ((t+=dt) >= 2) {
118
    t = 0;
119
    initDots();
120
  }
121
}
122
123
/*---------------------------------------------------------------------------*/
124
125
document.onclick = pause;
126
document.ondblclick = reset;
127
128
reset();
129
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

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