|
| 1 | +// Messing around with generated gradients |
| 2 | +// Copyright (c) 2010 Brian Arnold |
| 3 | +// MIT License |
| 4 | + |
| 5 | +// Keep global space cleeeeeeean |
| 6 | +(function () { |
| 7 | + function newGrad() { |
| 8 | + var box = document.getElementById('box'), grad = [], start, inc, end, noise, shade; |
| 9 | + |
| 10 | + // A few 'settings' |
| 11 | + start = 0.02; |
| 12 | + end = 1 - start; |
| 13 | + inc = 0.01; |
| 14 | + noise = start + inc; |
| 15 | + |
| 16 | + // Make a gradient bit by bit |
| 17 | + grad.push('linear'); |
| 18 | + grad.push('left top'); |
| 19 | + grad.push('left bottom'); |
| 20 | + grad.push('color-stop(0, rgb(153,153,153))'); |
| 21 | + grad.push('color-stop(' + start + ', rgb(193,193,193))'); |
| 22 | + |
| 23 | + // Introduce some noise! |
| 24 | + while (noise < end) { |
| 25 | + // Figure out a new shade |
| 26 | + shade = Math.floor(Math.random() * 20) + 180; |
| 27 | + grad.push('color-stop(' + noise + ', rgb(' + shade + ',' + shade + ',' + shade + '))'); |
| 28 | + //noise += Math.floor(Math.random() * 0.1); |
| 29 | + noise += inc; |
| 30 | + } |
| 31 | + |
| 32 | + // Finish it |
| 33 | + grad.push('color-stop(' + end + ', rgb(193,193,193))'); |
| 34 | + grad.push('color-stop(1, rgb(153,153,153))'); |
| 35 | + |
| 36 | + // Set it on the box |
| 37 | + box.style.backgroundImage = '-webkit-gradient(' + grad.join(', ') + ')'; |
| 38 | + } // function newGrad |
| 39 | + |
| 40 | + // Events! |
| 41 | + document.addEventListener('DOMContentLoaded', newGrad, false); |
| 42 | + document.getElementById('redo').addEventListener('click', newGrad, false); |
| 43 | + console.log('Whee'); |
| 44 | +})(); |
0 commit comments