Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


                <div class="controls">
	<div class="controls__group">
		<label for="points">Points: <span data-label="points"></span></label>
		<input id="points" type="range" min="8" max="60" step="2" data-slider="points">
	<div class="controls__group">
		<label for="rad">Inner radius: <span data-label="inner-radius"></span></label>
		<input id="rad" type="range" min="20" max="120" step="5" data-slider="inner-radius">

<div class="shape">


                @use "sass:math";

@import url(",700");

body {
	font-family: "Open Sans", sans-serif;
	margin: 0;
	padding: 1rem;
	min-height: 100vh;
	display: grid;
	gap: 1rem;
	place-content: center;

.shape {
	width: min(20rem, 90vmin);
	height: min(20rem, 90vmin);
	position: relative;
	background: whitesmoke;
	border: 1px solid lightgrey;
	&::after {
		content: '';
		position: absolute;
		inset: 0;
		background: linear-gradient(45deg, deeppink, orange);
		-webkit-clip-path: var(--clip);
		clip-path: var(--clip);
		transition: clip-path 200ms;

/* Controls */
.controls__group {
	> * {
		display: block;
		width: 100%;


Math.sin(θ) = opposite / hypotenuse
Math.cos(θ) = adjacent / hypotenuse
Math.tan(θ) = opposite / adjacent

const shape = document.querySelector('.shape')
const pointsInput = document.querySelector('[data-slider="points"]')
const pointsLabel = document.querySelector('[data-label="points"]')
const radInput = document.querySelector('[data-slider="inner-radius"]')
const radLabel = document.querySelector('[data-label="inner-radius"]')
const inputs = [radInput, pointsInput]

const size = 120

const createPolygon = () => {
	const radius = radInput.value
	const numberOfPoints = pointsInput.value
	const angleStep = (Math.PI * 2) / numberOfPoints
	const xPosition = shape.clientWidth / 2
	const yPosition = shape.clientHeight / 2

	const points = []

	for (let i = 1; i <= numberOfPoints; i++) {
		const radiusAtPoint = i % 2 === 0 ? radius : size
		const x = xPosition + Math.cos(i * angleStep) * radiusAtPoint
		const y = yPosition + Math.sin(i * angleStep) * radiusAtPoint

		points.push({ x, y })
	const polygonCoordinates ={ x, y }) => {
		return `${x}px ${y}px`
	}).join(',')'--clip', `polygon(${polygonCoordinates})`)
	pointsLabel.innerText = numberOfPoints
	radLabel.innerText = `${Math.round(radius / size * 100)}%`


inputs.forEach((input) => {
	input.addEventListener('input', createPolygon)

window.addEventListener('resize', createPolygon)