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

              
                <svg width='0' height='0'>
	<defs>
		<g id='x-axis'>
			<path d='M-30,0 L108,0 
							 L107,-2 L110,0 L107,2 
							 L108,0z'/>
			<text x='109' y='6.5' class='var'>θ</text>
		</g>
		
		<circle id='point' r='.75'/>
	</defs>
</svg>
<form class='hidden'>
	<button title='toggle controls'>toggle controls</button>
	<input type='range' id='angle' max='90' value='45'/>
	<label for='angle'>θ</label>
</form>
<div id='gc0' class='graph-container'>
	<svg viewbox='-30 -120 140 130'>
		<g class='axes'>
			<use xlink:href='#x-axis'/>
			<g class='y-axis'>
				<path d='M0,150 L0,-118 
								 L-2,-117 L0,-120 L02,-117 
								 L0,-118z'/>
				<text x='-1' y='-113'>sin(<tspan class='var'>θ</tspan>)</text>
			</g>
			<g class='o'>
				<use class='o' xlink:href='#point'/>
				<text x='-1' y='-2' 
							class='var'>O<tspan class='code'>(0,0)</tspan></text>
			</g>
		</g>
		
		<g class='guides'>
			<g class='h'>
				<line x1='0' y1='-50' x2='105' y2='-50'/>
				<use y='-50' xlink:href='#point'/>
				<text x='-2' y='-50'>.5</text>
				<line x1='0' y1='-100' x2='105' y2='-100'/>
				<use y='-100' xlink:href='#point'/>
				<text x='-2' y='-100'>1</text>
			</g>
			<g class='v'>
				<line x1='30' y1='0' x2='30' y2='-115'/>
				<use x='30' xlink:href='#point'/>
				<text x='30' y='5'>30°</text>
				<line x1='45' y1='0' x2='45' y2='-115'/>
				<use x='45' xlink:href='#point'/>
				<text x='45' y='5'>45°</text>
				<line x1='60' y1='0' x2='60' y2='-115'/>
				<use x='60' xlink:href='#point'/>
				<text x='60' y='5'>60°</text>
				<line x1='90' y1='0' x2='90' y2='-115'/>
				<use x='90' xlink:href='#point'/>
				<text x='90' y='5'>90°</text>
			</g>
		</g>
		
		<polyline class='graph'/>
		
		<g class='current' transform='translate(45)'>
			<line class='guide'/>
			<use class='proj' xlink:href='#point'/>
			<g class='pt'>
				<use xlink:href='#point'/>
				<text y='-2'>sin(45°) = .71</text>
			</g>
		</g>
	</svg>
</div>
<div id='gc1' class='graph-container'>
	<svg viewbox='-30 -120 140 130'>
		<g class='axes'>
			<use xlink:href='#x-axis'/>
			<g class='y-axis'>
				<path d='M0,150 L0,-118 
								 L-2,-117 L0,-120 L02,-117 
								 L0,-118z'/>
				<text x='-1' y='-113'>1/sin(<tspan class='var'>θ</tspan>)</text>
			</g>
			<g class='o'>
				<use class='o' xlink:href='#point'/>
				<text x='-1' y='-2' 
							class='var'>O<tspan class='code'>(0,0)</tspan></text>
			</g>
		</g>
		
		<g class='guides'>
			<g class='h'>
				<line x1='0' y1='-50' x2='105' y2='-50'/>
				<use y='-50' xlink:href='#point'/>
				<text x='-2' y='-50'>25</text>
				<line x1='0' y1='-100' x2='105' y2='-100'/>
				<use y='-100' xlink:href='#point'/>
				<text x='-2' y='-100'>50</text>
			</g>
			<g class='v'>
				<line x1='30' y1='0' x2='30' y2='-115'/>
				<use x='30' xlink:href='#point'/>
				<text x='30' y='5'>30°</text>
				<line x1='45' y1='0' x2='45' y2='-115'/>
				<use x='45' xlink:href='#point'/>
				<text x='45' y='5'>45°</text>
				<line x1='60' y1='0' x2='60' y2='-115'/>
				<use x='60' xlink:href='#point'/>
				<text x='60' y='5'>60°</text>
				<line x1='90' y1='0' x2='90' y2='-115'/>
				<use x='90' xlink:href='#point'/>
				<text x='90' y='5'>90°</text>
			</g>
		</g>
		
		<polyline class='graph'/>
		
		<g class='current' transform='translate(45)'>
			<line class='guide'/>
			<use class='proj' xlink:href='#point'/>
			<g class='pt'>
				<use xlink:href='#point'/>
				<text y='-2' class='to-right'>1/sin(45°) = 1.41</text>
			</g>
		</g>
	</svg>
