<section id="paths-6">
    <div class="container">
        <svg id="paths-6-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="900" viewBox="0 0 1600 900">
        </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-6.js" type="module"></script>
<section id="paths-6">
    <div class="container">
        <svg id="paths-6-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="900" viewBox="0 0 1600 900">
        </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-6.js' }}" type="module"></script>
/* No context defined. */
  • Content:
    import {
      createColor,
      getRandomInt,
      getRandomIntInclusive,
    } from "./utils-v1.js";
    
    console.log("paths-6 active");
    
    const draw = SVG('#paths-6-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;
      let c2 = y + getRandomIntInclusive(0, height * 1.5);
    
      pathData += `${c1},${c2} ${x},${y}`;
    
      return pathData;
    }
    
    let rect = draw.rect(width, height).fill('#00abab').opacity(0.1);
    
    let numWaves = 1;
    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('#008496');
      myPath.stroke({
        color: '#FFF',
        width: 20,
        opacity: 1
      });
    
      myPath.opacity(0.15);
    }
    
  • URL: /components/raw/paths-6/paths-6.js
  • Filesystem Path: components/03-svgjs/05-paths/06-paths-6/paths-6.js
  • Size: 1.8 KB
  • Content:
    #paths-6 {
      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-6/paths-6.scss
  • Filesystem Path: components/03-svgjs/05-paths/06-paths-6/paths-6.scss
  • Size: 222 Bytes

No notes defined.