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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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='-430 -500 1000 1000'>
	<defs>
		<polyline id='join'/>
		<circle id='point' r='4'/>
		<g id='guide'>
			<line/>
			<use xlink:href='#point'/>
		</g>
	</defs>
	
	<g class='arc'>
		<path/>
		<path/>
		<text></text>
	</g>
	
	<g class='join'>
		<use xlink:href='#join'/>
		<use xlink:href='#join' id='cutoff'/>
		<use xlink:href='#join'/>
		<use xlink:href='#point' id='midpoint'/>
	</g>
	
	<g class='guides'>
		<use xlink:href='#guide'/>
		<use xlink:href='#guide'/>
	</g>
	
	<g class='meas'>
		<path/>
		<text></text>
	</g>
</svg>

<form>
	<input type='range' min='8' max='150' value='120' id='angle'/>
	<label for='angle'>angle between segments</label>
	<input type='range' min='2' max='15' value='4' step='.2' id='lim'/>
	<label for='lim'><code><span class='token--prop'>stroke-miterlimit</span>: <span class='token--val'>4</span></code></label>
</form>

<section class='hidden'>
	<p>Given <code><span class='token--prop'>stroke-miterlimit</span>: <span class='token--val'>4</span></code>, the <code>miter</code> has been converted to a <code>bevel</code> from an angle of <code><span class='token--ang'>29°</span></code> down.</p>
</section>
            
          
!
            
              $a: 1;
$b: 1;

$theme-hl: #e18728;

$arc-bg: #d49b00;
$arc-c: #be4c39;
$arc-txt: #9351a6;
$join-c: #e18728;
$guide-c: #aaa;
$meas-c: #be4c39;

* { box-sizing: inherit; }

html {
	overflow: hidden;
	font: 1em/1.375em trebuchet ms, sans serif;
}

body { box-sizing: border-box; margin: 0; }

code {
	display: inline-block;
	font: 700 1em courier; 
	vertical-align: baseline;
}

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

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

polyline { fill: none; }

text { font: 700 2em monospace; }

.arc {
	path {
		&:nth-of-type(1) {
			fill: lighten($arc-bg, 30%);
		}
		&:nth-of-type(2) {
			fill: none;
			stroke: $arc-c;
			stroke-width: 4;
		}
	}
	text { fill: $arc-txt; }
}

.join {
	use {
		&:nth-of-type(-n + 2) {
			stroke-width: 50;
		}
		&:nth-of-type(1) {
			stroke: lighten($join-c, 30%);
			stroke-miterlimit: 15;
		}
		&:nth-of-type(2) {
			stroke: $join-c;
		}
		&:nth-of-type(3) {
			stroke: #191919;
			stroke-width: 2;
			stroke-dasharray: 4;
		}
	}	
}

[id='guide'] circle {
	fill: $guide-c;
	transform: scale(.75);
}

.guides {
	stroke: $guide-c;
	stroke-dasharray: 4;
}

.meas  {
	fill: $meas-c;
	
	path { stroke: $meas-c; }
}


/* ======= styling the form ======= */
$ctrl-bg: #262626;
$ctrl-ll: #aaa;
$ctrl-hl: $theme-hl;

$track-w: 14em;
$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: absolute;
	bottom: .25em; left: .25em;
	margin: .25em;
	padding: .5em;
	background: $ctrl-bg;
	color: $ctrl-ll;
}

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


/* ======= styling the info section ======= */
section {
	position: absolute;
	top: .5em; left: .5em;
	padding: .5em;
	max-width: 19em;
	opacity: .999;
	background: $arc-c;
	color: #fff;
	transition: .35s ease-out;
}

.hidden {
	opacity: .001;
}
            
          
!
            
              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 svg = document.querySelector('svg'), 
		vb = svg.getAttribute('viewBox').split(' ').map(function(p) { return ~~p }), 
		motion_radius = .5*min(vb[2], vb[3]), 
		el_arc_paths = svg.querySelectorAll('.arc path'), 
		el_arc_text = svg.querySelector('.arc text'), 
		arc_radius = 50, 
		el_join = document.getElementById('join'), 
		el_cj = document.getElementById('cutoff'),
		el_defg = svg.querySelector('#guide line'), 
		guide_len = motion_radius*.64, 
		el_guides = svg.querySelectorAll('.guides use'), 
		el_meas_line = svg.querySelector('.meas path'), 
		el_meas_text = svg.querySelector('.meas text'), 
		el_ang = document.getElementById('angle'), 
		ang = 1*el_ang.value, 
		el_lim = document.getElementById('lim'), 
		lim = 1*el_lim.value, 
		el_form_lim = document.querySelector('form .token--val'), 
		inf = document.querySelector('section'), 
		el_code_lim = inf.querySelector('.token--val'), 
		el_code_ang = inf.querySelector('.token--ang'), 
		sw = getComputedStyle(el_cj).strokeWidth.replace('px', '')*1;

