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

              
                <svg viewBox='-40 -460 800 500'>
	<defs>
		<line id='guide-v' y1='-410' y2='10'/>
		<line id='guide-h' x1='0' x2='730'/>
		<circle id='point' r='3'/>
		<use id='extreme' xlink:href='#point' transform='scale(2.5)'/>
	</defs>
	
	<g id='coord-syst'>
		<path id='axis-x' class='axis'
					d='M-45,0 L747,0 L743,-8 L755,0 L743,8 L747,0'/>
		<text x='834' y='10' class='var'
					text-anchor='middle' dominant-baseline='hanging'>θ</text>
		<path id='axis-y' class='axis'
					d='M0,430 L0,-442 L-8,-438 L0,-450 L8,-438 L0,-442'/>
		<text x='10' y='-444' class='code'
					text-anchor='start' dominant-baseline='middle'>
			1 + cos(<tspan class='var'>θ</tspan>)
		</text>
		<use xlink:href='#point'/>
		<text text-anchor='end' x='-8' y='-8'>0</text>
		<text dominant-baseline='hanging' x='8' y='8'>0°</text>
	</g>
	
	<g id='guides'>
		<use xlink:href='#guide-h' y='-400'/>
		<use xlink:href='#point' y='-400'/>
		<text x='-8' y='-400' 
					text-anchor='end' dominant-baseline='middle'>2</text>
		<use xlink:href='#guide-h' y='-300'/>
		<use xlink:href='#point' y='-300'/>
		<text x='-8' y='-300' 
					text-anchor='end' dominant-baseline='middle'>1.5</text>
		<use xlink:href='#guide-h' y='-200'/>
		<use xlink:href='#point' y='-200'/>
		<text x='-8' y='-200' 
					text-anchor='end' dominant-baseline='middle'>1</text>
		<use xlink:href='#guide-h' y='-100'/>
		<use xlink:href='#point' y='-100'/>
		<text x='-8' y='-100' 
					text-anchor='end' dominant-baseline='middle'>.5</text>
		
		<use xlink:href='#guide-v' x='180'/>
		<use xlink:href='#point' x='180'/>
		<text x='177' y='20' 
					text-anchor='end' dominant-baseline='hanging'>90°</text>
		<use xlink:href='#guide-v' x='360'/>
		<use xlink:href='#point' x='360'/>
		<text x='360' y='-15' 
					text-anchor='middle'>180°</text>
		<use xlink:href='#guide-v' x='540'/>
		<use xlink:href='#point' x='540'/>
		<text x='543' y='20' 
					text-anchor='start' dominant-baseline='hanging'>270°</text>
		<use xlink:href='#guide-v' x='720'/>
		<use xlink:href='#point' x='720'/>
		<text x='720' y='8' 
					text-anchor='end' dominant-baseline='hanging'>360°</text>
	</g>
	
	<polyline id='graph'/>
	
	<g id='extremes'>
		<use xlink:href='#extreme' x='0' y='-400' class='current'/>
		<use xlink:href='#extreme' x='360' y='0'/>
		<use xlink:href='#extreme' x='720' y='-400'/>
	</g>
	
	<g id='current' transform='translate(0 -400)'>
		<use xlink:href='#point' />
		<text y='-8' x='8' class='code'>1 + cos(0°) = 2</text>
	</g>
</svg>

<form class='hidden'>
	<button title='toggle controls'>toggle controls</button>
	<input type='range' id='angle' max='720' value='0' step='2'/>
	<label for='angle'>0°</label>
</form>
              
            
!

CSS

              
                @import 'compass/css3';

$a: 8;
$b: 5;

$theme-hl: #e18728;

$coord-syst-c: #444;
$guide-c: #ccc;
$graph-c: $theme-hl;
$cfg-c: #222;
$curr-c: #be4c39;
$extreme-c: #be4c39;
$extreme-bg: #d49b00;

html { overflow: hidden; }

body { margin: 0; }

