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

              
                <div class="svg-container"></div>
<button id="download" type="button" class="btn btn-primary mt-3" href="#">Download as SVG</button>
              
            
!

CSS

              
                body {
  font-family: Helvetica, Arial, sans-serif;
  text-align: center;
}

svg {
  display: block;
  border: 1px solid #333;
  margin: 1em auto 0;
  width: 100%;
  max-width: 400px;
  height: auto;
}
              
            
!

JS

              
                /* globals SVG, saveAs */

const IDMColors = {
  indigo: '#0066b3',
  green: '#00a651',
  yellow: '#ffcb05',
  red: '#ed1c24',
  blue: '#00aeef',
  purple: '#7670b3',
  lgreen: '#a6ce39',
  fucsia: '#c657a0',
  orange: '#f58220',
};

// Poster size
const A3_WIDTH = 841.9;
const A3_HEIGHT = 1190.6;
const WIDTH = A3_WIDTH;
const HEIGHT = A3_HEIGHT;

// Return a random color from the list of IDM colors
function randomColor() {
  const keys = Object.keys(IDMColors);
  const index = Math.floor(Math.random() * keys.length);
  return IDMColors[keys[index]];
}

function seqColor() {
  if (this.lastColor === undefined) {
    this.lastColor = 0;
  }

  this.lastColor += 1;
  return IDMColors[Object.keys(IDMColors)[this.lastColor % Object.keys(IDMColors).length]];
}

// Create the SVG element
const draw = SVG().addTo('.svg-container').size(WIDTH, HEIGHT).viewbox(0, 0, WIDTH, HEIGHT);

const circles = draw.group();

let radius = HEIGHT;
for (let i = 0; i < 9; i += 1) {
  radius = Math.pow(Math.pow(radius, 1/3) * 0.926, 3);
  let size = radius / 5 - (i * 2);
  for (let j=0; j<24; j+=1) {
    const angle = (j + 0.5 * (i % 2)) * (Math.PI * 2 / 24);
    const x = radius * Math.cos(angle);
    const y = radius * Math.sin(angle);
    circles
      .circle(size)
      .center(WIDTH / 2 + x, HEIGHT / (Math.PI * 2) + y)
      .attr({ fill: seqColor() });
  }
}

// Add the download button handler
document.getElementById('download').addEventListener('click', () => {
  // Extract the SVG data and send it to the browser as a fake file download
  const svgData = document.getElementsByTagName('svg')[0].innerHTML;
  const fullSVG = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
\t viewBox="0 0 ${A3_WIDTH} ${A3_HEIGHT}">
${svgData}
</svg>`;
  const blob = new Blob([fullSVG], { type: 'image/svg+xml' });
  saveAs(blob, 'poster-background.svg');
});

              
            
!
999px

Console