script.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // The amount of segment points we want to create:
  2. var amount = 3;
  3. // The maximum height of the wave:
  4. var height = 300;
  5. // Create a new path and style it:
  6. var path = new Path({
  7. // 80% black:
  8. strokeColor: [0.8],
  9. strokeWidth: 30,
  10. strokeCap: 'square'
  11. });
  12. var raster = new Raster({
  13. source: 'trame.svg',
  14. position: view.center
  15. });
  16. path.clipMask = true;
  17. // path.selected = true;
  18. path.closed = true;
  19. // path.fullySelected = true;
  20. // Add 5 segment points to the path spread out
  21. // over the width of the view:
  22. for (var i = 0; i <= amount; i++) {
  23. var maxPoint = new Point(700, 700);
  24. var point = maxPoint * Point.random(view.size) + 70;
  25. path.add(point);
  26. // path.add(new Point(500 / 700) * view.size);
  27. }
  28. // Select the path, so we can see how it is constructed:
  29. function onFrame(event) {
  30. // Loop through the segments of the path:
  31. for (var i = 0; i <= amount; i++) {
  32. var segment = path.segments[i];
  33. // A cylic value between -1 and 1
  34. var sinus = Math.sin(event.time * 0.05+ i);
  35. // Change the y position of the segment point:
  36. segment.point.y = sinus * height + 500;
  37. }
  38. // Uncomment the following line and run the script again
  39. // to smooth the path:
  40. path.smooth();
  41. }
  42. var copy = path.clone();
  43. copy.fullySelected = true;
  44. copy.position.x += 500;
  45. copy.smooth();
  46. // function Ball(r, p, v) {
  47. //
  48. // this.radius = r;
  49. // this.point = p;
  50. // this.vector = v;
  51. // this.maxVec = 0.1;
  52. // this.numSegment = Math.floor(r / 1 + 1);
  53. // this.boundOffset = [];
  54. // this.boundOffsetBuff = [];
  55. // this.sidePoints = [];
  56. // this.path = new Path({
  57. // fillColor: {
  58. // hue: Math.random() * 360,
  59. // saturation: 1,
  60. // brightness: 1
  61. // },
  62. // blendMode: 'lighter'
  63. // });
  64. //
  65. // for (var i = 0; i < this.numSegment; i ++) {
  66. // this.boundOffset.push(this.radius);
  67. // this.boundOffsetBuff.push(this.radius);
  68. // this.path.add(new Point());
  69. // this.sidePoints.push(new Point({
  70. // angle: 360 / this.numSegment * i,
  71. // length: 1
  72. // }));
  73. // }
  74. // }
  75. //
  76. // Ball.prototype = {
  77. // iterate: function() {
  78. // this.checkBorders();
  79. // if (this.vector.length > this.maxVec)
  80. // this.vector.length = this.maxVec;
  81. // this.point += this.vector;
  82. // this.updateShape();
  83. // },
  84. //
  85. // checkBorders: function() {
  86. // var size = view.size;
  87. // if (this.point.x < -this.radius)
  88. // this.point.x = size.width + this.radius;
  89. // if (this.point.x > size.width + this.radius)
  90. // this.point.x = -this.radius;
  91. // if (this.point.y < -this.radius)
  92. // this.point.y = size.height + this.radius;
  93. // if (this.point.y > size.height + this.radius)
  94. // this.point.y = -this.radius;
  95. // },
  96. //
  97. // updateShape: function() {
  98. // var segments = this.path.segments;
  99. // for (var i = 0; i < this.numSegment; i ++)
  100. // segments[i].point = this.getSidePoint(i);
  101. //
  102. // this.path.smooth();
  103. // for (var i = 0; i < this.numSegment; i ++) {
  104. // if (this.boundOffset[i] < this.radius / 4)
  105. // this.boundOffset[i] = this.radius / 4;
  106. // var next = (i + 1) % this.numSegment;
  107. // var prev = (i > 0) ? i - 1 : this.numSegment - 1;
  108. // var offset = this.boundOffset[i];
  109. // offset += (this.radius - offset) / 15;
  110. // offset += ((this.boundOffset[next] + this.boundOffset[prev]) / 2 - offset) / 3;
  111. // this.boundOffsetBuff[i] = this.boundOffset[i] = offset;
  112. // }
  113. // },
  114. //
  115. // react: function(b) {
  116. // var dist = this.point.getDistance(b.point);
  117. // if (dist < this.radius + b.radius && dist != 0) {
  118. // var overlap = this.radius + b.radius - dist;
  119. // var direc = (this.point - b.point).normalize(overlap * 0.015);
  120. // this.vector += direc;
  121. // b.vector -= direc;
  122. //
  123. // this.calcBounds(b);
  124. // b.calcBounds(this);
  125. // this.updateBounds();
  126. // b.updateBounds();
  127. // }
  128. // },
  129. //
  130. // getBoundOffset: function(b) {
  131. // var diff = this.point - b;
  132. // var angle = (diff.angle + 180) % 360;
  133. // return this.boundOffset[Math.floor(angle / 360 * this.boundOffset.length)];
  134. // },
  135. //
  136. // calcBounds: function(b) {
  137. // for (var i = 0; i < this.numSegment; i ++) {
  138. // var tp = this.getSidePoint(i);
  139. // var bLen = b.getBoundOffset(tp);
  140. // var td = tp.getDistance(b.point);
  141. // if (td < bLen) {
  142. // this.boundOffsetBuff[i] -= (bLen - td) / 2;
  143. // }
  144. // }
  145. // },
  146. //
  147. // getSidePoint: function(index) {
  148. // return this.point + this.sidePoints[index] * this.boundOffset[index];
  149. // },
  150. //
  151. // updateBounds: function() {
  152. // for (var i = 0; i < this.numSegment; i ++)
  153. // this.boundOffset[i] = this.boundOffsetBuff[i];
  154. // }
  155. // };
  156. //
  157. // //--------------------- main ---------------------
  158. //
  159. // var balls = [];
  160. // var numBalls = 7;
  161. // for (var i = 0; i < numBalls; i++) {
  162. // var position = Point.random() * view.size;
  163. // var vector = new Point({
  164. // angle: 360 * Math.random(),
  165. // length: Math.random() * 10
  166. // });
  167. // var radius = Math.random() * 100 + 100;
  168. // balls.push(new Ball(radius, position, vector));
  169. //
  170. // }
  171. // function onFrame() {
  172. // for (var i = 0; i < balls.length - 1; i++) {
  173. // for (var j = i + 1; j < balls.length; j++) {
  174. // balls[i].react(balls[j]);
  175. // }
  176. // }
  177. // for (var i = 0, l = balls.length; i < l; i++) {
  178. // balls[i].iterate();
  179. // }
  180. // }