svg {
	position: absolute;
  left: calc(50vw - #{$a/$b/2*100vh});
  height: 100vh; width: $a/$b*100vh;
  
  @media (max-aspect-ratio: #{$a}/#{$b}) {
    top: calc(50vh - #{$b/$a/2*100vw}); left: auto;
    width: 100vw; height: $b/$a*100vw;
	}
}

.drag text { user-select: none; }

path, line, polyline {
	vector-effect: non-scaling-stroke;
}

text {
	font: 1.125em courier, monospace;
}

.var { font-style: italic; }
.attach-right { text-anchor: end; }
.attach-top { dominant-baseline: hanging; }
.attach-mid { text-anchor: middle; }

.axis {
	fill: $coord-syst-c;
	stroke: $coord-syst-c;
}

[id='guides'] {
	use {
		stroke: $guide-c;
		stroke-dasharray: 8;
	}
}

[id='graph'] {
	fill: none;
	stroke: $graph-c;
	stroke-width: 3;
}

[id='extreme'] {
	fill: lighten($extreme-bg, 30);
	stroke: $extreme-c;
}

[id='extremes'] {
	cursor: pointer;
	
	.current {
		opacity: .2;
		animation: pulse .5s ease-in-out infinite alternate;
	}
}

@keyframes pulse {
	80%, 100% { opacity: .99; }
}

[id='current'] {
	fill: $curr-c;
	
	use {
		stroke: $curr-c;
		stroke-width: 3;
		cursor: pointer;
	}
	
	text {
		font-weight: 700;
	}
}



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

$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;
	top: 0; right: .5em;
	padding: .5em;
	background: $ctrl-bg;
	color: $ctrl-ll;
	font: 1em/1.375em trebuchet ms, sans serif;
	transition: .35s;
}

form.hidden {
	transform: translate(0, -100%);
}

button {
	position: absolute;
	right: 0; top: 100%; left: 0;
	border: none;
	width: 100%;
	border-radius: 0 0 .5em .5em;
	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: 0 .5*$tl $th .5*$tl;
		border-bottom-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; }
	
	+ label {
		display: block;
		text-align: center;
	}
		
	&:focus { outline: none; }
}
              
            
!

JS

              
                /* because IE up to and including 11 */
Math.sign = Math.sign || function(x) {
  x = +x; // convert to a number
  if(x === 0 || isNaN(x)) {
    return x;
  }
  return x > 0 ? 1 : -1;
};

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

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

var UNIT = [PI/360, -200], 
		OFFSET = 8, 
		TO_DEG = 180/PI, 
		
		svg = document.querySelector('svg'), 
		vb = svg.getAttribute('viewBox').split(' ').map(function(p) {
			return ~~p;
		}), 
		r, ratio_w, ratio_h, 
		g_el = document.getElementById('graph'), 
		drag = false, 
		curr = document.getElementById('current'), 
		txt = curr.querySelector('text'), 
		extremes = document.querySelectorAll('#extremes use'), 
		form = document.querySelector('form'), 
		toggle = form.querySelector('button'), 
		a = document.getElementById('angle'), 
		lbl = form.querySelector('label'), 
		target_x = null, sgn = 0, r_id = null;

var size = function() {
	r = svg.getBoundingClientRect();
	ratio_w = vb[2]/r.width;
	ratio_h = vb[3]/r.height;
};

var drawGraph = function() {
	var pts_txt = [], rad, f, x, y;
	
	for(x = 0; x < 720; x++) {
		rad = x*UNIT[0];
		f = cos(rad);
		y = UNIT[1]*(1 + f);
		
		pts_txt.push(x + ',' + y);
	}
	
	g_el.setAttribute('points', pts_txt.join(' '));
};

