<section id="paths-7">
    <div class="container">
        <svg id="paths-7-svg" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="1600" height="1600" viewBox="0 0 1600 1600">
        </svg>
    </div>
</section>

<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.topath.js@2.0.3/dist/svg.topath.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.filter.js@3.0.8/dist/svg.filter.min.js"></script>
<script src="../../js/components/paths-7.js" type="module"></script>
<section id="paths-7">
    <div class="container">
        <svg id="paths-7-svg" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="1600" height="1600" viewBox="0 0 1600 1600">
        </svg>
    </div>
</section>

<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.topath.js@2.0.3/dist/svg.topath.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.filter.js@3.0.8/dist/svg.filter.min.js"></script>
<script src="{{ path '/js/components/paths-7.js' }}" type="module"></script>
/* No context defined. */
  • Content:
    import {
      coinFlip,
      getRandomIntInclusive,
      getRandomArrayElement
    } from "./utils-v1.js";
    
    console.log("paths-7 active");
    
    const colors = [
      "#ffffff",
      "#70948a",
      "#9F9FA5",
      "#B7C4C4",
      "#E4E8E8",
      "#D8A2AF",
    ]
    
    const draw = SVG('#paths-7-svg');
    
    const width = draw.width();
    const height = draw.height();
    
    const sqSize = Math.min(width, height);
    
    // draw.path('M0 0 H50 A20 20 0 1 0 100 50 v25 C50 125 0 85 0 85 z')
    
    function randomPoint(max) {
      let x1 = getRandomIntInclusive(0, max);
      let y1 = getRandomIntInclusive(0, max);
    
      return [x1, y1];
    }
    
    function startPoint(x1, y1) {
      let pathData = "M";
    
      pathData += `${x1} ${y1}`;
    
      return pathData;
    }
    
    function lineTo(x, y) {
      let pathData = "L";
    
      pathData += `${x} ${y}`;
    
      return pathData;
    }
    
    function smoothClosedCurveTo(x, y) {
      let pathData = "S";
    
      let c1 = x + getRandomIntInclusive(-50, 50);
      let c2 = y + getRandomIntInclusive(0, height * 0.5);
    
      pathData += `${c1},${c2} ${x},${y}`;
    
      return pathData;
    }
    
    let rect = draw.rect(width, height).fill('#00abab').opacity(0.1);
    
    let numWaves = 10;
    let waveHeight = height / numWaves;
    
    for (let waves = 0; waves < numWaves; waves++) {
      let curY = waves * waveHeight;
      let yLine = getRandomIntInclusive(curY, curY + waveHeight);
    
      console.log({curY, yLine});
    
      let x1 = 0;
      let x2 = width;
      let xMid = getRandomIntInclusive(width * 0.25, width * 0.75);
    
      // Start
      let stringData = startPoint(x1, yLine);
    
      // Make a wave
      stringData += smoothClosedCurveTo(x1, yLine);
      stringData += smoothClosedCurveTo(xMid, yLine);
      stringData += smoothClosedCurveTo(x2, yLine);
    
      // Reverse the wave?
      stringData += lineTo(x2, yLine);
      stringData += smoothClosedCurveTo(x2, yLine);
      stringData += smoothClosedCurveTo(xMid, yLine);
      stringData += smoothClosedCurveTo(x1, yLine);
    
      let myPath = draw.path(stringData);
    
      myPath.fill(getRandomArrayElement(colors));
      myPath.opacity(0.75);
    
      myPath.stroke({
        color: '#FFF',
        width: 1,
        opacity: 0.5
      });
    
      myPath.addClass('wave');
    }
    
    draw.find('.wave').each(el => {
      if (coinFlip()) {
        el.backward();
      } else if (coinFlip()) {
        el.back();
      }
    })
    
  • URL: /components/raw/paths-7/paths-7.js
  • Filesystem Path: components/03-svgjs/05-paths/07-paths-7/paths-7.js
  • Size: 2.1 KB
  • Content:
    #paths-7 {
      padding: 1rem;
    
      .container {
        width: 100%;
        height: calc(100vh - 8rem);
    
        display: flex;
        align-items: center;
      }
    
      svg {
        //border: 1px solid teal;
        width: 100%;
        height: auto;
      }
    }
    
  • URL: /components/raw/paths-7/paths-7.scss
  • Filesystem Path: components/03-svgjs/05-paths/07-paths-7/paths-7.scss
  • Size: 222 Bytes

No notes defined.