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

              
                <?xml version="1.0" encoding="utf-8" ?>
<svg id="canvas" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"></svg>

<button class="btn btn-generate">
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#00f" viewBox="0 0 16 16"><path d="M1.161 8a6.84 6.84 0 1 0 6.842-6.84.58.58 0 1 1 0-1.16 8 8 0 1 1-6.556 3.412l-.663-.577a.58.58 0 0 1 .227-.997l2.52-.69a.58.58 0 0 1 .728.633l-.332 2.592a.58.58 0 0 1-.956.364l-.643-.56A6.812 6.812 0 0 0 1.16 8z"/><path d="M6.641 11.671V8.843h1.57l1.498 2.828h1.314L9.377 8.665c.897-.3 1.427-1.106 1.427-2.1 0-1.37-.943-2.246-2.456-2.246H5.5v7.352h1.141zm0-3.75V5.277h1.57c.881 0 1.416.499 1.416 1.32 0 .84-.504 1.324-1.386 1.324h-1.6z"/></svg>
</button>

<button class="btn btn-copy">
  <svg class="clipboard show" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#00f" viewBox="0 0 16 16"><path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/><path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/></svg>
  <svg class="clipboard-done" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#00f" class="bi bi-clipboard-check" viewBox="0 0 16 16"><path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"/></svg>
</button>

<button class="btn btn-save">
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#00f" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/></svg>
</button>

<button class="btn btn-save-image">
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#00f" viewBox="0 0 16 16"><path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/><path d="M1.5 2A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13zm13 1a.5.5 0 0 1 .5.5v6l-3.775-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12v.54A.505.505 0 0 1 1 12.5v-9a.5.5 0 0 1 .5-.5h13z"/></svg>
</button>

<div class="stamp"></div>
              
            
!

CSS

              
                body {
  margin: 60px 20px;
  height: calc(100vh - 120px);
  background: #ddd;
}

svg#canvas {
  width: 100%;
  height: 100%;
}

.btn {
  display: flex;
  border: none;
  position: absolute;
  right: 10px;
  background: #fff;
  padding: 8px;
  border-radius: 4px;
  box-shadow: 1px 1px 2px 0px rgb(0 0 0 / 5%);
}

.btn:hover {
  cursor: pointer;
  background: #00f;
}

.btn:hover svg {
  fill: #fff;
}

.btn:focus {
  outline: none;
}

.btn-generate {
  top: 10px;
}

.btn-copy {
  top: 50px;
}

.btn-save {
  top: 90px;
}

.btn-save-image {
  top: 130px;
}

.btn-generate svg,
.btn-copy svg,
.btn-save svg{
  display: block;
}

.btn-copy svg {
  display: none;
}

.btn-copy svg.show {
  display: block;
}

@media only screen and (max-width: 767px) {
  .btn {
    top: 10px;
  }
  .btn-generate {
    right: 10px;
  }

  .btn-copy {
    right: 50px;
  }

  .btn-save {
    right: 90px;
  }
  
  .btn-save-image {
    right: 130px;
  }
}

.stamp {
  text-align: center;
  font-family: Helvetica;
  font-size: 14px;
  color: #000;
  letter-spacing: 2px;
  display: block;
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
}
              
            
!

JS

              
                import copy from "https://cdn.skypack.dev/copy-to-clipboard@3.3.1";

//Set up Canvas
var w = 1000;
var h = 1000;
var fp = 4;
var canvas = SVG('#canvas').css('background', 'transparent');
canvas.size(w, h);
canvas.viewbox(0, 0, w, h);

//Set up random factors
var artworkID;
var fbase, ft, fct, fcb, fb;
var app_cs, app_csSeed;
var colour_base, colour_1, colour_2, colour_3, colour_4;

