2016-04-19

聚沙

一段代码

多年前看过,没怎么看懂,现在已经好很多了

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
[].forEach.call($$('*'),function(a){
  a.style.outline='1px solid #'+(~~(Math.random()*(1<<24))).toString(16)
})


var wrong = [];
for (var i = 0; i < 100; i++ ) {
  var hex = (~~(Math.random()*(1<<24))).toString(16);

  if (hex.length < 6 ) {
    wrong.push(hex);
  }
}
console.log(wrong)

[].forEach.call($$('*'),function(a) {
  var random = Math.random();

  if (random < (1 / (1 << 4)) ) {
    // random += 0.7;
    console.log(random)
  }
  var color = (~~(random * (1<<24))).toString(16);

  if (color.length < 6) {
    a.style.outline = '10px solid #' + color + 'a';
    console.log(color, a)
  } else {
    a.style.outline = '1px solid #' + color;
  }

})

Comments