Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <svg 
  viewBox="0 0 850 1100" 
  width="8.5in" 
  height="11in" 
  role="img"
>
  <title>
    A geometric pattern composed of nested circles and squiggly lines.
    Inspired by Legends of Zelda: Tears of the Kingdom
  </title>
  
  <defs>
    <linearGradient id="gold-gradient" gradientTransform="rotate(-50)">
      <stop offset="5%" stop-color="hsl(44, 100%, 67%)" />
      <stop offset="95%" stop-color="hsl(44, 70%, 27%)" />
    </linearGradient>
  </defs>

  <g class="pattern">
    <!-- 
      Our graphics code goes here 
    -->
  </g>
</svg>

<form autocomplete="off">
  <button type="button">Randomize</button>
</form>
              
            
!

CSS

              
                /* Define our base custom properties */
:root {
  --fill: #fff;
  --stroke: hsl(80, 80%, 28%);
}

/* Apply styles to our elements */
svg {
  background: var(--fill);
}
.fill {
  fill: var(--fill);
}
.stroke {
  fill: none;
  stroke: var(--stroke);
  stroke-width: 10;
}

* {
  font-family: sans-serif;
}

html, body {
  display: grid;
  place-items: center;
  min-height: 100%;
  background-color: #eee;
}

svg {
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
}

form {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 3em;
}

fieldset {
  display: flex;
  gap: 1em;
}
              
            
!

JS

              
                import { randomInt } from 'https://unpkg.com/randomness-helpers@0.0.1/dist/index.js';
import { spline } from 'https://unpkg.com/@georgedoescode/spline@1.0.1/spline.js';

const gridWidth = 850;
const gridHeight = 1100;

  const frameSize = 100;


function circle({ x, y, r, className }) {
  return `
    <circle 
      cx="${x}" 
      cy="${y}" 
      r="${r}" 
      class="${className}"
    />
  `;
}

function circleGroup({x, y, r }) {
  // We'll store all our circles in an array.
  const circles = [];

  // First, draw a circle with a white background but no border.
  // This will hide any elements behind the circle.
  circles.push(circle({ x, y, r, className: 'fill' }));

  // Decide how much space to put between our circles.
  const gap = 20;

  // Draw a number of circles, making each one smaller than the last
  // until we hit a radius of 0.
  let circleSize = r;
  while(circleSize > 0) {
    circles.push(circle({ x, y, r: circleSize, className: 'stroke' }));
    
    circleSize -= gap;
  }

  // Return all our circles as a single string;
  return circles.join('');
}

function squigglyLine(x, squiggleWidth, squiggleHeight) {
  const points = [];
  
  // Define an offset for how far the points should
  // be placed from the center of our line.
  let xOffset = squiggleWidth / 2;
  
  for(
    // Start slightly above the edge of our canvas
    let y = -1 * squiggleHeight; 
    // End slightly below the bottom
    y <= gridHeight + squiggleHeight; 
    // Iterate down, adding new points to our array
    y += squiggleHeight
  ) {
    // Add a new point.
    // Adjust our x value by our offset;
    points.push({y, x: x + xOffset});
    // Flip our x offset so the next point is 
    // placed on the other side of our center line.
    xOffset *= -1;
  }
  
  // Use our points to build a path
  return `
    <path d="${spline(points)}" class="stroke" />
  `;
}

const patternEl =  document.querySelector('.pattern');

function draw() {
  const circleGroups = [];
  for (let i = 0; i < randomInt(12, 24); i++) {
    circleGroups.push(circleGroup({
      x: randomInt(0, gridWidth),
      y: randomInt(0, gridHeight),
      r: randomInt(80, 240)
    }))
  }
  
  const lines = [];
  const lineGap = randomInt(15, 25);
  const squiggleWidth = randomInt(10, 15);
  const squiggleHeight = randomInt(60, 90);
  for(let x = lineGap * -1; x < gridWidth + lineGap; x += lineGap) {
    lines.push(squigglyLine(x, squiggleWidth, squiggleHeight));
  }
  
  patternEl.innerHTML = lines.join('') + circleGroups.join('') + `
    <rect fill="#fff" x="-500" y="-500" width="620" height="${
      gridHeight + 1000
    }"/>
    <rect fill="#fff" x="${
      gridWidth - frameSize - 20
    }" y="-500" width="620" height="${gridHeight + 1000}"/>
    <rect fill="#fff" x="-500" y="-500" width="${
      gridWidth + 1000
    }" height="620"/>
    <rect fill="#fff" x="-500" y="${gridHeight - frameSize - 20}" width="${
    gridWidth + 1000
  }" height="600"/>
    <rect
      class="stroke"
      x="${frameSize}" 
      y="${frameSize}"
      width="${gridWidth - frameSize * 2}"
      height="${gridHeight - frameSize * 2}"
    />
        <rect
      class="stroke"
      x="${frameSize + 20}" 
      y="${frameSize + 20}"
      width="${gridWidth - frameSize * 2- 40}"
      height="${gridHeight - frameSize * 2 - 40}"
    />
  `;;
}

draw();

document.querySelector('button').addEventListener('click', draw);
              
            
!
999px

Console