script.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. var path = new Path({
  2. fillColor: 'black'
  3. });
  4. var amount = 3
  5. for (var i = 0; i < amount; i++) {
  6. var point = new Point(600, 650) * Point.random(view.size);
  7. path.add(point);
  8. console.log(point);
  9. var segment = path.segments[i];
  10. }
  11. function onFrame(event) {
  12. // Loop through the segments of the path:
  13. // A cylic value between -1 and 1
  14. var sinus = Math.sin(event.time * 3 + i);
  15. // Change the y position of the segment point:
  16. segment.point.y = sinus * 60 + 100;
  17. }
  18. path.closed = true;
  19. path.fullySelected = true;
  20. path.position.x += 1000;
  21. path.smooth();
  22. // function Ball(r, p, v) {
  23. //
  24. // this.radius = r;
  25. // this.point = p;
  26. // this.vector = v;
  27. // this.maxVec = 0.1;
  28. // this.numSegment = Math.floor(r / 1 + 1);
  29. // this.boundOffset = [];
  30. // this.boundOffsetBuff = [];
  31. // this.sidePoints = [];
  32. // this.path = new Path({
  33. // fillColor: {
  34. // hue: Math.random() * 360,
  35. // saturation: 1,
  36. // brightness: 1
  37. // },
  38. // blendMode: 'lighter'
  39. // });
  40. //
  41. // for (var i = 0; i < this.numSegment; i ++) {
  42. // this.boundOffset.push(this.radius);
  43. // this.boundOffsetBuff.push(this.radius);
  44. // this.path.add(new Point());
  45. // this.sidePoints.push(new Point({
  46. // angle: 360 / this.numSegment * i,
  47. // length: 1
  48. // }));
  49. // }
  50. // }
  51. //
  52. // Ball.prototype = {
  53. // iterate: function() {
  54. // this.checkBorders();
  55. // if (this.vector.length > this.maxVec)
  56. // this.vector.length = this.maxVec;
  57. // this.point += this.vector;
  58. // this.updateShape();
  59. // },
  60. //
  61. // checkBorders: function() {
  62. // var size = view.size;
  63. // if (this.point.x < -this.radius)
  64. // this.point.x = size.width + this.radius;
  65. // if (this.point.x > size.width + this.radius)
  66. // this.point.x = -this.radius;
  67. // if (this.point.y < -this.radius)
  68. // this.point.y = size.height + this.radius;
  69. // if (this.point.y > size.height + this.radius)
  70. // this.point.y = -this.radius;
  71. // },
  72. //
  73. // updateShape: function() {
  74. // var segments = this.path.segments;
  75. // for (var i = 0; i < this.numSegment; i ++)
  76. // segments[i].point = this.getSidePoint(i);
  77. //
  78. // this.path.smooth();
  79. // for (var i = 0; i < this.numSegment; i ++) {
  80. // if (this.boundOffset[i] < this.radius / 4)
  81. // this.boundOffset[i] = this.radius / 4;
  82. // var next = (i + 1) % this.numSegment;
  83. // var prev = (i > 0) ? i - 1 : this.numSegment - 1;
  84. // var offset = this.boundOffset[i];
  85. // offset += (this.radius - offset) / 15;
  86. // offset += ((this.boundOffset[next] + this.boundOffset[prev]) / 2 - offset) / 3;
  87. // this.boundOffsetBuff[i] = this.boundOffset[i] = offset;
  88. // }
  89. // },
  90. //
  91. // react: function(b) {
  92. // var dist = this.point.getDistance(b.point);
  93. // if (dist < this.radius + b.radius && dist != 0) {
  94. // var overlap = this.radius + b.radius - dist;
  95. // var direc = (this.point - b.point).normalize(overlap * 0.015);
  96. // this.vector += direc;
  97. // b.vector -= direc;
  98. //
  99. // this.calcBounds(b);
  100. // b.calcBounds(this);
  101. // this.updateBounds();
  102. // b.updateBounds();
  103. // }
  104. // },
  105. //
  106. // getBoundOffset: function(b) {
  107. // var diff = this.point - b;
  108. // var angle = (diff.angle + 180) % 360;
  109. // return this.boundOffset[Math.floor(angle / 360 * this.boundOffset.length)];
  110. // },
  111. //
  112. // calcBounds: function(b) {
  113. // for (var i = 0; i < this.numSegment; i ++) {
  114. // var tp = this.getSidePoint(i);
  115. // var bLen = b.getBoundOffset(tp);
  116. // var td = tp.getDistance(b.point);
  117. // if (td < bLen) {
  118. // this.boundOffsetBuff[i] -= (bLen - td) / 2;
  119. // }
  120. // }
  121. // },
  122. //
  123. // getSidePoint: function(index) {
  124. // return this.point + this.sidePoints[index] * this.boundOffset[index];
  125. // },
  126. //
  127. // updateBounds: function() {
  128. // for (var i = 0; i < this.numSegment; i ++)
  129. // this.boundOffset[i] = this.boundOffsetBuff[i];
  130. // }
  131. // };
  132. //
  133. // //--------------------- main ---------------------
  134. //
  135. // var balls = [];
  136. // var numBalls = 7;
  137. // for (var i = 0; i < numBalls; i++) {
  138. // var position = Point.random() * view.size;
  139. // var vector = new Point({
  140. // angle: 360 * Math.random(),
  141. // length: Math.random() * 10
  142. // });
  143. // var radius = Math.random() * 100 + 100;
  144. // balls.push(new Ball(radius, position, vector));
  145. //
  146. // }
  147. // function onFrame() {
  148. // for (var i = 0; i < balls.length - 1; i++) {
  149. // for (var j = i + 1; j < balls.length; j++) {
  150. // balls[i].react(balls[j]);
  151. // }
  152. // }
  153. // for (var i = 0, l = balls.length; i < l; i++) {
  154. // balls[i].iterate();
  155. // }
  156. // }