script.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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();