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

              
                - var amin = 90, amax = 170, aval = 120;
- var vb_u = 1000, vb_w = Math.ceil(2*Math.PI)*vb_u;
- var vb_h = Math.ceil(2*Math.cos(0) + 1)*vb_u;
- var vb_x = -.5*vb_w, vb_y = -.5*vb_h, na = .01*vb_w;
- var k = .025, ax_x = (1 - k)*vb_x, ax_y = (1 - k)*vb_y;
- var fs = .024*vb_w, ng = 6, ug = Math.PI/ng*vb_u;
- var ns = 360, us = 2*Math.PI/ns;
- var sx = -Math.round(aval/180*Math.PI*vb_u);
- var sy = Math.round(Math.sin(aval/180*Math.PI)*vb_u);
- var ex = Math.round(aval/180*Math.PI*vb_u);
- var ey = -Math.round(Math.sin(aval/180*Math.PI)*vb_u);
- var so = +((180 - aval)/360).toFixed(3);
- var eo = +((180 + aval)/360).toFixed(3);
- var pr = .01*vb_h, ps = 2*pr, pr1 = Math.round(.65*pr);
- var mx = .25*ns*us*vb_u;

style
	| html {
	| 	--amin: #{amin}; --amax: #{amax}; --aval: #{aval}
	| }
	| [x] {
	| 	font: #{fs}px consolas, monaco, monospace;
	| 	letter-spacing: #{-fs/5}
	| }

form
	section
		label(for='sa') start angle
		span.swrap(style=`--min:${-amax};--max:${-amin};--val:${-aval}`)
			input#sa(type='range' min=-amax max=-amin value=-aval)
			output(for='sa') #{-aval}
	section
		label(for='ea') end angle
		span.swrap(style=`--min:${amin};--max:${amax};--val:${aval}`)
			input#ea(type='range' min=amin max=amax value=aval)
			output(for='ea') #{aval}

svg(viewBox=[vb_x, vb_y, vb_w, vb_h].join(' '))
	marker#e(markerWidth=na markerHeight=na 
						viewBox='0 -4 8 8' 
						orient='auto' refX='7')
		path(d='M8 0 0-4V4')
	pattern#p(width=ps height=ps patternUnits='userSpaceOnUse' patternTransform='rotate(45)')
		rect(width=ps height=Math.round(.2*ps))
	linearGradient#g
		stop#os(stop-color='#ccc' offset=so)
		stop(stop-color='#a57' offset=0)
		stop#oe(stop-color='#a57' offset=eo)
		stop(stop-color='#ccc' offset=0)
	
	path.a(d=`M${ax_x} 0H${-ax_x}`)
	path.a(d=`M0 ${-ax_y}V${ax_y}`)
	text(x=-(ax_x + .5*fs) y=-.5*fs) k
	text(x=-4*fs y=(.7*fs + ax_y)) sin(<tspan>k</tspan>)
	
	- var gd = [];
	- for(var i = 1; i <=ng; i++) {
		- var ca = i*ug, cy = Math.round(Math.sin(ca/vb_u)*vb_u);
		- gd.push(`M${Math.round(ca)}-${vb_u}V${vb_u}`);
		- if(i <= .5*ng) gd.push(`M${ax_x} ${cy}H${-ax_x}`) 
	- }
	path#u(d=gd.join(''))
	use(xlink:href='#u' transform='rotate(180)')
	
	rect#r(x=sx y=-sy width=(ex - sx) height=(sy - ey))
	
	- gd = [];
	- for(var i = 0; i <=ns; i++) {
		- var ca = (i - .5*ns)*us, cx = Math.round(ca*vb_u);
		- var cy = Math.round(vb_u*Math.sin(ca - Math.PI));
		- gd.push([cx, cy]);
	- }
	path(d=`M${gd.join(' ')}`)
	
	g#v
		circle(r=pr1 cy=-vb_u)
		circle#ymax(r=pr1 cx=Math.round(mx) cy=-vb_u)
		circle(r=pr1 cx=Math.round(mx))
		circle#xmax(r=pr1 cx=Math.round(2*mx))
	use(xlink:href='#v' transform='rotate(180)')
	
	circle(r=pr)
	circle#ps(r=pr cx=sx cy=sy)
	circle#pe(r=pr cx=ex cy=ey)
	circle#psx(r=pr1 cx=sx)
	circle#psy(r=pr1 cy=sy)
	circle#pex(r=pr1 cx=ex)
	circle#pey(r=pr1 cy=ey)
	
	text(x=(mx - .7*fs) y=fs) 90°
	text(x=2*mx - fs y=fs) 180°
	text(x=-(mx + fs) y=-.3*fs) -90°
	text(x=-(2*mx + 1.25*fs) y=-.3*fs) -180°
	text(x=-.8*fs y=-.3*fs) 0
	text(x=-.8*fs y=-(vb_u + .3*fs)) 1
	text(x=.1*fs y=(vb_u + .9*fs)) -1

.box
              
            
!

CSS

              
                $demo-lh: 1.25;
