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.

103 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Bouncing Balls</title>
  6. <link rel="stylesheet" href="../css/style.css">
  7. <script type="text/javascript" src="../../dist/paper-full.js"></script>
  8. <script type="text/paperscript" canvas="canvas">
  9. var Ball = function(point, vector) {
  10. if (!vector || vector.isZero()) {
  11. this.vector = Point.random() * 5;
  12. } else {
  13. this.vector = vector * 2;
  14. }
  15. this.point = point;
  16. this.dampen = 0.4;
  17. this.gravity = 3;
  18. this.bounce = -0.6;
  19. var color = {
  20. hue: Math.random() * 360,
  21. saturation: 1,
  22. brightness: 1
  23. };
  24. var gradient = new Gradient([color, 'black'], true);
  25. var radius = this.radius = 50 * Math.random() + 30;
  26. // Wrap CompoundPath in a Group, since CompoundPaths directly
  27. // applies the transformations to the content, just like Path.
  28. var ball = new CompoundPath({
  29. children: [
  30. new Path.Circle({
  31. radius: radius
  32. }),
  33. new Path.Circle({
  34. center: radius / 8,
  35. radius: radius / 3
  36. })
  37. ],
  38. fillColor: new Color(gradient, 0, radius, radius / 8),
  39. });
  40. this.item = new Group({
  41. children: [ball],
  42. applyMatrix: false,
  43. position: this.point
  44. });
  45. }
  46. Ball.prototype.iterate = function() {
  47. var size = view.size;
  48. this.vector.y += this.gravity;
  49. this.vector.x *= 0.99;
  50. var pre = this.point + this.vector;
  51. if (pre.x < this.radius || pre.x > size.width - this.radius)
  52. this.vector.x *= -this.dampen;
  53. if (pre.y < this.radius || pre.y > size.height - this.radius) {
  54. if (Math.abs(this.vector.x) < 3)
  55. this.vector = Point.random() * [150, 100] + [-75, 20];
  56. this.vector.y *= this.bounce;
  57. }
  58. var max = Point.max(this.radius, this.point + this.vector);
  59. this.item.position = this.point = Point.min(max, size - this.radius);
  60. this.item.rotate(this.vector.x);
  61. };
  62. var balls = [];
  63. for (var i = 0; i < 10; i++) {
  64. var position = Point.random() * view.size,
  65. vector = (Point.random() - [0.5, 0]) * [50, 100],
  66. ball = new Ball(position, vector);
  67. balls.push(ball);
  68. }
  69. var textItem = new PointText({
  70. point: [20, 30],
  71. fillColor: 'black',
  72. content: 'Click, drag and release to add balls.'
  73. });
  74. var lastDelta;
  75. function onMouseDrag(event) {
  76. lastDelta = event.delta;
  77. }
  78. function onMouseUp(event) {
  79. var ball = new Ball(event.point, lastDelta);
  80. balls.push(ball);
  81. lastDelta = null;
  82. }
  83. function onFrame() {
  84. for (var i = 0, l = balls.length; i < l; i++)
  85. balls[i].iterate();
  86. }
  87. </script>
  88. </head>
  89. <body>
  90. <canvas id="canvas" resize></canvas>
  91. </body>
  92. </html>