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 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

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

              
                - var dim = 2500; //- svg dimension
- var tl = -.5*dim; //- top left coord
- var ei = .02*dim; //- inner edge length
- var th = ei; //-tooth height
- var hei = .5*ei; //- half edge length
- var twr = .8; //-tooth width ratio
- var b = twr*hei;
- var t2 = Math.pow(b, 2);
- var data = [];

- data.push({'n': 16, 'x': .5*tl, 'y': .25*tl});
- data.push({'n': 13, 'j': 2});
- data.push({'n': 12, 'j': 6});
- data.push({'n': 9, 'j': 3});
- data.push({'n': 8, 'j': 3, 'r': .35});

- data.push({'n': 14, 'r': .45, 'm': 1, 'p': -60});
- data.push({'n': 9, 'j': -6});
- data.push({'n': 15, 'j': 2});

- var n = data.length;

mixin cog(i)
	- var np = 2*data[i].n;
	- data[i].ba = Math.PI/data[i].n;
	- var hba = .5*data[i].ba;
	- var rii = hei/Math.tan(hba);
	- var rio = rii + th;
	- var li = Math.sqrt(t2 + Math.pow(rii, 2));
	- var lo = Math.sqrt(t2 + Math.pow(rio, 2));
	- var ai = Math.atan(b/rii);
	- var ao = Math.atan(b/rio);
	- var v = []; //-array of vertices
	- for(var j = 0; j < np; j++) {
		- var j1 = j%2;
		- var r = j1?lo:li;
		- for(var k = 0; k < 2; k++) {
			- var a = j*data[i].ba - Math.pow(-1, k)*(j1?ao:ai);
			- var x = r*Math.cos(a);
			- var y = r*Math.sin(a);
			- v.push([x, y]);
		- }
	- }
	//- compute position of cog
	- data[i].rco = rio/Math.cos(hba);
	- data[i].a = 0;
	- data[i].badg = 180/data[i].n;
	- var a = 0;
	- var r = 0;
	- if(i) {
		- if(data[i].j) {
			- data[i].a = data[i - 1].a + (2*data[i].j + 1)*data[i - 1].badg + 180;
			- a = (data[i].a/180 - 1)*Math.PI;
			- r = data[i].rco + data[i - 1].rco - th;
		- }
		
		-if(data[i].m) {
			- a = (data[i].p*Math.PI/180) || 0;
			- r = data[i].rco + data[i - 1].rco + data[i].m*th;
		- }
		
		- data[i].x = data[i - 1].x + r*Math.cos(a);
		- data[i].y = data[i - 1].y + r*Math.sin(a);
	- }
	- var t = 'translate(' + data[i].x + ' ' + data[i].y + ')rotate(' + data[i].a + ')'
	g.pos(transform=t)
		polygon(points=v.join(' '))
		- if(data[i].r) {
			- data[i].ra = data[i].r*data[i].rco;
			circle(r=data[i].ra)
			- if(data[i - 1].r) {
				- var dr = data[i].ra - data[i - 1].ra;
				- var beta = Math.acos(dr/r);
				- var gamma = Math.PI - beta;
				- var a2 = data[i].p + 180;
				- var f = (beta > .5*Math.PI)*1;
				- var x = data[i].ra*Math.cos(beta);
				- var y = data[i].ra*Math.sin(beta);
				- var d = 'M' + x + ',' + -y + 'A' + data[i].ra + ' ' + data[i].ra + ' 0 1 ' + f + ' ' + x + ' ' + y;
				- var x = r + data[i - 1].ra*Math.cos(gamma);
				- var y = data[i - 1].ra*Math.sin(gamma);
				- d += 'L' + x + ' ' + y + 'A' + data[i - 1].ra + ' ' + data[i - 1].ra + ' 0 1 ' + f + ' ' + x + ' ' + -y + 'z';
				path(d=d transform=`rotate(${a2})`)
			- }
		- }

mixin heart()
	- var ymm = .225*tl;
	- var yum = .625*tl;
	- var xo = -.625*tl;
	- var yuo = .625*tl;
	- var ymo = .2*tl;
	- var ylo = -.25*tl;
	- var ylm = -.5625*tl;
	- var d = 'M0,' + ymm + 'C0 ' + yum + ' ' + xo + ' ' + yuo + ' ' + xo + ' ' + ymo + 'Q' + xo + ' ' + ylo + ' 0 ' + ylm + 'Q' + -xo + ' ' + ylo + ' ' + -xo + ' ' + ymo + 'C' + -xo + ' ' + yuo + ' 0 ' + yum + ' 0 ' + ymm;
	mask#heart
		rect.w(x=tl y=tl width=dim height=dim)
		path(d=d)
	rect.cover(x=tl y=tl width=dim height=dim mask='url(#heart)')
	

svg(viewBox=`${tl} ${tl} ${dim} ${dim}`)
	g.train
		- for(var i = 0; i < n; i++)
			+cog(i)
	+heart
              
            
!

CSS

              
                @import 'compass/css3';

$bg: #000;
$svg-dim: 100vmin;
$g0: radial-gradient($bg 14%, transparent 17%);
$g1: radial-gradient(#999 15%, transparent 20%);
$bs: 1.5em;
$off: .05*$bs;
$data: 16 #fbd047, 13 #fb7c6d, 12 #f561ca, 9 #dd7aef, 8 #c4a6dd .35, 14 #62b6f2 .45, 9 #84d2ba, 15 #b8ed83;
$nc: length($data);
$t: .5s;
$k: 1;
$f: 0;
$dir: normal reverse;

body {
	display: flex;
	justify-content: center;
	margin: 0;
	height: 100vh;
	background: $bg;
}

svg {
	align-self: center;
	width: $svg-dim; height: $svg-dim;
	box-shadow: inset 0 0 0 .125em $bg;
	background: 
		$g0, $g0 .5*$bs .5*$bs, 
		$g1 0 $off, $g1 .5*$bs .5*$bs + $off
		#666;
	background-size: $bs $bs;
}

@for $i from 0 to $nc {
	$cdata: nth($data, $i + 1);
	$c: nth($cdata, 2);
	$nt: nth($cdata, 1);
	
	@if $i > 0 and length($cdata) > 2 {
		$pdata: nth($data, $i);
		
		@if length($pdata) > 2 {
			$hap: .5*180deg/nth($pdata, 1);
			$hac: .5*180deg/$nt;
			$f: 1 - $f;
			$k: $k*nth($cdata, 3)/nth($pdata, 3)*(.5/sin($hac) + 1/cos($hac))/(.5/sin($hap) + 1/cos($hap));
		}
	}
	
	.pos:nth-child(#{$i + 1}) {
		polygon {
			fill: $c;
			animation-duration: $nt*$k*$t;
			animation-direction: nth($dir, ($i + $f)%2 + 1);
		}
		
		circle { fill: darken($c, 20%) }
	}
}

polygon { animation: r 0s linear infinite; }

@keyframes r { to { transform: rotate(1turn); } }

.pos path {
	fill: none;
	stroke: #fff;
	stroke-width: 3;
	vector-effect: non-scaling-stroke;
}

mask .w { fill: #fff; }

.cover { fill: $bg; }
              
            
!

JS

              
                
              
            
!
999px

Console