//Set up colour scheme
var cscheme = new Array;
cscheme[0] = ["#3BCFB8","#F29B9B","#F25252","#FFD045","#71F5B3"];
cscheme[1] = ["#FFEBB9","#FFC1AA","#FF979B","#FF6E8B","#FF447C"];
cscheme[2] = ["#F5DA00","#E1E1E1","#A9A9A9","#515151","#1C1C1C"];
cscheme[3] = ["#EB582C","#43412C","#E8B66F","#407B67","#E5D414"];
cscheme[4] = ["#F013B5","#B280D1","#6EAAEB","#32E6CE","#7DF0C0"];

//Rendering
generate();

function generate() {
	console.clear();
	//Setup
	app_cs = rand(cscheme.length);
	app_csSeed = rand(cscheme[app_cs].length);
	colour_base = cscheme[app_cs][app_csSeed];
	colour_1 = cscheme[app_cs][(app_csSeed + 1) % cscheme[app_cs].length];
	colour_2 = cscheme[app_cs][(app_csSeed + 2) % cscheme[app_cs].length];
	colour_3 = cscheme[app_cs][(app_csSeed + 3) % cscheme[app_cs].length];
	colour_4 = cscheme[app_cs][(app_csSeed + 4) % cscheme[app_cs].length];
	
	fbase = rand(3);
	ft = rand(6);
	fct = rand(5);
	fcb = rand(5);
	fb = rand(4);
	//ft = fct = fcb = fb = 2;
	canvas.clear();
	drawBase(fbase);
	drawCenterTop(fct);
	drawCenterBottom(fcb);
	drawBottom(fb);
	drawTop(ft);
	
	drawStamp(fbase, ft, fct, fcb, fb, app_cs, app_csSeed);
}

//Display artwork stamp
function drawStamp(a, b, c, d, e, f, g) {
	artworkID = num(a)+"-"+num(b)+"-"+num(c)+"-"+num(d)+"-"+num(e)+"-"+num(f)+"-"+num(g);
	document.querySelector(".stamp").innerHTML = "Ref: "+artworkID;
}

//Draw Base
function drawBase(c) {
	canvas.rect(w, h).fill(colour_base);

	/*var group = canvas.group();
	var total = 1000;
	for (var i = 0; i < total; i++) {
		var dotD = rand(10) + 1;
		var dot = canvas.circle(dotD)
			.x(rand(w - dotD))
			.y(rand(h - dotD))
			.fill(colour_1)
			.stroke("none")
		group.add(dot);
	}*/

	switch(c) {
		case 0:
			var rhombus = canvas.polyline([
					0, h,
					w / 2, 0,
					w, h,
					0, h
				])
				.fill({color: "#000", opacity: .05})
				.stroke("none")
		break;
		case 1:
			var rhombus = canvas.polyline([
					0, h,
					w / 2, 0,
					w, h,
					0, h
				])
				.fill({color: "#fff", opacity: .1})
				.stroke("none")
		break;
		default:
	}
}

