<section id="blobs-1">
    <div class="container">
        <svg id="blobs-1-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="400" height="300" viewBox="0 0 400 300">
        </svg>
    </div>
</section>

<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
<script src="../../js/components/blobs-1.js" type="module"></script>
<section id="blobs-1">
    <div class="container">
        <svg id="blobs-1-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="400" height="300" viewBox="0 0 400 300">
        </svg>
    </div>
</section>

<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
<script src="{{ path '/js/components/blobs-1.js' }}" type="module"></script>
/* No context defined. */
  • Content:
    import {
      getRandomIntInclusive,
    } from "./utils-v1.js";
    
    const colors = [
      "#511259",
      "#553159",
      "#696273",
      "#F2EDA2",
      "#8C846C",
    ]
    
    function getColor(colors) {
      return colors[getRandomIntInclusive(0, colors.length - 1)];
    }
    
    function getRandomArrayElement(arr) {
      return arr[getRandomIntInclusive(0, arr.length - 1)];
    }
    
    console.log("blobs-1 active");
    
    const draw = SVG('#blobs-1-svg');
    
    const width = draw.width();
    const height = draw.height();
    
    const sqSize = 30;
    
    // Blob code
    
    const blobs = [];
    const numBlobs = 3;
    const defs = draw.defs();
    
    for (let i = 0; i < numBlobs; i++) {
      // Create a group
    
      const group = defs.group();
    
      // Create a square inside the group
    
      let curSquare = group.rect(sqSize, sqSize);
    
      blobs.push(group);
    }
    
    // Grid code
    
    let cols = Math.floor(width / sqSize);
    let rows = Math.floor(height / sqSize);
    
    let startX = (width - (cols * sqSize)) / 2;
    let startY = (height - (rows * sqSize)) / 2;
    
    console.log({startX, startY});
    
    for (let r = 0; r < rows; r++) {
      for (let c = 0; c < cols; c++) {
        let currentShape = draw.use(getRandomArrayElement(blobs));
        let objscale = sqSize / currentShape.bbox().width * 0.975;
    
        currentShape.transform({
          position: [startX + c * sqSize + sqSize / 2, startY + r * sqSize + sqSize / 2],
          scale: objscale,
          rotate: getRandomIntInclusive(0, 3) * 90
        });
    
        currentShape.attr({
          fill: getColor(colors),
        });
      }
    }
    
  • URL: /components/raw/blobs-1/blobs-1.js
  • Filesystem Path: components/03-svgjs/03-blobs/01-blobs-1/blobs-1.js
  • Size: 1.4 KB
  • Content:
    #blobs-1 {
      padding: 1rem;
    
      .container {
        width: 100%;
        height: calc(100vh - 2rem);
      }
    
      svg {
        border: 1px solid teal;
        width: 100%;
        height: auto;
      }
    }
    
  • URL: /components/raw/blobs-1/blobs-1.scss
  • Filesystem Path: components/03-svgjs/03-blobs/01-blobs-1/blobs-1.scss
  • Size: 175 Bytes

No notes defined.