Pen Settings



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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


                <h1>SVG Lines Genarative Art</h1>
<button class="go one">Draw lines</button><button class="go two">Draw colours</button><button class="go three">Draw all sorts</button>
<button class="go save">Save it</button>
<svg class="svg" width="100%" height="100%" viewbox="0 0 600 600" id="svg"></svg>
<canvas id="canvas" width="600" height="600"></canvas>
<div id="png-container"></div>


                * {margin: 0; padding: 0;}
body {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
h1 {
  margin: 0; padding: 0;
  position: absolute; left: 98%; top: 2%; white-space: nowrap; transform: rotate(90deg); transform-origin: left top;
svg {
   position:fixed; top:0; left:0; height:100%; width:100%;
   pointer-events: none; z-index: 0;
.go {
  padding: 1em;
  position: fixed;
  border: 0;
  border-right: 3px solid #ED5138;
  background: #DFDE64;
  height: 40px;

.one {top: 10px; left: 10px;}
.two {top: 60px; left: 10px;}
.three {top: 110px; left: 10px;}
.save {top: 180px; left: 10px; background-color:#86D2F3;}

#canvas {display: none;}

#png-container {
    display: none;
    height: 400px;
    width: 400px;
    margin: 0 auto;
    border: 10px solid #F3D400;
    padding: 20px;

#png-container img {
  max-height: 100%;
  max-width: 100%;


                var lines = [];
var count;
var s = Snap("#svg");
function buildPath(c) {
  var p0 = r(0,600);
  var p1 = r(0,600);
  var p2 = r(100,400);
  var p3 = r(100,400);
  var p4 = r(100,500);
  var p5 = r(100,500);
  var clr, clrfill;
  if(c=="c" || c=="a") {clr = colour();} else {clr = "#ff0082";}
  if(c=="a") {clrfill = colour();} else {clrfill = "none";}
  lines[count] = s.path("M300,0 C"+p0+","+p1+" "+p2+","+p3+" "+p4+","+p5+" S200,300 300,600").attr({
  fill: clrfill,
  "fill-opacity": 0.3,
  stroke: clr,
  strokeWidth: 3
  var pathLength = Snap.path.getTotalLength(lines[count]);
  lines[count] = pathLength + ' ' + pathLength;
  lines[count] = pathLength;
  Snap.animate(pathLength, 0, function( value ) {
      lines[count] = value;
    }, 400);

var pngContainer = document.querySelector('#png-container');

var int;
function go(c) {
  img = null;
  svg = null;
  pngContainer.innerHTML = ''; = 'none';
  if (int) {clearInterval(int);}
  int = setInterval(function() {
  }, 1200);

function colour() {
  return '#'+Math.floor(Math.random()*16777215).toString(16);

function r(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive 

document.querySelector(".one").addEventListener("click", function() {go('n')});
document.querySelector(".two").addEventListener("click", function() {go('c')});
document.querySelector(".three").addEventListener("click", function() {go('a')});
document.querySelector(".save").addEventListener("click", function() {saveIt()});

var canvas, img, svg;
function saveIt() {
  var svgString = new XMLSerializer().serializeToString(document.querySelector('svg'));
  canvas = document.getElementById("canvas");
  var ctx = canvas.getContext("2d");
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  var DOMURL = self.URL || self.webkitURL || self;
  img = new Image();
  svg = new Blob([svgString], {type: "image/svg+xml;charset=utf-8"});
  var url = DOMURL.createObjectURL(svg);
  img.onload = function() {
      ctx.drawImage(img, 0, 0);
      var png = canvas.toDataURL("image/png");
      pngContainer.innerHTML = '<img src="'+png+'"/>'; = 'block';
  img.src = url;