//Draw Top
function drawTop(c) {
	/*var shape = canvas.rect(w, h / fp)
		.fill(colour_base)
		.stroke("none")*/
	switch(c) {
		case 0:
			//Short & Middle
			var group = canvas.group();
			var cellW = w / 2;
			var cellH = h / fp;

			var hair = canvas.polyline([
					0, 0,
					cellW, 0,
					0, cellH,
					0, 0
				])
				.move(0, 0)
				.fill(colour_1)
				.stroke("none")
			group.add(hair);

			var clone = hair.clone();
			clone.flip('x', {x: cellW, y: 0})
			group.add(clone);
		break;
		case 1:
			//Even straight down
			var group = canvas.group();
			var base = canvas.rect(w, h / fp)
				.fill(colour_base)
				.stroke("none")
			group.add(base);

			var rectFragmentT = rand(20) * 2 + 5;
			var cellW = w / rectFragmentT;
			var cellH = h / fp;
			for (var i = 0; i < rectFragmentT; i++) {
				if(i % 2 == 0) {
					var hair = canvas.rect(cellW, cellH)
						.move(i * cellW, 0)
						.fill(colour_1)
						.stroke("none")
					group.add(hair);
				}
			}
		break;
		case 2:
			//Details
			var group = canvas.group();
			var base = canvas.rect(w, h / fp)
				.fill(colour_base)
				.stroke("none")
			group.add(base);

			var shape = canvas.rect(w, h / fp / 6)
				.fill(colour_1)
				.stroke("none")
				.move(0, 0)
			group.add(shape);
			var shape = canvas.rect(w, h / fp / 6)
				.fill(colour_1)
				.stroke("none")
				.move(0, h / fp / 6 * 5)
			group.add(shape);
			var rectFragmentT = rand(20) * 2 + 5;
			var cellW = w / rectFragmentT;
			var cellH = h / fp / 6;
			for (var i = 0; i < rectFragmentT; i++) {
				if(i % 2 == 1) {
					var hair = canvas.rect(cellW, cellH)
						.move(i * cellW, h / fp / 6)
						.fill(colour_3)
						.stroke("none")
					group.add(hair);
					var hair = canvas.rect(cellW, cellH)
						.move(i * cellW, h / fp / 6 * 4)
						.fill(colour_3)
						.stroke("none")
					group.add(hair);
				}

				if(i % 2 == 0) {
					var dotD = Math.min(cellW, cellH * 2);
					var dot = canvas.circle(dotD)
						.cx(i * cellW + cellW / 2)
						.cy(h / fp / 2)
						.fill(colour_1)
						.stroke("none")
					group.add(dot);
				}
			}
		break;
		case 3:
			//Long & Middle
			var group = canvas.group();
			var cellW = w / 2;
			var cellH = h;
			var hair = canvas.polyline([
					0, 0,
					cellW, 0,
					0, cellH - cellH / 3,
					0, 0
				])
				.move(0, 0)
				.fill(colour_1)
				.stroke("none")
			group.add(hair);

			var clone = hair.clone();
			clone.flip('x', {x: cellW, y: 0})
			group.add(clone);
		break;
		case 4:
			//Block
			var shape = canvas.rect(w, h / fp)
				.fill(colour_1)
				.stroke("none")
				.move(0, 0)
		break;
		default:
	}
}

