cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <svg viewbox='-1000 -1000 2000 2000'>
	<defs>
		<path id='axis' d='M-1000,0 L977,0 L970,-14 L991,0 L970,14 L977,0z' />
		<circle id='point' r='8'/>
		<line id='moving'/>
	</defs>
	
	<g class='axes'>
		<use xlink:href='#axis'/>
		<text class='var' x='975' y='-25'>x</text>
		<use xlink:href='#axis' 
				 transform='rotate(90)'/>
		<text class='var' y='975' x='25'>y</text>
	</g>
	
	<circle id='guide' r='800'/>
	
	<g class='arc'>
		<path class='fill'/>
		<path class='line'/>
		<text>60°</text>
	</g>
	
	<g class='ang-pt' id='a'>
		<use xlink:href='#point'/>
		<text class='var'>A</text>
	</g>
	
	<g class='deg-labels'></g>
	
	<g class='rot'>
		<g class='line'>
			<use xlink:href='#moving'/>
			<use xlink:href='#moving'/>
		</g>
		<g class='ang-pt' id='b'>
			<use xlink:href='#point'/>
			<text class='var'>B</text>
		</g>
	</g>
	
	<g class='ang-pt' id='o'>
		<use xlink:href='#point'/>
		<text class='var'>O</text>
	</g>
</svg>

<form class='hidden'>
	<button title='toggle controls'>toggle controls</button>
	<input type='range' id='angle' max='360' value='60'/>
</form>

<div class='usage-inf'>drag orange line</div>
            
          
!
            
              @import 'compass/css3';

$theme-c: #e18728;
$hl-c: #be4c39;

$arc-bg: #d49b00;
$arc-c: #be4c39;
$arc-txt: #9351a6;
$coord-syst-c: #ccc;
$deg-label-c: #838383;
$base-pt-c: $deg-label-c;

@mixin hide-me {
	opacity: .001;
	pointer-events: none;
	
	* { transform: scale(0); }
}

@mixin show-me {
	opacity: .999;
	pointer-events: auto;
	
	* { transform: scale(1); }
}

html { overflow: hidden; }

body { margin: 0; }

svg {
	display: block;
	margin: calc(50vh - 50vmin) auto;
	min-width: 10em; min-height: 10em;
	width: 100vmin; height: 100vmin;
	max-width: 100em; max-height: 100em;
	font-size: 1em;
	
	> .ang-pt {
		fill: $base-pt-c;
	}
}

text {
	font: 4em serif;
	
	.prevent-sel & { user-select: none; }
}

.var {
	opacity: 0;
	font-style: italic;
}

[id='guide'] {
	fill: transparent;
	stroke: #ccc;
	stroke-width: 5;
	stroke-dasharray: 16;
}

.arc {
	.fill {
		fill: lighten($arc-bg, 30%);
	}
	.line {
		fill: none;
		stroke: $arc-c;
		stroke-width: 4;
		vector-effect: non-scaling-stroke;
	}
	
	text {
		fill: $arc-txt;
		dominant-baseline: middle;
		font: 700 168px monospace;
		text-anchor: middle;
	}
}

[id='axis'] {
	stroke: $coord-syst-c;
	stroke-width: 1.5;
	vector-effect: non-scaling-stroke;
}

.axes {
	fill: $coord-syst-c;
	
	text {
		&:first-of-type {
			text-anchor: end;
		}
	}
}

[id='a'] text { dominant-baseline: hanging; }

