script.js 5.2 KB

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