flazer

source-bulan by flazer

Feb 4th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. <!DOCTYPE HTML><html lang="en"><head><title>Gerhana matahari | eQi</title><link rel="shortcut icon" href="http://swararakyat.files.wordpress.com/2007/06/indonesia_flag.gif" type="image/x-icon" /> <meta charset="utf-8"><meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"><link rel="shortcut icon" href="http://swararakyat.files.wordpress.com/2007/06/indonesia_flag.gif" type="image/x-icon" /><style type="text/css">*{color:#808080;}body{background-color:#000000;background-image:url('http://mrdoob.com/lab/javascript/effects/zoomblur/03/space.jpg');background-position:top center;margin:0px;overflow:hidden;}#info{position:absolute;top:0px;width:100%;padding:5px;font-family:Monospace;font-size:13px;text-align:center;}</style> </head><body><script type="text/javascript">var _gaq = _gaq || [];
  2. _gaq.push(['_setAccount', 'UA-86951-7']);
  3. _gaq.push(['_trackPageview']);
  4.  
  5. (function() {
  6. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  7. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  8. (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  9. })();
  10. </script><div id="container"></div><div id="info">Rollover the sun to create a eclipse.</div><script type="text/javascript">var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight,
  11. SCREEN_WIDTH_HALF = window.innerWidth / 2, SCREEN_HEIGHT_HALF = window.innerHeight / 2,
  12. LEVELS = 32;
  13.  
  14. var context, shape, shapeContext;
  15. var planet;
  16.  
  17. var mouseX = 0, mouseY = 0;
  18. var easedMouseX = 0, easedMouseY = 0;
  19.  
  20. init();
  21. setInterval(loop, 1000/30);
  22.  
  23. function init() {
  24.  
  25. var container, canvas;
  26.  
  27. container = document.getElementById('container');
  28.  
  29. planet = document.createElement("canvas");
  30. planet.width = 150;
  31. planet.height = 150;
  32. planet.style.position = 'absolute';
  33. container.appendChild(planet);
  34.  
  35. planetContext = planet.getContext("2d");
  36. planetContext.beginPath();
  37. planetContext.arc(75 - (easedMouseX * 1000), 75 - (easedMouseY * 1000), 75, 0, Math.PI * 2, true);
  38. planetContext.fillStyle = "rgb(0, 0, 0)";
  39. planetContext.fill();
  40.  
  41. canvas = document.createElement("canvas");
  42. canvas.width = 512;
  43. canvas.height = 512;
  44. canvas.style.position = 'absolute';
  45. canvas.style.top = (SCREEN_HEIGHT_HALF - 256) + "px";
  46. canvas.style.left = (SCREEN_WIDTH_HALF - 256) + "px";
  47. container.appendChild(canvas);
  48.  
  49. context = canvas.getContext("2d");
  50.  
  51. shape = document.createElement("canvas");
  52. shape.width = 128;
  53. shape.height = 128;
  54.  
  55. shapeContext = shape.getContext("2d");
  56.  
  57. document.addEventListener('mousemove', onDocumentMouseMove, false);
  58. }
  59.  
  60. function onDocumentMouseMove(event) {
  61.  
  62. mouseX = - (event.clientX - SCREEN_WIDTH_HALF) * 0.001;
  63. mouseY = - (event.clientY - SCREEN_HEIGHT_HALF) * 0.001;
  64.  
  65. }
  66.  
  67. function loop() {
  68.  
  69. easedMouseX += (mouseX - easedMouseX) * .2;
  70. easedMouseY += (mouseY - easedMouseY) * .2;
  71.  
  72. planet.style.top = (SCREEN_HEIGHT_HALF - 75 - (easedMouseY * 1000)) + "px";
  73. planet.style.left = (SCREEN_WIDTH_HALF - 75 - (easedMouseX * 1000)) + "px";
  74.  
  75. shapeContext.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  76.  
  77. shapeContext.globalCompositeOperation = "source-over";
  78. shapeContext.beginPath();
  79. shapeContext.arc(64, 64, 64, 0, Math.PI * 2, true);
  80. shapeContext.fillStyle = "rgb(255, 255, 230)";
  81. shapeContext.fill();
  82.  
  83. shapeContext.globalCompositeOperation = "destination-out";
  84. shapeContext.beginPath();
  85. shapeContext.arc(64 - (easedMouseX * 1000), 64 - (easedMouseY * 1000), 75, 0, Math.PI * 2, true);
  86. shapeContext.fillStyle = "rgb(0, 0, 0)";
  87. shapeContext.fill();
  88.  
  89. context.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  90.  
  91. for (var i = 0; i < LEVELS; i ++) {
  92.  
  93. var size = 128 + i * 10;
  94. var size_half = size * 0.5;
  95. var x = 256 - size_half;
  96. var y = 256 - size_half;
  97.  
  98. context.globalAlpha = (256 / ((i + 4) * (i + 4) * 20));
  99. context.drawImage(shape, x, y, size, size);
  100.  
  101. }
  102.  
  103. }
  104.  
  105. </script> </body></html>
Add Comment
Please, Sign In to add comment