Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1650 1170" width="1650" height="1170" version="1.1" >
  <!-- 
    Johan Karlsson, 2020
    https://twitter.com/DonKarlssonSan 
  -->
</svg>

              
            
!

CSS

              
                html, body {
  height: 100%;
  margin: 0;
  cursor: pointer;
  background-color: #223;
}

svg {
  position: absolute;
  width: 100%;
  height: 100%;
}

              
            
!

JS

              
                /*
  Johan Karlsson, 2020
  https://twitter.com/DonKarlssonSan
  MIT License, see Details View
*/

let svg;
let w = 1650;
let h = 1170;
let m;
let simplex;
let config = {
  strength: 100,
  zoom: 700,
  r: 250,
  angleStrength: 4,
  lineSpacing: 3,
  lineWidth: 1,
};


function setup() {
  console.clear();
  svg = document.querySelector("svg");
  document.addEventListener("click", draw);
  document.addEventListener("keydown", onKeyDown);
  m = Math.min(w, h) * 0.9;
  setupQuickSettings();
}

function setupQuickSettings() {
  let settings = QuickSettings.create(0, 0, "Noise Settings");
  settings.addRange("Strength", 1, 150, config.strength, 1, val => config.strength = val);
  settings.addRange("Zoom", 1, 1200, config.zoom, 1, val => config.zoom = val);
  settings.addRange("Radial Zoom", 1, 400, config.r, 1, val => config.r = val);
  settings.addRange("Angle Strength", 0.1, 20, config.angleStrength, 0.1, val => config.angleStrength = val);
  
  let lineSettings = QuickSettings.create(200, 0, "Line Settings");
  lineSettings.addRange("Line Spacing", 1, 20, config.lineSpacing, 1, val => config.lineSpacing = val);
  lineSettings.addRange("Line Width", 1, 5, config.lineWidth, 1, val => config.lineWidth = val);
}

function onKeyDown (e) {
  if(e.code === "KeyD") {
    download();
  }
}

function download() {
  let svgDoc = svg.outerHTML;
  let filename = "noisy-circles.svg";
  let element = document.createElement("a");
  element.setAttribute("href", "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svgDoc));
  element.setAttribute("download", filename);
  element.style.display = "none";
  document.body.appendChild(element);
  element.addEventListener("click", e => e.stopPropagation());
  element.click();
  document.body.removeChild(element);
}

function draw() {
  simplex = new SimplexNoise();
  let group = document.querySelector("#container");
  if (group) {
    group.remove();
  }
  group = createSvgElement("g");
  group.setAttribute("id", "container");
  group.setAttribute("fill", "none");
  group.setAttribute("stroke", "white");
  group.setAttribute("stroke-width", config.lineWidth);
  
  group.setAttribute("stroke-linecap", "round");
  group.setAttribute("stroke-linejoin", "round");
  
  for (let i = 3; i < m / 2; i += config.lineSpacing) {
    drawCircle(i, group);
  }

  let logo = new Logo(w * 0.9, h * 0.9, "white");
  logo.draw(group);

  svg.appendChild(group);
}

function drawCircle(r, groupElement) {
  let points = [];
  // Spread the starting point of each circle
  // to avoid pen up/down patterns when plotting.
  let randomAngleOffset = Math.PI * 2 * Math.random();
  let nrOfPOints = r * 1.5 + 10;
  let deltaAngle = (Math.PI * 2) / nrOfPOints;
  for (let angle = 0; angle < Math.PI * 2; angle += deltaAngle) {
    let p = calcPoint(angle + randomAngleOffset, r);
    points.push(p);
  }
  let p0 = points[0];
  points.push(p0);
  let path = createSvgElement("path");
  let commands = convertPointsToCommands(points);
  path.setAttribute("d", commands);
  groupElement.appendChild(path);
}

function calcPoint(angle, r) {
  let x = Math.cos(angle) * r + w / 2;
  let y = Math.sin(angle) * r + h / 2;
  let noiseX = Math.cos(angle) * r * config.angleStrength + w / 2;
  let noiseY = Math.sin(angle) * r * config.angleStrength + h / 2;
  n = simplex.noise3D(
    noiseX / config.zoom, 
    noiseY / config.zoom, 
    r/config.r) * config.strength;
  x = Math.cos(angle) * (r + n) + w / 2;
  y = Math.sin(angle) * (r + n) + h / 2;
  return `${x} ${y}`;
}

function createSvgElement(elementName) {
  const svgNs = "http://www.w3.org/2000/svg";
  return document.createElementNS(svgNs, elementName);
}

function convertPointsToCommands(points) {
  let commands = [];
  commands.push(`M ${points[0]}`);
  for (let i = 1; i < points.length; i++) {
    commands.push(`L ${points[i]}`);
  }
  return commands.join(" ");
}

setup();
draw();

              
            
!
999px

Console