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.

            
              - var nmax = 3, nmin = 0, nval = 2;
- var m = nmax + .5;
- var vb_u = 1500;
- var vb_h = 2*vb_u, vb_w = 2*vb_h;
- var vb_x = -.5*(vb_w - vb_u);
- var vb_y = -.5*(vb_h + vb_u);
- var ax0 = .25*vb_u, ax1 = vb_u + ax0;
- var k = .05, pr = Math.round(.1*k*vb_w);
- var ps = 2*pr, na = Math.round(.25*pr);
- var pr1 = Math.round(.65*pr), fs = .025*vb_w;
- var sw = .002*vb_w;
- var p = 180, np = p*m;
- var vg = [];

svg(viewBox=[vb_x, vb_y, vb_w, vb_h].join(' '))
	style
		| svg {
		| 	font: #{fs}px consolas, monaco, monospace;
		| 	letter-spacing: #{-.1*fs}px
		| }
		| [d], [r], #r { stroke-width: #{sw} }
		| #f { stroke-width: #{2*sw} }
	marker#e(markerWidth=na markerHeight=na 
						viewBox='0 -4 8 8' 
						orient='auto')
		path(d='M8 0 0-4V4')
	
	pattern#p(width=ps height=ps patternUnits='userSpaceOnUse' patternTransform='rotate(60)')
		rect(width=ps height=Math.round(na))
	
	clipPath#o
		rect#r(y=-vb_u width=vb_u height=vb_u)
	
	g#c
		path(d=`M${-ax0} 0H${ax1}`)
		path(d=`M0 ${ax0}V${-ax1}`)
		text(x=ax1 y=fs): tspan k
		text(x=.25*fs y=-ax1) 1-|cos(<tspan>k</tspan>·(n + ½)·180°)|
		
	use(xlink:href='#r')
	
	- for(var i = 0; i <= np; i++) {
		- var x = Math.round(i*2*vb_u/p);
		- var y = Math.abs(Math.round(vb_u*Math.cos(i*Math.PI/p))) - vb_u;
		- vg.push([x, y])
	- }
	path#f(d=`M${vg.join(' ')}`)

	circle(r=pr)
	circle(r=pr1 cx=vb_u)
	circle(r=pr1 cy=-vb_u)
	circle(r=pr cx=vb_u cy=-vb_u)
	
	text(x=-.75*fs y=.9*fs) 0
	text(x=-.75*fs y=.35*fs - vb_u) 1
	text(x=vb_u - .25*fs y=.9*fs) 1

form
	section
		input#n(type='range' min=nmin max=nmax value=nval)
		label(for='n') n:
			output(for='n') #{nval}
            
          
!
            
              $theme-dark: #262626;
$theme-light: invert($theme-dark);
$theme-orange: #f90;
$theme-tomato: #b53;

$track-w: 12.5em;
$track-h: .25em;
$thumb-d: 1.5em;

@mixin track() {
	box-sizing: border-box;
	border: none;
	width: $track-w; height: $track-h;
	border-radius: $track-h;
	background: $theme-light;
}

@mixin thumb() {
	box-sizing: border-box;
	border: solid .125*$thumb-d $theme-dark;
	width: $thumb-d; height: $thumb-d;
	border-radius: 50%;
	background: currentcolor;
}

* { color: inherit; font: inherit }

body {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: space-between;
	margin: 0;
	height: 100vh;
	font: 1.25em/ 2 consolas, monaco, monospace
}

svg {
	flex: 1;
	width: 100%;
}

tspan { font-style: italic }

.sup { font-size: .75em }

[id='e'] {
	stroke: transparent;
	fill: $theme-dark
}

[id='p'] { fill: $theme-orange }

[id='l'] { stroke: $theme-light }

[id='c'] [d] {
	stroke: $theme-dark;
	marker-end: url(#e)
}

[id='r'] {
	stroke: $theme-orange;
	stroke-dasharray: 1%;
	fill: url(#p)
}

[id='f'] {
	stroke: $theme-tomato;
	fill: none;
	clip-path: url(#o)
}

[r] {
	stroke: $theme-dark;
	fill: $theme-orange
}

form {
	display: flex;
	align-items: center;
	justify-content: space-around;
	padding: .75em 0 0;
	width: 100%;
	background: $theme-dark;
	color: $theme-light;
}

input, label {
	display: block;
	margin: .25em auto;
	text-align: center;
}

input {
	&, &::-webkit-slider-thumb {
		-webkit-appearance: none;
	}
	
	margin: 0;
	padding: 0;
	width: $track-w; height: $thumb-d;
	background: transparent;
	transition: color .3s;
	cursor: pointer;
	
	&::-webkit-slider-runnable-track {
		@include track
	}
	&::-moz-range-track { @include track }
	&::-ms-track { @include track }
	
	&::-webkit-slider-thumb {
		margin-top: .5*($track-h - $thumb-d);
		@include thumb
	}
	&::-moz-range-thumb { @include thumb }
	&::-ms-thumb {
		margin-top: 0;
		@include thumb
	}
	
	&::-ms-tooltip { display: none }
	
	&:focus {
		outline: solid 1px transparent;
		color: $theme-orange;
		
		+ label output { color: $theme-orange }
	}
}
            
          
!
            
              const _N = document.getElementById('n'), 
			_O = _N.nextElementSibling.querySelector('output'), 
			_F = document.getElementById('f');

let n, 
		pts = _F.getAttribute('d').replace(/(M|L)\s?/g, '')
						.split(/\s|\,/).map(c => +c);

function update() {
	if(n !== +_N.value) {
		_O.value = n = +_N.value;
		
		let num = 2*n + 1;
				
		_F.setAttribute('d', `M${pts.map(c => c.map((k, i) => i ? k : Math.round(k/num))).join(' ')}`)
	}
};

pts = pts.reduce((a, c, i) => i%2 ? a.concat([[pts[i - 1], c]]) : a, []);
update();

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

Console