//Draw Center Top
function drawCenterTop(c) {
	/*var shape = canvas.rect(w, h / fp)
		.fill("#fff")
		.stroke({color: "#000", opacity: 1, width: 0.5})
		.x(0)
		.y(h / fp)*/
	switch(c) {
		case 0:
			//Strip
			if (rand(2) == 0) {
				var shape = canvas.rect(w - w / 20, h / fp  - w / 20)
					.fill(colour_3)
					.stroke("none")
					.cx(w / 2)
					.cy(h / fp + h / fp / 2)
			}

			var group = canvas.group();
			var total = rand(3) + 1;
			var cellW = w / total;
			var cellH = h / fp;

			var boundD = (cellW * cellH) / Math.sqrt(Math.pow(cellW, 2) + Math.pow(cellH, 2));
			var diameter = Math.min(cellW / 3, cellH / 3);
			var boundR = Math.sqrt(Math.pow(boundD, 2) / 2);
			var randAngle = rand(360);
			var randDist = rand(Math.floor((boundD - diameter) / 2));
			var showLine = rand(2) ? true : false;

			for (var i = 0; i < total; i++) {
				if (showLine) {
					var line = canvas.line([cellW * i + cellW / 2,0, cellW * i + cellW / 2,h])
						.stroke({color: colour_3, opacity: 1, width: 4})
					group.add(line);
				}

				var rhombus = canvas.polyline([
						0, cellH / 2,
						cellW / 2, 0,
						cellW, cellH / 2,
						cellW / 2, cellH,
						0, cellH / 2
					])
					.move(cellW * i, cellH)
					.fill(colour_1)
					.stroke("none")
				group.add(rhombus);

				var boundCircle = canvas.circle(boundD - boundD / 10)
					.cx(cellW * i + cellW / 2)
					.cy(cellH + cellH / 2)
					.fill(colour_2)
					.stroke("none")
				group.add(boundCircle);

				//var dotX = cellW * i + cellW / 2 + Math.cos(toRadians(randAngle)) * randDist;
				//var dotY = cellH + cellH / 2 + Math.sin(toRadians(randAngle)) * randDist;
				var dotX = cellW * i + cellW / 2;
				var dotY = cellH + cellH / 2;
				var dot = canvas.circle(diameter)
					.x(dotX - diameter / 2)
					.y(dotY - diameter / 2)
					.fill(colour_4)
					.stroke("none")
				group.add(dot);
			}
		break;
		case 1:
			var group = canvas.group();
			var total = rand(2) + 1;
			var cellW = w / total;
			var cellH = h / fp;
			
			var diameter = Math.min(cellW / 3, cellH / 3);
			var randAngle = rand(360);
			var randDist = rand(Math.floor((cellH - diameter) / 2));
			var showLine = rand(2) ? true : false;

			for (var i = 0; i < total; i++) {
				if (showLine) {
					var line = canvas.line([cellW * i + cellW / 2,0, cellW * i + cellW / 2,h])
						.stroke({color: colour_3, opacity: 1, width: 4})
						.css('stroke-linejoin', 'round')
						.css('stroke-linecap', 'round')
					group.add(line);
				}

				var eye = new Array();
				eye.push(['M', 0, cellH / 2])
				eye.push(['Q', cellW / 2, 0 - cellH / 2, cellW, cellH / 2])
				eye.push(['M', cellW, cellH / 2])
				eye.push(['Q', cellW / 2, cellH + cellH / 2, 0, cellH / 2])

				var path = new SVG.PathArray(eye);
				var shape = canvas.path(path)
					.move(cellW * i, cellH)
					.fill(colour_4)
					.stroke("none")
				group.add(shape);

				var boundCircle = canvas.circle(cellH)
					.cx(cellW * i + cellW / 2)
					.cy(cellH + cellH / 2)
					.fill(colour_2)
					.stroke("none")
				group.add(boundCircle);
				var clone = boundCircle.clone();
				clone.scale(0.5).fill(colour_4);
				group.add(clone);

				//var dotX = cellW * i + cellW / 2 + Math.cos(toRadians(randAngle)) * randDist;
				//var dotY = cellH + cellH / 2 + Math.sin(toRadians(randAngle)) * randDist;
				var dotX = cellW * i + cellW / 2;
				var dotY = cellH + cellH / 2;
				var dot = canvas.circle(diameter)
					.x(dotX - diameter / 2)
					.y(dotY - diameter / 2)
					.fill(colour_2)
					.stroke("none")
				group.add(dot);
			}
		break;
		case 2:
			var shape = canvas.rect(w, h / fp / 4 * 3)
				.x(0)
				.cy(h / fp / 2 * 3)
				.fill(colour_1)
				.stroke("none")

			var group = canvas.group();
			var total = rand(2) + 1;
			var cellW = w / total;
			var cellH = h / fp;
			
			var diameter = Math.min(cellW / 3, cellH / 3);
			var randAngle = rand(360);
			var randDist = rand(Math.floor((cellH - diameter) / 2 * 0.9));
			var showLine = rand(2) ? true : false;

			for (var i = 0; i < total; i++) {
				if (showLine) {
					var line = canvas.line([cellW * i + cellW / 2,0, cellW * i + cellW / 2,h])
						.stroke({color: colour_3, opacity: 1, width: 4})
						.css('stroke-linejoin', 'round')
						.css('stroke-linecap', 'round')
					group.add(line);
				}

				var boundCircle = canvas.circle(cellH)
					.cx(cellW * i + cellW / 2)
					.cy(cellH + cellH / 2)
					.fill(colour_base)
					.stroke("none")
				group.add(boundCircle);
				var clone = boundCircle.clone();
				clone.scale(0.9).fill(colour_4);
				group.add(clone);

				//var dotX = cellW * i + cellW / 2 + Math.cos(toRadians(randAngle)) * randDist;
				//var dotY = cellH + cellH / 2 + Math.sin(toRadians(randAngle)) * randDist;
				var dotX = cellW * i + cellW / 2;
				var dotY = cellH + cellH / 2;
				var dot = canvas.circle(diameter)
					.x(dotX - diameter / 2)
					.y(dotY - diameter / 2)
					.fill(colour_2)
					.stroke("none")
				group.add(dot);
			}
		break;
		case 3:
			var group = canvas.group();
			var total = rand(2) + 1;
			var cellW = w / total;
			var cellH = h / fp;
			
			var diameter = Math.min(cellW / 3, cellH / 3);
			var randAngle = rand(360);
			var randDist = rand(Math.floor((cellH - diameter) / 2));
			var showLine = rand(2) ? true : false;

			for (var i = 0; i < total; i++) {
				if (showLine) {
					var line = canvas.line([cellW * i + cellW / 2,0, cellW * i + cellW / 2,h])
						.stroke({color: colour_3, opacity: 1, width: 4})
						.css('stroke-linejoin', 'round')
						.css('stroke-linecap', 'round')
					group.add(line);
				}

				var boundSquare = canvas.rect(cellH, cellH)
					.cx(cellW * i + cellW / 2)
					.cy(cellH + cellH / 2)
					.fill(colour_2)
					.stroke("none")
				group.add(boundSquare);
				
				//var dotX = cellW * i + cellW / 2 + Math.cos(toRadians(randAngle)) * randDist;
				//var dotY = cellH + cellH / 2 + Math.sin(toRadians(randAngle)) * randDist;
				var dotX = cellW * i + cellW / 2;
				var dotY = cellH + cellH / 2;
				var dot = canvas.circle(diameter)
					.x(dotX - diameter / 2)
					.y(dotY - diameter / 2)
					.fill(colour_4)
					.stroke("none")
				group.add(dot);
			}
		break;
		case 4:
			var group = canvas.group();
			var total = rand(2) + 1;
			var cellW = w / total;
			var cellH = h / fp;
			
			var diameter = Math.min(cellW / 3, cellH / 3);
			var randAngle = rand(360);
			var randDist = rand(Math.floor((cellH - diameter) / 2));
			var showLine = rand(2) ? true : false;

			for (var i = 0; i < total; i++) {
				if (showLine) {
					var line = canvas.line([cellW * i + cellW / 2,0, cellW * i + cellW / 2,h])
						.stroke({color: colour_3, opacity: 1, width: 4})
						.css('stroke-linejoin', 'round')
						.css('stroke-linecap', 'round')
					group.add(line);
				}

				var boundCircle = canvas.circle(cellH)
					.cx(cellW * i + cellW / 2)
					.cy(cellH + cellH / 2)
					.fill(colour_2)
					.stroke("none")
				group.add(boundCircle);
				
				//var dotX = cellW * i + cellW / 2 + Math.cos(toRadians(randAngle)) * randDist;
				//var dotY = cellH + cellH / 2 + Math.sin(toRadians(randAngle)) * randDist;
				var dotX = cellW * i + cellW / 2;
				var dotY = cellH + cellH / 2;
				var dot = canvas.circle(diameter)
					.x(dotX - diameter / 2)
					.y(dotY - diameter / 2)
					.fill(colour_4)
					.stroke("none")
				group.add(dot);
			}
		break;
	}
}