.deg-labels {
	cursor: pointer;
	
	:not(:nth-of-type(9n + 1)) {
		@include hide-me;
	}
	
	rect, text {
		transition: .35s ease-out;
		pointer-events: inherit;
	}
	
	rect { fill: none; }
	
	:nth-of-type(18n + 1) rect {
		fill: rgba(#fff, .7);
	}
	
	text {
		fill: $deg-label-c;
		dominant-baseline: middle;
		font: 700 168px monospace;
		text-anchor: middle;
	}

	g:hover {
		rect { fill: $hl-c; }
		text { fill: #fff; }
	}
}

.rot {
	fill: $hl-c;
	cursor: pointer;
}

[id='moving'] {
	vector-effect: non-scaling-stroke;
}

.line use {	
	&:nth-of-type(1) {
		stroke: transparent;
		stroke-width: 50;
	}
	&:nth-of-type(2) {
		stroke: $theme-c;
		stroke-width: 4;
	}
}

[id='b'], [id='o'] {
	text { dominant-baseline: middle; }
}

.ang-pt text {
	text-anchor: middle;
}

		
@media ( min-width: 240px) and 
			 (min-height: 240px) {
	.deg-labels, .arc {
		text { font-size: 128px; }
	}
}

@media ( min-width: 320px) and 
			 (min-height: 320px) {
	.var {
		opacity: .999;
		font-size: 100px;
	}
	
	.deg-labels, .arc {
		text { font-size: 102px; }
	}
	
	.deg-labels {		
		:nth-of-type(9n + 1) {
			@include hide-me;
		}
		
		:nth-of-type(6n + 1) {
			@include show-me;
		}
	}
}

@media ( min-width: 480px) and 
			 (min-height: 480px) {
	.var {
		font-size: 70px;
	}
	
	.deg-labels, .arc {
		text { font-size: 72px; }
	}
	
	.deg-labels {		
		:nth-of-type(3n + 1) {
			@include show-me;
		}
		
		:nth-of-type(6n + 1) text {
			fill: $hl-c;
		}
	}
}

@media ( min-width: 800px) and 
			 (min-height: 800px) {
	.var {
		font-size: 43px;
	}
	
	.deg-labels, .arc {
		text { font-size: 48px; }
	}
	
	.deg-labels {		
		:nth-of-type(3n + 1) {
			@include hide-me;
		}
		
		:nth-of-type(2n + 1) {
			@include show-me;
		}
	}
}

@media ( min-width: 1400px) and 
			 (min-height: 1400px) {
	.deg-labels {
		text { font-size: 16px; }
		
		:nth-of-type(n + 1) {
			@include show-me;
		}
	}
}

/* =============== CONTROLS =============== */
$ctrl-bg: #262626;
$ctrl-ll: #aaa;
$ctrl-hl: $theme-c;

$track-w: 13em;
$track-h: .25em;

$thumb-d: 1.25em;

@mixin track() {
	width: $track-w; height: $track-h;
	background: $ctrl-ll;
}

@mixin fill() {
	background: $ctrl-hl;
}

@mixin thumb() {
	border: none;
	width: $thumb-d; height: $thumb-d;
	border-radius: 50%;
	background: $ctrl-hl;
}

form {
	position: fixed;
	bottom: 0; left: 50%;
	padding: .5em;
	transform-origin: 50% 100%;
	transform: translate(-50%);
	background: $ctrl-bg;
	color: $ctrl-ll;
	font: 1em/1.375em trebuchet ms, sans serif;
	transition: .35s;
	
	@media (min-aspect-ratio: 1/1) {
		left: 0; bottom: 50%;
		transform: translate(-50%) 
			rotate(90deg);
		
		input[type='range'] {
			transform: rotate(180deg);
		}
	}
}

.hidden {
	transform: translate(-50%, 100%);
	
	@media (min-aspect-ratio: 1/1) {
		transform: translate(-50%) 
			rotate(90deg) translateY(100%);
	}
}

button {
	position: absolute;
	right: 0; bottom: 100%; left: 0;
	border: none;
	width: 100%;
	border-radius: .5em .5em 0 0;
	background: $ctrl-ll;
	color: $ctrl-bg;
	text-indent: -200vw;
	transition: inherit;
	cursor: pointer;
	
	&:hover {
		color: $ctrl-hl;
	}
	
	&:before {
		$tl: 1em;
		$th: $tl*sqrt(3)/2;
		
		position: absolute;
		top: 50%; left: 50%;
		border: solid 0 transparent;
		border-width: $th .5*$tl 0 .5*$tl;
		border-top-color: currentColor;
		transform: translate(-50%, -50%);
		transition: inherit;
		content: '';
		
		.hidden & {
			transform: translate(-50%, -50%) 
				rotate(180deg);
		}
	}
}

input[type='range'] {
	&, 
	&::-webkit-slider-runnable-track, 
	&::-webkit-slider-thumb {
		-webkit-appearance: none;
	}
	
	display: block;
	margin: 1em auto 0;
	padding: 0;
	width: $track-w; height: 2em;
	background: none;
	font-size: 1em;
	cursor: pointer;
	
	&::-webkit-slider-runnable-track {
		@include track();
	}
	&::-moz-range-track {
		@include track();
	}
	&::-ms-track {
		border: none;
		@include track();
		color: transparent;
	}
	
	&::-moz-range-progress {
		height: $track-h;
		@include fill();
	}
	&::-ms-fill-lower {
		@include fill();
	}
	
	&::-webkit-slider-thumb {
		margin-top: ($track-h - $thumb-d)/2;
		@include thumb();
	}
	&::-moz-range-thumb {
		@include thumb();
	}
	&::-ms-thumb {
		@include thumb();
	}
	
	&::-ms-tooltip { display: none; }
		
	&:focus { outline: none; }
}


.usage-inf {
	position: absolute;
	right: 0; top: 0;
	padding: .5em;
	background: #be4c39;
	color: #fff;
	font: 1.25em verdana, sans-serif;
	transition: .5s;
	
	&.hidden { opacity: 0; }
}
            
          
!
            
              /* because IE up to and including 11 */
Math.hypot = Math.hypot || function() {
  var y = 0;
  var length = arguments.length;

  for (var i = 0; i < length; i++) {
    if (arguments[i] === Infinity || arguments[i] === -Infinity) {
      return Infinity;
    }
    y += arguments[i] * arguments[i];
  }
  return Math.sqrt(y);
};

/* because me lazy */
Object.getOwnPropertyNames(Math).map(function(p) {
  window[p] = Math[p];
});

Node.prototype.setAttrs = function(attr_obj) {
  for(var prop in attr_obj) {
    this.setAttribute(prop, attr_obj[prop]);
  }
};

var NS_URI = 'http://www.w3.org/2000/svg', 
		svg = document.querySelector('svg'), 
		vb = svg.getAttribute('viewBox').split(' ')
					.map(function(d) {
						return ~~d;
					}), 
		svg_rect, sfw, sfh, 
		r = .4*min(vb[2], vb[3]), 
		ra = .2*r, 
		n = 72, 
		cf = PI/180, cfi = 1/cf, 
		lbl_wrap = svg.querySelector('.deg-labels'), 
		deg_labels = [], 
		max_lbl_r = 0, 
		mov_g = svg.querySelector('.rot'), 
		mov_line = document.getElementById('moving'), 
		_a = document.getElementById('a'), 
		_a_pt = _a.querySelector('use'), 
		_a_lbl = _a.querySelector('text'), 
		_o = document.getElementById('o'), 
		_o_pt = _o.querySelector('use'), 
		_o_lbl = _o.querySelector('text'), 
		_b = document.getElementById('b'), 
		_b_pt = _b.querySelector('use'), 
		_b_lbl = _b.querySelector('text'), 
		arc = svg.querySelector('.arc'), 
		arc_fill = arc.querySelector('.fill'), 
		arc_line = arc.querySelector('.line'), 
		arc_lbl = arc.querySelector('text'), 
		angle = ~~arc_lbl.textContent.split('°')[0],
		angle_target = null, r_id = null, 
		angle_dir, angle_motion_unit = 3, 
		dragging = false, 
		form = document.querySelector('form'), 
		toggle = form.querySelector('button'), 
		slider = document.getElementById('angle'), 
		call_allowed = true, 
		ui = document.querySelector('.usage-inf');

var setAngle = function(deg_val) {
	var bb_b = _b_lbl.getBBox(), 
			bb_o = _o_lbl.getBBox(), 
			bb_ang = arc_lbl.getBBox(), 
			ang_lbl_r = .5*hypot(bb_ang.width, bb_ang.height), 
			j = floor(deg_val/180), 
			k = pow(-1, j), 
			d_str = '', 
			rad_val = -deg_val*cf, 
			d_x = ra*cos(rad_val), 
			d_y = ra*sin(rad_val), 
			a_txt = '';
	
	arc.setAttribute(
		'transform', 
		'rotate(' + deg_val + ')'
	);
	
	d_str += 'M' + d_x + ',' + d_y + 
		'A' + ra + ' ' + ra + 
		' 0 ' + j + ' 1 ' + ra + ' 0';
	arc_line.setAttribute('d', d_str);
	
	d_str += 'L0,0z';
	arc_fill.setAttribute('d', d_str);
	
	a_txt = (deg_val > 15) ? 
		('rotate(' + -.5*deg_val + ')' + 
		'translate(' + ~~(ra + ang_lbl_r) + ')' + 
		'rotate(' + -.5*deg_val + ')') : 
		('rotate(' + -deg_val + ')' + 
		'translate(' + ~~(.5*ra) + ' ' + ~~(-.5*ang_lbl_r) + ')')
		
	arc_lbl.textContent = deg_val + '°';
	arc_lbl.setAttribute(
		'transform', 
		a_txt
	);
	
	mov_g.setAttribute(
		'transform', 
		'rotate(' + deg_val + ')'
	);
	
	_b_lbl.setAttribute(
		'transform', 
		'translate(0 ' + ~~(k*bb_b.height) + ')' + 
		'rotate(' + -deg_val + ')'
	);
	_o_lbl.setAttribute(
		'transform', 
		'rotate(' + .5*deg_val + ')' + 
		'translate(' + ~~(-k*bb_o.width) + ')' + 
		'rotate(' + -.5*deg_val + ')'
	);
	
	slider.value = angle;
};

var sizeMe = function() {
	var bbox, xtra = 20, x_off = -xtra*.5;
	
	svg_rect = svg.getBoundingClientRect();
	sfw = vb[2]/svg_rect.width;
	sfh = vb[3]/svg_rect.height;
	
	max_lbl_r = 0;
		
	if(max(svg_rect.width, svg_rect.height) < 480) {
		deg_labels[0].text.textContent = '0°';
	}
	else {
		deg_labels[0].text.textContent = '360°≡0°';
	}
	
	for(var i = 0; i < n; i++){
		bbox = deg_labels[i].text.getBBox();

		max_lbl_r = max(
			max_lbl_r, 
			.5*hypot(bbox.width, bbox.height)
		);

		deg_labels[i].rect.setAttrs({
			'x': ~~bbox.x + x_off, 
			'y': ~~bbox.y, 
			'width': ~~bbox.width + xtra, 
			'height': ~~bbox.height
		});
	}
	
	mov_line.setAttribute('x2', r - 1.25*max_lbl_r);
	
	setAngle(angle);
};

var init = function() {
	var au_deg = 360/n, 
			a_curr, 
			frag = document.createDocumentFragment(), 
			g_curr, lbl_curr, bg_curr, 
			transf_str = '';
		
	_a.setAttribute(
		'transform', 
		'translate(' + ~~(.75*r) + ')'
	);
	_b.setAttribute(
		'transform', 
		'translate(' + ~~(.5*r) + ')'
	);
	
	for(var i = 0; i < n; i++) {
		a_curr = ~~(i*au_deg);
		transf_str = 'rotate(' + a_curr + ')' + 
			'translate(' + ~~(r) + ')' + 
			'rotate(' + -a_curr + ')';
		
		g_curr = document.createElementNS(
			NS_URI, 
			'g'
		);
		g_curr.setAttrs({
			'transform': transf_str, 
			'id': 'd' + a_curr
		});
		
		bg_curr = lbl_curr = document.createElementNS(
			NS_URI, 
			'rect'
		);
		bg_curr.setAttribute('rx', 8);
		
		lbl_curr = document.createElementNS(
			NS_URI, 
			'text'
		);
		lbl_curr.textContent = 
			(i == 0) ? ('360°≡0°') : (a_curr + '°');
		
		deg_labels.push({
			'g': g_curr, 
			'rect': bg_curr, 
			'text': lbl_curr
		});
		
		g_curr.appendChild(bg_curr);
		g_curr.appendChild(lbl_curr);
		frag.appendChild(g_curr);
	}
		
	lbl_wrap.appendChild(frag);
	
	sizeMe();
};

var updateAngle = function() {	
	if(abs(angle_target - angle) < angle_motion_unit) {
		angle = angle_target;
		setAngle(angle);
		
		call_allowed = true;
		cancelAnimationFrame(r_id);
		angle_target = r_id = null;
		return;
	}
	
	angle += angle_dir*angle_motion_unit;
	setAngle(angle);
	
	r_id = requestAnimationFrame(updateAngle);
};

var sliderChange = function() {
	if(call_allowed) {
		angle_target = ~~slider.value;
		angle_dir = (angle_target > angle)?1:-1;
		
		call_allowed = false;
		updateAngle();
	}
};

init();

addEventListener('resize', sizeMe, false);

lbl_wrap.addEventListener('click', function(e) {
	var t = e.target, 
			tag = t.tagName.toLowerCase();
	
	if(r_id) {
		cancelAnimationFrame(r_id);
		r_id = null;
	}
	
	if(tag === 'rect' || tag === 'text') {
		t = t.parentNode;
	}
	
	angle_target = ~~t.id.replace('d', '');
	angle_dir = (angle_target > angle)?1:-1;
	
	updateAngle();
}, false);

addEventListener('mousedown', function(e) {
	var t = e.target.correspondingUseElement || 
					e.target;
		
	if(t.parentNode.id === 'b' || 
		 t.getAttribute('xlink:href') === '#moving') {
		dragging = true;
	}
}, false);
addEventListener('mousemove', function(e) {
	var x, y, a_rad;
	
	if(dragging) {
		if(svg.getAttribute('class') !== 'prevent-sel') {
			svg.setAttribute('class', 'prevent-sel');
		}
		
		x = (e.clientX - svg_rect.left)*sfw + vb[0];
		y = (e.clientY - svg_rect.top)*sfh + vb[1];
		a_rad = atan2(y, x);
		
		if(a_rad < 0) { a_rad += 2*PI; }
		
		angle = ~~(a_rad*cfi);
		
		setAngle(angle);
	}
}, false);
addEventListener('mouseup', function() {
	if(dragging) {
		dragging = false;
		
		if(svg.getAttribute('class') === 'prevent-sel') {
			svg.setAttribute('class', 'prevent-sel');
		}
	}
}, false);

toggle.addEventListener('click', function(e) {
	e.preventDefault();
	form.classList.toggle('hidden');
}, false);

slider.addEventListener('input', sliderChange, false);
slider.addEventListener('change', sliderChange, false);

ui.addEventListener('mouseover', function() {
	ui.classList.add('hidden');
}, false);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console