Web Interface For Lite Argus Control modules
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.

151 lines
4.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Candy Crash</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. // kynd.info 2014
  10. function Ball(r, p, v) {
  11. this.radius = r;
  12. this.point = p;
  13. this.vector = v;
  14. this.maxVec = 15;
  15. this.numSegment = Math.floor(r / 3 + 2);
  16. this.boundOffset = [];
  17. this.boundOffsetBuff = [];
  18. this.sidePoints = [];
  19. this.path = new Path({
  20. fillColor: {
  21. hue: Math.random() * 360,
  22. saturation: 1,
  23. brightness: 1
  24. },
  25. blendMode: 'lighter'
  26. });
  27. for (var i = 0; i < this.numSegment; i ++) {
  28. this.boundOffset.push(this.radius);
  29. this.boundOffsetBuff.push(this.radius);
  30. this.path.add(new Point());
  31. this.sidePoints.push(new Point({
  32. angle: 360 / this.numSegment * i,
  33. length: 1
  34. }));
  35. }
  36. }
  37. Ball.prototype = {
  38. iterate: function() {
  39. this.checkBorders();
  40. if (this.vector.length > this.maxVec)
  41. this.vector.length = this.maxVec;
  42. this.point += this.vector;
  43. this.updateShape();
  44. },
  45. checkBorders: function() {
  46. var size = view.size;
  47. if (this.point.x < -this.radius)
  48. this.point.x = size.width + this.radius;
  49. if (this.point.x > size.width + this.radius)
  50. this.point.x = -this.radius;
  51. if (this.point.y < -this.radius)
  52. this.point.y = size.height + this.radius;
  53. if (this.point.y > size.height + this.radius)
  54. this.point.y = -this.radius;
  55. },
  56. updateShape: function() {
  57. var segments = this.path.segments;
  58. for (var i = 0; i < this.numSegment; i ++)
  59. segments[i].point = this.getSidePoint(i);
  60. this.path.smooth();
  61. for (var i = 0; i < this.numSegment; i ++) {
  62. if (this.boundOffset[i] < this.radius / 4)
  63. this.boundOffset[i] = this.radius / 4;
  64. var next = (i + 1) % this.numSegment;
  65. var prev = (i > 0) ? i - 1 : this.numSegment - 1;
  66. var offset = this.boundOffset[i];
  67. offset += (this.radius - offset) / 15;
  68. offset += ((this.boundOffset[next] + this.boundOffset[prev]) / 2 - offset) / 3;
  69. this.boundOffsetBuff[i] = this.boundOffset[i] = offset;
  70. }
  71. },
  72. react: function(b) {
  73. var dist = this.point.getDistance(b.point);
  74. if (dist < this.radius + b.radius && dist != 0) {
  75. var overlap = this.radius + b.radius - dist;
  76. var direc = (this.point - b.point).normalize(overlap * 0.015);
  77. this.vector += direc;
  78. b.vector -= direc;
  79. this.calcBounds(b);
  80. b.calcBounds(this);
  81. this.updateBounds();
  82. b.updateBounds();
  83. }
  84. },
  85. getBoundOffset: function(b) {
  86. var diff = this.point - b;
  87. var angle = (diff.angle + 180) % 360;
  88. return this.boundOffset[Math.floor(angle / 360 * this.boundOffset.length)];
  89. },
  90. calcBounds: function(b) {
  91. for (var i = 0; i < this.numSegment; i ++) {
  92. var tp = this.getSidePoint(i);
  93. var bLen = b.getBoundOffset(tp);
  94. var td = tp.getDistance(b.point);
  95. if (td < bLen) {
  96. this.boundOffsetBuff[i] -= (bLen - td) / 2;
  97. }
  98. }
  99. },
  100. getSidePoint: function(index) {
  101. return this.point + this.sidePoints[index] * this.boundOffset[index];
  102. },
  103. updateBounds: function() {
  104. for (var i = 0; i < this.numSegment; i ++)
  105. this.boundOffset[i] = this.boundOffsetBuff[i];
  106. }
  107. };
  108. //--------------------- main ---------------------
  109. var balls = [];
  110. var numBalls = 18;
  111. for (var i = 0; i < numBalls; i++) {
  112. var position = Point.random() * view.size;
  113. var vector = new Point({
  114. angle: 360 * Math.random(),
  115. length: Math.random() * 10
  116. });
  117. var radius = Math.random() * 60 + 60;
  118. balls.push(new Ball(radius, position, vector));
  119. }
  120. function onFrame() {
  121. for (var i = 0; i < balls.length - 1; i++) {
  122. for (var j = i + 1; j < balls.length; j++) {
  123. balls[i].react(balls[j]);
  124. }
  125. }
  126. for (var i = 0, l = balls.length; i < l; i++) {
  127. balls[i].iterate();
  128. }
  129. }
  130. </script>
  131. </head>
  132. <body>
  133. <canvas id="canvas" resize hidpi="off" style="background:black"></canvas>
  134. </body>
  135. </html>