$demo-lh: 1.25;
$demo-dark: #262626;
$demo-light: invert($demo-dark);
$demo-ll: #555;
$demo-hl: #f90;
$ctrl-pad: .5em;
$ctrl-wmax: 32em;

$lbl-w: 5.25em;

$thumb-d: 1.25em;
$thumb-r: .5*$thumb-d;

$track-h: 6px;
$track-r: .5*$track-h;
$track-m: calc((100% - #{$thumb-d}));
$track-s: calc(#{$track-m}/var(--range));
$track-x: calc(#{-$track-r} - .5*#{$track-m}/var(--range));

$t: .3s;

@mixin track {
	border: none;
	width: 100%; height: $track-h;
	border-radius: $track-r;
	background: $demo-ll;
	background: 
		radial-gradient(circle at calc(var(--pos) + #{$thumb-r}) 50%, 
				transparent $thumb-r, $demo-ll 0);
}

@mixin thumb {
	box-sizing: border-box;
  border: solid .25*$thumb-d transparent;
	width: $thumb-d; height: $thumb-d;
	border-radius: 50%;
	background: $demo-ll content-box;
	transition: $t;
	transition-property: border-width, background-color
}

@mixin thumb-focus {
	border-width: 0;
	background: $demo-hl
}

* {
	margin: 0;
	font: inherit;
	vector-effect: non-scaling-stroke
}

html { font: 1.25em/ #{$demo-lh} trebuchet ms, sans-serif; }

body {
	--fs: 1.125em;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 10em; height: 100vh;
}

form {
	display: flex;
	align-self: center;
	align-items: center;
	justify-content: space-around;
	border: solid 0 $demo-dark;
	border-width: 0 calc(50vw - .5*#{$ctrl-wmax});
	padding: $ctrl-pad;
	width: 100vw;
	max-width: $ctrl-wmax;
	background: $demo-dark;
	color: $demo-light;
	
	@media (max-width: 600px) {
		flex-direction: column;
		
		.swrap { width: calc(100% - #{2*$ctrl-pad}) }
	}
}

section {
	flex: 1;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	border: none;
	padding: .25em 0 1.25em;
	max-width: $ctrl-wmax;
}

label {
	padding-right: .5em;
	width: $lbl-w;
	text-align: right;
	
	&:after { content: ':' }
}

.swrap {
	--range: calc(var(--max) - var(--min));
	--pos: calc((var(--val) - var(--min))*(100% - #{$thumb-d})/var(--range));
	position: relative;
	width: calc(100% - #{2*$ctrl-pad + $lbl-w});
}

[type='range'] {
	&::-webkit-slider-runnable-track, 
	&::-webkit-slider-thumb, & {
		-webkit-appearance: none
	}
	
	width: 100%; height: 1.5*$thumb-d;
	background: transparent;
	cursor: pointer;
	
	&::-webkit-slider-runnable-track {
		@include track
	}
	
	&::-moz-range-track {
		@include track
	}
	
	&::-ms-track {
		@include track;
		background: $demo-ll;
		color: transparent
	}
	
	&::-ms-fill-lower {
		display: none
	}
	
	&::-webkit-slider-thumb {
		margin-top: calc(#{$track-r} - #{$thumb-r});
		@include thumb
	}
	
	&::-moz-range-thumb {
		@include thumb
	}
	
	&::-ms-thumb {
		margin-top: 0;
		@include thumb;
		border-color: $demo-dark
	}

	&:focus {
		outline: none;
		
		&::-webkit-slider-thumb {
			@include thumb-focus
		}

		&::-moz-range-thumb {
			@include thumb-focus
		}

		&::-ms-thumb {
			@include thumb-focus
		}
		
		+ output { --f: .99 }
	}
	
	+ output {
		--f: .01;
		position: absolute;
		top: 100%; left: calc(#{$thumb-r} + var(--pos));
		padding: 0 .375em;
		border-radius: 5px;
		transform-origin: 50% 0;
		transform: translate(-50%) scale(var(--f));
		opacity: var(--f);
		background: $demo-hl;
		transition: opacity $t;
	}
	
	@supports not (clip-path: circle(5px)) {
		+ output { display: none }
	}
}

svg { max-height: calc(100vh - 8rem) }

[d], [r], #r { fill: none; stroke: $demo-dark }

[d], #r { mix-blend-mode: darken }

#p rect, [r] { fill: $demo-hl }

#e [d] { fill: $demo-dark; stroke: none }

.a, [r], rect {
  stroke-width: 2px;
  marker-end: url(#e)
}

#u { stroke: $demo-light }

#r {
	fill: url(#p);
	stroke: $demo-hl;
	stroke-dasharray: 8px
}

#r + [d] {
	stroke: url(#g);
	stroke-width: 4px
}

tspan, [d] + [x] { font-style: italic }

@supports not (vector-effect: non-scaling-stroke) {
	[d][d] { stroke-width: 14 !important; marker: none }
}

.box {
	width: 100%; min-height: 3rem;
	flex: 1;
	--stop-ini: 43%;
	--stop-fin: 57%;
	background: linear-gradient(90deg, 
		#ff9800 var(--stop, var(--stop-ini)), 
		#3c3c3c 0);
	font: 3em/ 1 Leckerli One, cursive;
	text-align: center;
	
	@media (min-aspect-ratio: 6/5) {
		line-height: 2;
	}
	
	&:after {
		display: flex;
  	flex-direction: row;
		justify-content: center;
  	align-items: center;
		height: 100%;
		cursor: pointer;
		content: 'Click!';
		
		@supports (mix-blend-mode: screen) {
			/* in supports because 
 		 	 * background: inherit 
		 	 * breaks Edge for some reason 
		 	 * (sorry, I had no better idea) */
			background: inherit;
			-webkit-background-clip: text;
			background-clip: text;
			color: transparent;
			filter: invert(1) grayscale(1) contrast(10);
		}
	}
}
              
            
!

JS

              
                const _S = document.querySelector('span'), 
			_R = document.getElementById('r'), 
			_B = document.querySelector('.box'), 
			XMAX = document.getElementById('xmax').getAttribute('cx'), 
			YMAX = document.getElementById('ymax').getAttribute('cy'), 
			END_NAMES = ['s', 'e'], 
			N_ENDS = END_NAMES.length,
			VARS = {}, NF = 50, 
			S = getComputedStyle(_B), 
			INI = +S.getPropertyValue('--stop-ini').replace('%', ''), 
			FIN = +S.getPropertyValue('--stop-fin').replace('%', ''), 
			PRC = FIN - INI;

let ini, fin, range, 
		rID = null, f = 0, dir = -1;

function updateAng(e) {
	let _t = e.target;
		
	if(_t.type === 'range') {
		let a_new = +_t.value, name = _t.id.charAt(0);
		
		if(a_new !== VARS[name].ang) {
			VARS[name].ang = a_new;
			
			updateRangeTip(name);
			updateEnd(name);
			updateArea();
		}
	}
};

function updateRangeTip(name) {
	let i = VARS[name].ang - VARS[name].sub;
	
	VARS[name].tip.textContent = VARS[name].ang;
	VARS[name].parent.style.setProperty('--val', VARS[name].ang)
};

function updateEnd(name) {
	let i = +(VARS[name].ang/360 + .5).toFixed(3), 
			k = VARS[name].ang/180, 
			x = k*XMAX, 
			y = Math.sin(k*Math.PI)*YMAX;
	
	VARS[name].o.setAttribute('offset', i);
	VARS[name].p.setAttribute('cx', x);
	VARS[name].px.setAttribute('cx', x);
	VARS[name].p.setAttribute('cy', y);
	VARS[name].py.setAttribute('cy', y);
};

function updateArea() {
	let x = +VARS.s.px.getAttribute('cx'), 
			y = +VARS.e.py.getAttribute('cy'), 
			w = +VARS.e.px.getAttribute('cx') - x, 
			h = +VARS.s.py.getAttribute('cy') - y;
	
	_R.setAttribute('x', x);
	_R.setAttribute('y', y);
	_R.setAttribute('width', w);
	_R.setAttribute('height', h);
};

function timing(k) {
	let sa = VARS.s.ang*Math.PI/180, 
			ea = VARS.e.ang*Math.PI/180, 
			sv = Math.sin(sa), 
			ev = Math.sin(ea);
	
	return dir > 0 ? 
		(Math.sin(k*(ea - sa) + sa) - sv)/(ev - sv) : 
		(Math.sin(k*(ea - sa) - ea) + ev)/(ev - sv);
};

function stopAni() {
  cancelAnimationFrame(rID);
  rID = null;  
};

function updatePrc() {
	f += dir;
	
	let k = f/NF;	
  
  _B.style.setProperty(
		'--stop', 
		`${+(INI + timing(k)*PRC).toFixed(2)}%`
	);
  
  if(!(f%NF)) {
    stopAni();
    return
  }
  
  rID = requestAnimationFrame(updatePrc)
};

(function init() {	
	for(let i = 0; i < N_ENDS; i++) {
		var name = END_NAMES[i]
		
		VARS[name] = {};
		
		VARS[name].range = document.getElementById(`${name}a`);
		VARS[name].parent = VARS[name].range.parentNode;
		VARS[name].ang = +VARS[name].range.value;
		VARS[name].sub = Math.min(VARS[name].range.min, VARS[name].range.max);
		VARS[name].tip = document.querySelector(`output[for='${name}a']`);
		VARS[name].o = document.getElementById(`o${name}`);
		VARS[name].p = document.getElementById(`p${name}`);
		VARS[name].px = document.getElementById(`p${name}x`);
		VARS[name].py = document.getElementById(`p${name}y`);
		
		if(name === 'e') {
			ini = +VARS[name].range.min;
			fin = +VARS[name].range.max;
			range = fin - ini;
		}
	}
		
	addEventListener('change', updateAng, false);
	addEventListener('input', updateAng, false);
	
	_B.addEventListener('click', e => {
		if(rID) stopAni();
		dir *= -1;
		updatePrc();
	}, false);
})();
              
            
!
999px

Console