Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
7.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Nyan Rainbow</title>
  6. <link rel="stylesheet" href="../css/style.css">
  7. <script type="text/javascript" src="../../dist/paper-full.js"></script>
  8. <script type="text/javascript" src="http://paperjs.org/assets/mediaelement/mediaelement.js"></script>
  9. <script type="text/paperscript" canvas="canvas">
  10. // A tribute to Nyan Cat http://www.youtube.com/watch?v=QH2-TGUlwu4
  11. var mediaElement;
  12. var playing = false;
  13. MediaElement('nyan', {
  14. pluginPath: '/assets/mediaelement/',
  15. success: function(me) {
  16. mediaElement = me;
  17. me.play();
  18. me.addEventListener('timeupdate', function(time) {
  19. if (me.currentTime > 3.7)
  20. playing = true;
  21. });
  22. }
  23. });
  24. var mousePos = view.center + [view.bounds.width / 3, 100];
  25. var position = view.center;
  26. function onFrame(event) {
  27. position += (mousePos - position) / 10;
  28. var vector = (view.center - position) / 10;
  29. moveStars(vector * 3);
  30. moveRainbow(vector, event);
  31. }
  32. function onMouseMove(event) {
  33. mousePos = event.point;
  34. }
  35. function onKeyDown(event) {
  36. if (event.key == 'space')
  37. project.activeLayer.selected = !project.activeLayer.selected;
  38. }
  39. var moveStars = new function() {
  40. // The amount of symbol we want to place;
  41. var count = 50;
  42. // Create a symbol, which we will use to place instances of later:
  43. var path = new Path.Circle({
  44. center: new Point(0, 0),
  45. radius: 5,
  46. fillColor: 'white',
  47. strokeColor: 'black'
  48. });
  49. var symbol = new SymbolDefinition(path);
  50. // Place the instances of the symbol:
  51. for (var i = 0; i < count; i++) {
  52. // The center position is a random point in the view:
  53. var center = Point.random() * view.size;
  54. var placed = symbol.place(center);
  55. placed.scale(i / count + 0.01);
  56. placed.data = {
  57. vector: new Point({
  58. angle: Math.random() * 360,
  59. length : (i / count) * Math.random() / 5
  60. })
  61. };
  62. }
  63. var vector = new Point({
  64. angle: 45,
  65. length: 0
  66. });
  67. function keepInView(item) {
  68. var position = item.position;
  69. var viewBounds = view.bounds;
  70. if (position.isInside(viewBounds))
  71. return;
  72. var itemBounds = item.bounds;
  73. if (position.x > viewBounds.width + 5) {
  74. position.x = -item.bounds.width;
  75. }
  76. if (position.x < -itemBounds.width - 5) {
  77. position.x = viewBounds.width;
  78. }
  79. if (position.y > viewBounds.height + 5) {
  80. position.y = -itemBounds.height;
  81. }
  82. if (position.y < -itemBounds.height - 5) {
  83. position.y = viewBounds.height
  84. }
  85. }
  86. return function(vector) {
  87. // Run through the active layer's children list and change
  88. // the position of the placed symbols:
  89. var layer = project.activeLayer;
  90. for (var i = 0; i < count; i++) {
  91. var item = layer.children[i];
  92. var size = item.bounds.size;
  93. var length = vector.length / 10 * size.width / 10;
  94. item.position += vector.normalize(length) + item.data.vector;
  95. keepInView(item);
  96. }
  97. };
  98. };
  99. var moveRainbow = new function() {
  100. var paths = [];
  101. var colors = ['red', 'orange', 'yellow', 'lime', 'blue', 'purple'];
  102. for (var i = 0; i < colors.length; i++) {
  103. var path = new Path({
  104. fillColor: colors[i]
  105. });
  106. paths.push(path);
  107. }
  108. var count = 30;
  109. var group = new Group(paths);
  110. var headGroup;
  111. var eyePosition = new Point();
  112. var eyeFollow = (Point.random() - 0.5);
  113. var blinkTime = 200;
  114. function createHead(vector, count) {
  115. var eyeVector = (eyePosition - eyeFollow);
  116. eyePosition -= eyeVector / 4;
  117. if (eyeVector.length < 0.00001)
  118. eyeFollow = (Point.random() - 0.5);
  119. if (headGroup)
  120. headGroup.remove();
  121. var top = paths[0].lastSegment.point;
  122. var bottom = paths[paths.length - 1].firstSegment.point;
  123. var radius = (bottom - top).length / 2;
  124. var circle = new Path.Circle({
  125. center: top + (bottom - top) / 2,
  126. radius: radius,
  127. fillColor: 'black'
  128. });
  129. circle.scale(vector.length / 100, 1);
  130. circle.rotate(vector.angle, circle.center);
  131. innerCircle = circle.clone();
  132. innerCircle.scale(0.5);
  133. innerCircle.fillColor = (count % blinkTime < 3)
  134. || (count % (blinkTime + 5) < 3) ? 'black' : 'white';
  135. if (count % (blinkTime + 40) == 0)
  136. blinkTime = Math.round(Math.random() * 40) + 200;
  137. var eye = circle.clone();
  138. eye.position += eyePosition * radius;
  139. eye.scale(0.15, innerCircle.position);
  140. eye.fillColor = 'black';
  141. headGroup = new Group(circle, innerCircle, eye);
  142. }
  143. return function(vector, event) {
  144. var vector = (view.center - position) / 10;
  145. if (vector.length < 5)
  146. vector.length = 5;
  147. count += vector.length / 100;
  148. group.translate(vector);
  149. var rotated = vector.rotate(90);
  150. var middle = paths.length / 2;
  151. for (var j = 0; j < paths.length; j++) {
  152. var path = paths[j];
  153. var nyanSwing = playing ? Math.sin(event.count / 2) * vector.length : 1;
  154. var unitLength = vector.length * (2 + Math.sin(event.count / 10)) / 2;
  155. var length = (j - middle) * unitLength + nyanSwing;
  156. var top = view.center + rotated.normalize(length);
  157. var bottom = view.center + rotated.normalize(length + unitLength);
  158. path.add(top);
  159. path.insert(0, bottom);
  160. if (path.segments.length > 200) {
  161. var index = Math.round(path.segments.length / 2);
  162. path.segments[index].remove();
  163. path.segments[index - 1].remove();
  164. }
  165. path.smooth();
  166. }
  167. createHead(vector, event.count);
  168. if (mediaElement)
  169. mediaElement.setVolume(vector.length / 200);
  170. }
  171. }
  172. </script>
  173. <style>
  174. body {
  175. background: black;
  176. }
  177. </style>
  178. </head>
  179. <body>
  180. <audio id="nyan" src="http://dl.dropbox.com/u/31703/nyan.mp3" autoplay autobuffer preload=none loop style="display:none"></audio>
  181. <canvas id="canvas" resize hidpi="off"></canvas>
  182. </body>
  183. </html>