//Draw Center Bottom
function drawCenterBottom(c) {
	/*var shape = canvas.rect(w, h / fp)
		.fill("#fff")
		.stroke({color: "#000", opacity: 1, width: 0.5})
		.x(0)
		.y(h / fp * 2)*/
	
	var cellW = w / 5;
	var cellH = h / fp / 4 * 3;

	switch(c) {
		case 0:
			if (rand(2) == 0) {
				var dot = canvas.circle(w / 20)
					.cx(w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
				var dot = canvas.circle(w / 20)
					.cx(w - w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
			}

			var nose = canvas.polyline([
					0, cellH / 2,
					cellW / 2, 0,
					cellW, cellH / 2,
					cellW / 2, cellH,
					0, cellH / 2
				])
				.cx(w / 2)
				.cy(h / fp * 2 + h / fp / 2)
				.fill(colour_3)
				.stroke("none")
		break;
		case 1:
			if (rand(2) == 0) {
				var dot = canvas.circle(w / 20)
					.cx(w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
				var dot = canvas.circle(w / 20)
					.cx(w - w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
			}

			var nose = canvas.polyline([
					cellW / 2, 0,
					cellW, cellH,
					0, cellH,
					cellW / 2, 0
				])
				.cx(w / 2)
				.cy(h / fp * 2 + h / fp / 2)
				.fill(colour_3)
				.stroke("none")
		break;
		case 2:
			if (rand(2) == 0) {
				var dot = canvas.circle(w / 20)
					.cx(w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
				var dot = canvas.circle(w / 20)
					.cx(w - w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
			}

			var nose = canvas.polyline([
					cellW / 2, cellH,
					0, 0,
					cellW, 0,
					cellW / 2, cellH
				])
				.cx(w / 2)
				.cy(h / fp * 2 + h / fp / 2)
				.fill(colour_3)
				.stroke("none")

			/*var nose = canvas.rect(cellH / 4 * 3, cellH / 2)
				.cx(w / 2 - cellH / 2)
				.cy(h / fp * 2 + h / fp / 2)
				.fill(colour_3)
				.stroke("none")
			var nose = canvas.rect(cellH / 4 * 3, cellH / 2)
				.cx(w / 2 + cellH / 2)
				.cy(h / fp * 2 + h / fp / 2)
				.fill(colour_3)
				.stroke("none")*/
		break;
		case 3:
			if (rand(2) == 0) {
				var dot = canvas.circle(w / 20)
					.cx(w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
				var dot = canvas.circle(w / 20)
					.cx(w - w / 20)
					.cy(h / fp * 2 + w / 20)
					.fill(colour_1)
					.stroke("none");
			}

			var nose = canvas.circle(cellH)
				.cx(w / 2)
				.cy(h / fp * 2 + h / fp / 2)
				.fill(colour_3)
				.stroke("none")
		break;
		default:
	}
}

//Draw Bottom
function drawBottom(c) {
	/*var shape = canvas.rect(w, h / fp)
		.fill("#fff")
		.stroke({color: "#000", opacity: 1, width: 0.5})
		.x(0)
		.y(h / fp * 3)*/

	switch(c) {
		case 0:
			if (rand(2) == 0) {
				var shape = canvas.rect(w - w / 20, h / fp  - w / 20)
					.fill(colour_2)
					.stroke("none")
					.cx(w / 2)
					.cy(h / fp * 3 + h / fp / 2)
			}

			//Single rect
			var mouthW = w * ((rand(6) + 4) / 10);
			var mouthH = h / fp / 2;
			var mouth = canvas.rect(mouthW, mouthH)
				.cx(w / 2)
				.cy(h / fp * 3 + mouthH)
				.fill(colour_4)
				.stroke("none")
		break;
		case 1:
			//Beard and checked
			var group = canvas.group();
			var beard = canvas.rect(w, h / fp)
				.x(0)
				.y(h / fp * 3)
				.fill(colour_2)
				.stroke("none")
			group.add(beard);

			var mouthW = w * ((rand(6) + 4) / 10);
			var mouthH = h / fp / 2;
			var checkCol = rand(6) * 2 + 5;
			var checkRow = 2;
			var checkW = mouthW / checkCol;
			var checkH = mouthH / checkRow;
			var checkC = 0;
			for (var j = 0; j < checkRow; j++) {
				for (var i = 0; i < checkCol; i++) {
					var mouth = canvas.rect(checkW, checkH)
						.fill(colour_4)
						.stroke("none")
						.x((w / 2 - mouthW / 2) + checkW * i)
						.y((h / fp * 3 + h / fp / 2 - mouthH / 2) + checkH * j)
					
					if(j % 2 == 0) {
						mouth.fill(colour_2)
						if(i % 2 == 0) {
							mouth.fill(colour_4)
						}
					} else {
						if(i % 2 == 0) {
							mouth.fill(colour_2)
						}
					}
					group.add(mouth);
					checkC++;
				}
			}
		break;
		case 2:
			//Single rect and beard
			var beard = canvas.polyline([
					0, h / fp * 3 - h / fp / 2,
					w / 2, h / fp * 3,
					w, h / fp * 3 - h / fp / 2,
					w, h,
					0, h,
					0, h / fp * 3 - h / fp / 2
				])
				.x(0)
				.y(h / fp * 3 - h / fp / 2)
				.fill(colour_2)
				.stroke("none")
			var mouth = canvas.rect(w * ((rand(6) + 4) / 10), h / fp / 2)
				.cx(w / 2)
				.cy(h / fp * 3 + h / fp / 2)
				.fill(colour_4)
				.stroke("none")
		break;
		case 3:
			//Double rect
			var mouthW = w * ((rand(6) + 4) / 10);
			var mouthH = h / fp / 4;
			var mouth = canvas.rect(mouthW, mouthH)
				.cx(w / 2)
				.cy(h / fp * 3 + h / fp / 2 - mouthH / 2 - 1)
				.fill(colour_4)
				.stroke("none")

			var mouthW = w * ((rand(6) + 4) / 10);
			var mouth = canvas.rect(mouthW, mouthH)
				.cx(w / 2)
				.cy(h / fp * 3 + h / fp / 2 + mouthH / 2 + 1)
				.fill(colour_4)
				.stroke("none")
		break;
	}
}

function toRadians (angle) {
	return angle * (Math.PI / 180);
}

function rand(num) {
  return Math.floor(Math.random() * num);
}

function num(int, isSingle) {
  if(int.toString().length == 1 && !isSingle) {
    return '0'+int.toString();
  }else {
    return int.toString();
  }
}

//Action - Generate
document.querySelector(".btn-generate").addEventListener("click", generate);

//Action - Copy to clipboard
//Credit to @georgedoescode https://codepen.io/georgedoescode/pen/dyNVNjG
document.querySelector(".btn-copy").addEventListener("click", function() {
  copy(canvas.node.outerHTML);
  document.querySelector("svg.clipboard").classList.remove("show");
  document.querySelector("svg.clipboard-done").classList.add("show");
  
  setTimeout(function () {
    document.querySelector("svg.clipboard").classList.add("show");
    document.querySelector("svg.clipboard-done").classList.remove("show");
  }, 1500);
});

//Action - Save as svg
//Credit to @terabaud https://codepen.io/terabaud/pen/mdJqeYz
function save() {
  var anchor = document.createElement('a');
  anchor.setAttribute('download', 'robot2-'+artworkID+'.svg');
  var code = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"".concat(canvas.viewbox(), "\">").concat(canvas.node.innerHTML, "</svg>");
  anchor.setAttribute("href", "data:application/octet-stream;base64," + btoa(code));
  anchor.setAttribute('target', '_blank');
  return anchor;
}

document.querySelector(".btn-save").addEventListener('click', function() {
  save()['click']();
});

//Action - Save as png
//Credit to https://github.com/exupero/saveSvgAsPng
document.querySelector(".btn-save-image").addEventListener('click', function() {
  saveSvgAsPng(document.getElementById("canvas"), 'robot2-'+artworkID+".png", {scale: 1});
});
              
            
!
999px

Console