JSDM

HTML

2
 
1
<canvas id="noise"></canvas>
2
  <canvas id="c"></canvas>

CSS

xxxxxxxxxx
17
 
1
*{
2
  padding:0;
3
  margin:0;
4
}
5
html, body{
6
  height:100%;
7
  overflow:hidden;
8
}
9
#c{
10
  position:absolute;
11
  top:5%;
12
}
13
#noise{
14
  position:absolute;
15
  top:0%;
16
  z-index:2;
17
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

90
 
1
var canvas=document.getElementById("c");
2
var ctx=canvas.getContext("2d");
3
var W, H;
4
var colors=[
5
  "#2e942a",
6
  "#e0d041",
7
  "#31a194",
8
  "#ae2c2b",
9
  "#3f4187"
10
];
11
var background="#fbf4e4";
12
var limit=5;
13
function choose(array){
14
  var random=Math.floor(array.length*Math.random());
15
  return array[random];
16
}
17
18
function generateNoise(opacity) {
19
  var noiseCanvas=document.getElementById("noise");
20
  noiseCanvas.width=window.innerWidth;
21
  noiseCanvas.height=window.innerHeight;
22
  noiseCtx=noiseCanvas.getContext("2d");
23
  var x, y;
24
  var number;
25
  for (x=0; x<noiseCanvas.width; x++) {
26
    for (y=0; y<noiseCanvas.height; y++) {
27
      number = Math.floor(Math.random()*60 + 180);
28
      noiseCtx.fillStyle = "rgba(" + number + "," + number + "," + number + "," + opacity + ")";
29
      noiseCtx.fillRect(x, y, 1, 1);
30
    }
31
  }
32
}
33
34
35
36
function resizeCanvas(){
37
  W = window.innerWidth;
38
  H = 0.9*window.innerHeight;
39
  canvas.width = W;
40
  canvas.height = H;
41
}
42
function drawBackground(){
43
  document.body.style.background = background;
44
  ctx.beginPath();
45
  ctx.rect(0, 0, W, H);
46
  ctx.fillStyle = background;
47
  ctx.fill();
48
}
49
50
function sqrt(x){
51
  return Math.pow(x, 0.5);
52
}
53
54
55
function triangle(xTop, yTop, length){
56
  var color=choose(colors);
57
58
  ctx.fillStyle=color;
59
  ctx.beginPath();
60
  ctx.moveTo(xTop, yTop);
61
  ctx.lineTo(xTop + 0.5*length, yTop + length*sqrt(3)/2);
62
  ctx.lineTo(xTop - 0.5*length, yTop + length*sqrt(3)/2);
63
  ctx.lineTo(xTop, yTop);
64
  ctx.closePath();
65
  ctx.fill();
66
}
67
68
function triangles(xTop, yTop, length, i){
69
  if(i==limit){
70
    triangle(xTop, yTop, length/2);
71
    triangle(xTop + 0.5*length/2, yTop + length*sqrt(3)/4, length/2);
72
    triangle(xTop - 0.5*length/2, yTop + length*sqrt(3)/4, length/2);
73
  }else if(i<limit){
74
    i+=1;
75
    triangles(xTop, yTop, length/2, i);
76
    triangles(xTop + 0.5*length/2, yTop + length*sqrt(3)/4, length/2, i);
77
    triangles(xTop - 0.5*length/2, yTop + length*sqrt(3)/4, length/2, i);
78
  }
79
}
80
81
function draw(){
82
  resizeCanvas();
83
  drawBackground();
84
  triangles(W/2,0, H*1.1, 0);
85
}
86
window.onresize=draw;
87
88
89
generateNoise(0.1)
90
draw();
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

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