</div>

<div class='usage-inf'>drag red point</div>
              
            
!

CSS

              
                @import 'compass/css3';

$theme-hl: #e18728;

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

body { text-align: center; }

.graph-container {
	display: inline-block;
	width: 92.4vh; height: 85.8vh;
	max-width: 42em; max-height: 39em;
	
	@media (max-width: 45em) {
		min-width: 19em;
		width: 92.4vw; height: 85.8vw;
	}
}

text {
	text-anchor: end;
	font: .375em courier, monospace;
	
	.no-select & { user-select: none; }
	
	@media (min-width: 840px) {
		font-size: .3125em;
	}
}

.var { font-style: italic; }
.code { font-style: normal; }
.to-right { text-anchor: start; }
.to-mid { text-anchor: middle; }

[id='x-axis'], .axes {
	fill: $coord-syst-c;
	
	path {
		fill: $coord-syst-c;
		stroke: $coord-syst-c;
		stroke-width: 1;
		vector-effect: non-scaling-stroke;
	}
}

.guides {	
	line {
		stroke: $guide-c;
		stroke-dasharray: 3;
		stroke-width: 1;
		vector-effect: non-scaling-stroke;
	}
	use, text { fill: $coord-syst-c; }
	
	.v text { text-anchor: middle; }
}

.graph {
	fill: none;
	stroke: $graph-c;
}

.current {
	.proj {
		fill: $cfg-c;
	}
	
	.guide {
		stroke: $cfg-c;
		stroke-dasharray: 6;
		stroke-width: 1;
		vector-effect: non-scaling-stroke;
	}
	
	.pt {
		fill: $curr-c;
		
		use {
			stroke: $curr-c;
			stroke-width: 2;
			vector-effect: non-scaling-stroke;
			cursor: pointer;
			
			@media (max-width: 640px) {
				stroke-width: 5;
			}
		}
		
		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;
	bottom: 0; left: 50%;
	padding: .5em;
	transform: translate(-50%);
	background: $ctrl-bg;
	color: $ctrl-ll;
	font: 1em/1.375em trebuchet ms, sans serif;
	transition: .35s;
}

form.hidden {
	transform: translate(-50%, 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; }
	
	+ label {
		display: block;
		text-align: center;
	}
		
	&: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; }
}
              
            
!

JS

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

var PRECISION_UNIT = .25, 
		MULTIPLIER = [100, 2], 
		
		gc0 = document.getElementById('gc0'), 
		gc1 = document.getElementById('gc1'), 
		svg0 = gc0.querySelector('svg'), 
		svg1 = gc1.querySelector('svg'), 
		vb0 = svg0.getAttribute('viewBox').split(' ')
					.map(function(d) {
						return ~~d;
					}), 
		vb1 = svg1.getAttribute('viewBox').split(' ')
					.map(function(d) {
						return ~~d;
					}), 
		r0, r1, f0, f1, 
		curr0 = svg0.querySelector('.current'), 
		curr1 = svg1.querySelector('.current'), 
		guide0 = curr0.querySelector('.guide'), 
		guide1 = curr1.querySelector('.guide'), 
		pt0 = curr0.querySelector('.pt'), 
		pt1 = curr1.querySelector('.pt'), 
		lbl0 = pt0.querySelector('text'), 
		lbl1 = pt1.querySelector('text'), 
		dt0 = pt0.querySelector('use'), 
		dt1 = pt1.querySelector('use'), 
		a = document.getElementById('angle'), 
		lbl = document.querySelector('[for=angle]'),
		dragged = null, 
		form = document.querySelector('form'), 
		toggle = form.querySelector('button'), 
		ui = document.querySelector('.usage-inf');

var drawGraphs = function() {
	var g0 = gc0.querySelector('.graph'), 
			g1 = gc1.querySelector('.graph'), 
			pa0 = [], pa1 = [], 
			x, fval,  
			n = 90/PRECISION_UNIT, 
			unit_angle = .5*PI/n, curr_angle;
	
	for(var i = 0; i <= n; i++) {
		x = (i*PRECISION_UNIT).toFixed(2);
		curr_angle = i*unit_angle;
		fval = -sin(curr_angle);
		
		pa0.push(x + ',' + (MULTIPLIER[0]*fval).toFixed(3));
		
		if(x >= 1) {
			fval = 1/fval;
		
			pa1.push(x + ',' + (MULTIPLIER[1]*fval).toFixed(3));
		}
	}
		
	g0.setAttribute('points', pa0.join(' '));
	g1.setAttribute('points', pa1.join(' '));
};