var radians = function(deg) {
	return deg*PI/180;
};

var init = function() {
	el_defg.setAttribute('y2', guide_len);
	update();
};

var update = function() {
	var alpha = radians(ang)/2, x_end, y_end, 
			pts = [], 
			miter, ratio, 
			bb_miter, bb_arc, 
			curr_ar, x_a1, y_a1, x_a2, y_a2, 
			att = '', 
			x_m, y_m, base_dev = 4, f1 = 3, f2 = 2, 
			mt = '';
	
	el_cj.style.strokeMiterlimit = lim;
	
	x_end = round(motion_radius*cos(alpha));
	y_end = round(motion_radius*sin(alpha));
		
	pts = [
		x_end + ',' + -y_end, 
		0 + ',' + 0, 
		x_end + ',' + y_end
	];
	
	el_join.setAttribute('points', pts.join(' '));
		
	miter = sw/sin(alpha);
	ratio = miter/sw;
	
	el_guides[0].setAttribute('x', -miter/2);
	el_guides[1].setAttribute('x', miter/2);
	
	el_meas_text.textContent = round(miter);
	bb_miter = el_meas_text.getBBox();
	
	el_meas_text.setAttrs({
		'x': -.5*bb_miter.width, 
		'y': guide_len + bb_miter.height
	});
	
	el_arc_text.textContent = ang + '°';
	bb_arc = el_arc_text.getBBox();
	curr_ar = .5*miter + arc_radius*pow(ratio, .3);
	
	el_arc_text.setAttrs({
		'x': curr_ar + bb_arc.width*pow(el_ang.min/ang, .25), 
		'y': .3*bb_arc.height
	});
	
	x_a1 = x_a2 = curr_ar*cos(alpha);
	y_a1 = curr_ar*sin(-alpha);
	y_a2 = curr_ar*sin(alpha);
	
	att += 'M' + x_a1 + ',' + y_a1 + 
				 'A' + curr_ar + ' ' + curr_ar + 
				 ' 0 0 1 ' + x_a2 + ' ' + y_a2;
	
	el_arc_paths[1].setAttribute('d', att);
	
	att += 'L0,0z'
	
	el_arc_paths[0].setAttribute('d', att);
	
	x_m = round(.5*miter);
	y_m = round(guide_len - f2*base_dev);
	
	mt += 'M' + (f2*base_dev - x_m) + ',' + y_m + 
				'L' + (f1*base_dev - x_m) + ',' + (y_m - f2*base_dev) + 
				'L' + (-x_m) + ',' + y_m + 
				'L' + (f1*base_dev - x_m) + ',' + (y_m + f2*base_dev) + 
				'L' + (f2*base_dev - x_m) + ',' + y_m + 
				'L' + (x_m - f2*base_dev) + ',' + y_m + 
				'L' + (x_m - f1*base_dev) + ',' + (y_m - f2*base_dev) + 
				'L' + x_m + ',' + y_m + 
				'L' + (x_m - f1*base_dev) + ',' + (y_m + f2*base_dev) + 
				'L' + (x_m - f2*base_dev) + ',' + y_m + 
				'z';
	
	el_meas_line.setAttribute('d', mt);
	
	if(ratio > lim && 
		 inf.classList.contains('hidden')) {
		inf.classList.remove('hidden');
	}
	if(ratio < lim && 
		 !inf.classList.contains('hidden')) {
		inf.classList.add('hidden');
	}
};

init();

var angleUpdate = function() {
	ang = 1*el_ang.value;
	update();
};

var limitUpdate = function() {
	var lim_angle;
	
	lim = 1*el_lim.value;
	lim_angle = 2*asin(1/lim);
	
	el_form_lim.textContent = 
	el_code_lim.textContent = lim;
	el_code_ang.textContent = 
		(lim_angle*180/PI).toFixed(2) + '°';
	
	update();
};

el_ang.addEventListener('input', angleUpdate, false);
el_ang.addEventListener('change', angleUpdate, false);

el_lim.addEventListener('input', limitUpdate, false);
el_lim.addEventListener('change', limitUpdate, false);
            
          
!
999px
Loading ..................

Console