script.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. $(function() {
  2. var c = document.getElementById('canv');
  3. var $canv = c.getContext('2d');
  4. var w = c.width = window.innerWidth;
  5. var h = c.height = window.innerHeight;
  6. var draw = function(a, b, t) {
  7. $canv.lineWidth = 0.8;
  8. // $canv.fillStyle = 'white';
  9. $canv.fillStyle = 'rgba(255, 255, 255, 1)';
  10. $canv.fillRect(0, 0, w, h);
  11. for (var i = -60; i < 60; i += 1) {
  12. // $canv.strokeStyle = 'hsla(277, 95%, 15%, .15)';
  13. $canv.strokeStyle = 'hsla(207, 73%, 44%, .15)';
  14. $canv.beginPath();
  15. $canv.moveTo(0, h / 2);
  16. for (var j = 0; j < w; j += 10) {
  17. $canv.lineTo(10 * Math.sin(i / 10) +
  18. j + 0.008 * j * j,
  19. Math.floor(h / 2 + j / 2 *
  20. Math.sin(j / 50 - t / 50 - i / 118) +
  21. (i * 0.9) * Math.sin(j / 25 - (i + t) / 65)));
  22. };
  23. $canv.stroke();
  24. }
  25. }
  26. var t = 0;
  27. window.addEventListener('resize', function() {
  28. c.width = w = window.innerWidth;
  29. c.height = h = window.innerHeight;
  30. $canv.fillStyle = 'hsla(207, 95%, 55%, 1)';
  31. }, false);
  32. var run = function() {
  33. window.requestAnimationFrame(run);
  34. t += 1;
  35. draw(33, 52 * Math.sin(t / 2400), t);
  36. };
  37. run();
  38. })