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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              - var pmin = 1, pmax = pmin + 1, pval = pmax;
- var vb_d = 250, k = .05;
- var pr = Math.round(.2*k*vb_d), na = Math.round(2*pr);
- var fs = Math.round(3*na);
- var vb_x = -2*k*vb_d, vb_y = (2*k - 1)*vb_d;
- var ax0 = ~~(k*vb_d), ax1 = ~~((3*k - 1)*vb_d);
- var gmx = (1 - 4*k)*vb_d, kg = 5, gu = gmx/kg;
- var pr1 = +(5*pr/7).toFixed(2);

form#ctrls
	label(for='p') exponent 
		code: em p
	span.swrap(style=`--min:${pmin};--max:${pmax};--val:${pval}`)
		input#p(type='range' min=pmin max=pmax 
						value=pval step=.025*(pmax - pmin))
		output(for='p') #{pval}

section#result
	svg#graph(viewBox=[vb_x, vb_y, vb_d, vb_d].join(' '))
		style
			| * { --fs: #{fs}px }
		marker#e(markerWidth=na markerHeight=na 
						viewBox='0 -4 8 8' 
						orient='auto' refX='3')
			path(d='M8 0 0-4V4')
		- var gd = [];
		- for(var i = 0; i < kg; i++) {
			- var gc = (i + 1)*gu;
			- gd.push(`M${gc}${-gmx}V0M0${-gc}H${gmx}`)
		- }
		path(d=gd.join(''))
		text(x=-ax1 y=-Math.round(.3*fs)) k
		text(x=(gmx - .2*fs) y=.9*fs) 1
		path(d=`M0 ${ax0}V${ax1}`)
		text(x=Math.round(.3*fs) y=(ax1 + .3*fs)) <tspan id='fl'>f</tspan>,<tspan id='gl'>g</tspan>
		text(x=-.75*fs y=-(gmx - .3*fs)) 1
		path(d=`M${-ax0} 0H${-ax1}`)
		line#id(x2=gmx y2=-gmx)
		circle(r=pr1 cy=-gmx)
		circle(r=pr1 cx=gmx)
		path.fn#f
		path.fn#g
		path.fn.cmp#o(d=`M0 0C0 0 ${.58*gmx}${-gmx} ${gmx}${-gmx}`)
		path.fn.cmp#i(d=`M0 0C${.42*gmx} 0 ${gmx}${-gmx} ${gmx}${-gmx}`)
		circle(r=pr)
		text(x=-.8*fs y=.9*fs) 0
		circle#u(r=pr cx=gmx cy=-gmx)
		text(x=gmx+pr y=-(gmx+pr)) 1,1
	ul#legend
		li: code#fe <em>f</em>(<em>k</em>) = <em>k<sup>p</sup></em>
		li: code#ge <em>g</em>(<em>k</em>) = 1 - (1 - <em>k</em>)<em><sup>p</sup></em>
            
          
!

CSS

            
              $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));

$graph-c0: #b53;
$graph-c1: #95a;

$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; padding: 0; font: inherit }

body {
	display: flex;
	flex-direction: column;
	overflow-x: hidden;
	min-height: 10em; height: 100vh;
	font: 1.25em/ #{$demo-lh} 
		trebuchet ms, tahoma, sans-serif;
}

code { font: 1.25em consolas, monaco, monospace }

sup { font-size: .75em }


/* ========================= */

/* 1. CONTROLS: slider, label & tooltip */
[id='ctrls'] {
	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: 400px) {
		flex-direction: column;
		
		.swrap { width: calc(100% - #{2*$ctrl-pad}) }
	}
}

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


/* ========================= */

/* 2. RESULT: graph & legend */
[id='result'] {
	display: flex;
	align-items: center;
	flex-direction: column;
	justify-content: center;
	flex: 1;
	
	@media (max-aspect-ratio: 5/6) {
		ul { flex-direction: column }
		ul li:first-child:after { content: '' }
	}
	
	@media (min-aspect-ratio: 7/4),
				 (min-width: $ctrl-wmax + 20em) {
		flex-direction: row;
		
		ul { flex-direction: column }
		ul li:first-child:after { content: '' }
	}
}

[id^='g'] { color: $graph-c0 }

[id^='f'] { color: $graph-c1 }


/* 2.a Graph */
[id='graph'] {
	flex: 1;
	overflow: visible;
	min-height: 10em;
	max-width: $ctrl-wmax; max-height: 100%;
	
	@media (min-height: 400px) {
		max-height: calc(100vh - #{2*$ctrl-pad + 2*$thumb-r + 2em});
	}
}

[d], [r], line {
  fill: none;
	stroke: $demo-light;
  vector-effect: non-scaling-stroke;
	
	@supports not (vector-effect: non-scaling-stroke) {
		stroke-width: .75px !important
	}
}

[x] {
	font: var(--fs) consolas, monaco, monospace;
	letter-spacing: calc(-1*var(--fs)/5)
}

[y] + [d], [r] {
	stroke: $demo-dark;
	stroke-width: 2px;
	marker-end: url(#e)
}

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

[r] { fill: $demo-hl }

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

tspan { fill: currentcolor }

[id='id'] { stroke-width: 3px }

.fn {
	stroke: currentcolor;
	stroke-width: 4px;
}

.cmp {
	color: $demo-hl;
	stroke-width: 3px;
	stroke-opacity: .65;
	stroke-dasharray: 9px;
}


/* 2.b Legend */
[id='legend'] {
	display: flex;
	padding: .5em 1em;
	
	li {
		list-style: none;
		padding: .5em;
		white-space: nowrap;
		
		&:first-child:after {
			display: inline-block;
			margin-left: 1em;
			content: '•'
		}
	}
}
            
          
!

JS

            
              const _P = document.getElementById('p'), 
			_S = _P.parentNode, 
			_O = _S.querySelector('output'), 
			_U = document.getElementById('u'), 
			_F = document.getElementById('f'), 
			_G = document.getElementById('g'), 
			_SVG = document.getElementById('graph'), 
			_Z = document.getElementById('o'), 
			MIN = +_P.min, RANGE = _P.max - _P.min, 
			PREC = 1000, 
			MAXX = +_U.getAttribute('cx'), 
			MAXY = +_U.getAttribute('cy'), 
			U = 1/PREC;

let p = +_P.value;

function updateVal() {
	_S.style.setProperty('--val', p);
	_O.textContent = p
};

function graph() {
	let i = p - _P.min, data = { f: [], g: [] };
	
	for(var j = 0; j <= PREC; j++) {
		let c = j*U, x = +(c*MAXX).toFixed(2), 
				cp = i + MIN, 
				fy = Math.pow(c, cp)*MAXY, 
				gy = (1 - Math.pow(1 - c, cp))*MAXY;

		data.f.push([x, +fy.toFixed(2)]);
		data.g.push([x, +gy.toFixed(2)]);
	}
	
	_F.setAttribute('d', `M${data.f.join('L')}`);
	_G.setAttribute('d', `M${data.g.join('L')}`);
	
	_SVG.insertBefore(_G, _Z);
	_SVG.insertBefore(_F, _G);
};

function update() {
	let newp = +_P.value;
	
	if(newp !== p) {
		_SVG.removeChild(_F);
		_SVG.removeChild(_G);
		p = newp;
		updateVal();
		graph()
	}
};

(function init() {
	graph();
	_P.addEventListener('input', update, false);
	_P.addEventListener('change', update, false);
})();
            
          
!
999px

Console