JSDM

HTML

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

CSS

x
 
1
html,
2
body {
3
  height: 100%;
4
  width: 100%;
5
  margin: 0;
6
  overflow: hidden;
7
}
8
9
#space {
10
  width: 100%
11
}
12
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

xxxxxxxxxx
82
 
1
window.requestAnimFrame = (function(){   return  window.requestAnimationFrame})();
2
var canvas = document.getElementById("space");
3
var c = canvas.getContext("2d");
4
5
var numStars = 1900;
6
var radius = '0.'+Math.floor(Math.random() * 9) + 1  ;
7
var focalLength = canvas.width *2;
8
var warp = 0;
9
var centerX, centerY;
10
11
var stars = [], star;
12
var i;
13
14
var animate = true;
15
16
initializeStars();
17
18
function executeFrame(){
19
  
20
  if(animate)
21
    requestAnimFrame(executeFrame);
22
  moveStars();
23
  drawStars();
24
}
25
26
function initializeStars(){
27
  centerX = canvas.width / 2;
28
  centerY = canvas.height / 2;
29
  
30
  stars = [];
31
  for(i = 0; i < numStars; i++){
32
    star = {
33
      x: Math.random() * canvas.width,
34
      y: Math.random() * canvas.height,
35
      z: Math.random() * canvas.width,
36
      o: '0.'+Math.floor(Math.random() * 99) + 1
37
    };
38
    stars.push(star);
39
  }
40
}
41
42
function moveStars(){
43
  for(i = 0; i < numStars; i++){
44
    star = stars[i];
45
    star.z--;
46
    
47
    if(star.z <= 0){
48
      star.z = canvas.width;
49
    }
50
  }
51
}
52
53
function drawStars(){
54
  var pixelX, pixelY, pixelRadius;
55
  
56
  // Resize to the screen
57
  if(canvas.width != window.innerWidth || canvas.width != window.innerWidth){
58
    canvas.width = window.innerWidth;
59
    canvas.height = window.innerHeight;
60
    initializeStars();
61
  }
62
  if(warp==0)
63
  {c.fillStyle = "rgba(0,0,0,1)";
64
  c.fillRect(0,0, canvas.width, canvas.height);}
65
  for(i = 0; i < numStars; i++){
66
    star = stars[i];
67
    
68
    pixelX = (star.x - centerX) * (focalLength / star.z);
69
    pixelX += centerX;
70
    pixelY = (star.y - centerY) * (focalLength / star.z);
71
    pixelY += centerY;
72
    pixelRadius = 1 * (focalLength / star.z);
73
    
74
    c.fillRect(pixelX, pixelY, pixelRadius, pixelRadius);
75
    c.fillStyle = "rgba(255, 255, 255, "+star.o+")";
76
  }
77
}
78
;
79
80
executeFrame();
81
82
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

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