var setCurrent = function(x) {
	var x = x || 0, rad, deg, f, y;
	
	rad = x*UNIT[0];
	f = 1 + cos(rad);
	y = ~~(UNIT[1]*f);
	deg = ~~(rad*TO_DEG);

	curr.setAttrs({
		'transform': 'translate(' + x + ' ' + y + ')'
	});

	txt.textContent = 
		'1 + cos(' + deg + '°) = ' + f.toFixed(2)
		.replace('.00', '')
		.replace('0.', '.')
		.replace('-0', '0');

	if(f <= .5 && 
		 txt.getAttribute('class').indexOf('attach-top') < 0) {
		txt.setAttrs({
			'class': txt.getAttribute('class').trim() + ' attach-top', 
			'y': 8
		});
	}
	if(f > .5 && 
		 txt.getAttribute('class').indexOf('attach-top') > -1) {
		txt.setAttrs({
			'class': txt.getAttribute('class').replace('attach-top', '').trim(), 
			'y': -8
		});
	}

	if(((f <= .5 && deg < 180) || (f > .5 && deg > 180)) && 
		 txt.getAttribute('class').indexOf('attach-right') < 0) {
		txt.setAttrs({
			'class': txt.getAttribute('class').trim() + ' attach-right', 
			'x': -8
		});
	}
	if(((f > .5 && deg < 180) || (f <= .5 && deg > 180)) && 
		 txt.getAttribute('class').indexOf('attach-right') > -1) {
		txt.setAttrs({
			'class': txt.getAttribute('class').replace('attach-right', '').trim(), 
			'x': 8
		});
	}

	if(deg === 180 && 
		 txt.getAttribute('class').indexOf('attach-mid') < 0) {
		txt.setAttribute(
			'class', 
			txt.getAttribute('class').trim() + ' attach-mid'
		);
	}
	if(deg !== 180 && 
		 txt.getAttribute('class').indexOf('attach-mid') > -1) {
		txt.setAttribute(
			'class', 
			txt.getAttribute('class').replace('attach-mid', '').trim()
		);
	}

	for(var i = 0; i < 3; i++) {
		if(~~extremes[i].getAttribute('x') === x && 
			 extremes[i].getAttribute('class') !== 'current') {
			extremes[i].setAttribute('class', 'current');
		}
		if(~~extremes[i].getAttribute('x') !== x && 
			 extremes[i].getAttribute('class') === 'current') {
			extremes[i].setAttribute('class', '');
		}
	}
	
	lbl.textContent = deg + '°';
};

var handleAngleChange = function() {
	setCurrent(~~a.value);
};

var move = function() {
	var x;
	
	if(target_x !== null && sgn) {
		x = (~~a.value) + a.step*sgn;
		setCurrent(x);
		a.value = x;

		if(abs(x - target_x) < (~~a.step)) {
			a.value = target_x;
			setCurrent(target_x);
			cancelAnimationFrame(r_id);
			r_id = null;
			target_x = null;
			sgn = 0;
			return;
		}
		
		r_id = requestAnimationFrame(move);
	}
};


size();
drawGraph();


addEventListener('resize', size, false);

addEventListener('mousedown', function(e) {
	var tg = e.target.correspondingUseElement || e.target;
	
	if(tg.parentNode === curr) {
		drag = true;
		document.body.classList.add('drag');
	}
}, false);

addEventListener('mousemove', function(e) {
	var x, y, rad, deg, f;
	
	if(drag) {
		x = ~~((e.clientX - r.left)*ratio_w + vb[0]);
		x = min(max(x, 0), 720);
		setCurrent(x);
		a.value = x;
	}
}, false);

addEventListener('mouseup', function(e) {
	if(drag) {
		drag = false;
		document.body.classList.remove('drag');
	}
}, false);

addEventListener('dblclick', function(e) {
	var tg = e.target.correspondingUseElement || e.target;
	
	if(tg.parentNode.id === 'extremes') {
		target_x = ~~tg.getAttribute('x') || 0;
		sgn = sign(target_x - (~~a.value));
		
		if(r_id) {
			cancelAnimationFrame(r_id);
			r_id = null;
		}
		
		move();
	}
}, false);

a.addEventListener('input', handleAngleChange, false);
a.addEventListener('change', handleAngleChange, false);

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

Console