var getCurrentValue = function(angle, p) {
	return MULTIPLIER[.5*(1 - p)] * 
				 pow(-sin(angle), p);
};

var sizeRefresh = function() {
	r0 = svg0.getBoundingClientRect();
	r1 = svg1.getBoundingClientRect();
	
	f0 = vb0[2]/r0.width;
	f1 = vb1[2]/r1.width;
};

var init = function() {
	drawGraphs();
	handleAngleChange();
	sizeRefresh();
};

var handleAngleChange = function() {
	var a_deg = a.value*1, 
			a_rad = a_deg*PI/180, 
			ttxt = 'translate(' + a_deg + ')', 
			base_txt = 'sin(' + a_deg + '°) = ', 
			rv = sin(a_rad), 
			fv0 = getCurrentValue(a_rad, 1), 
			fv1 = getCurrentValue(a_rad, -1);
	
	lbl.innerHTML = '<span class=var>θ</span> is ' 
		+ a_deg + '°';
	
	curr0.setAttribute('transform', ttxt);	
	guide0.setAttribute('y2', fv0.toFixed(3));
	pt0.setAttribute(
		'transform', 
		'translate(0 ' + fv0.toFixed(3) + ')'
	);
	lbl0.textContent = 
		(base_txt +	(round(rv*100))/100)
		.replace(' 0.', ' .');
	
	if(a_deg <= 45 && 
		 !lbl0.classList.contains('to-right')) {
		lbl0.classList.add('to-right');
		lbl0.setAttribute('x', 3.5);
	}
	if(a_deg > 45 && 
		 lbl0.classList.contains('to-right')) {
		lbl0.classList.remove('to-right');
		lbl0.setAttribute('x', 0);
	}
	
	if(a_deg >= 1) {
		if(curr1.style.display === 'none') {
			curr1.style.display = 'block';
		}
		
		curr1.setAttribute('transform', ttxt);
		guide1.setAttribute('y2', fv1);
		pt1.setAttribute(
			'transform', 
			'translate(0 ' + fv1 + ')'
		);
		lbl1.textContent = 
		('1/' + base_txt + (round(1/rv*100))/100);
		
		if(a_deg <= 45 && 
			 !lbl1.classList.contains('to-right')) {
			lbl1.classList.add('to-right');
			lbl1.classList.remove('to-mid');
			lbl1.setAttribute('x', 3);
			lbl1.setAttribute('y', -1);			
		}
		if(a_deg > 45) {
			if(lbl1.classList.contains('to-right'))
				lbl1.classList.remove('to-right');
			lbl1.classList.add('to-mid');
			lbl1.setAttribute('x', 0);
			lbl1.setAttribute('y', -5);
		}
		if(a_deg > 75 && 
			 lbl1.classList.contains('to-mid')) {
			lbl1.classList.remove('to-mid');
			lbl1.setAttribute('x', 15);
			lbl1.setAttribute('y', -3);
		}
	}
	else {
		curr1.style.display = 'none';
	}
};

var dragstart = function(e) {
	var t = e.target;
			
	if(t === dt0 || t === dt1) {
		dragged = t;
		document.body.classList.add('no-select');
	}
};

var drag = function(e) {
	var raw_x, rel_x, scaled_x, is0;
		
	if(dragged) {
		is0 = dragged === dt0;
				
		raw_x = e.clientX;
		rel_x = raw_x - (is0?r0:r1).left;
		scaled_x = rel_x*(is0?f0:f1) + ((is0)?vb0:vb1)[0];
		a.value = max(0, min(90, round(scaled_x)));
		handleAngleChange();
	}
};

var dragend = function() {
	if(dragged) {
		dragged = null;
		document.body.classList.remove('no-select');
	}
};

init();

addEventListener('resize', sizeRefresh, false);

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

addEventListener('mousedown', dragstart, false);
addEventListener('mousemove', drag, false);
addEventListener('mouseup', dragend, false);

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

ui.addEventListener('mouseover', function() {
	ui.classList.add('hidden');
}, false);
              
            
!
999px

Console