Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div id="root" class="root">
	<div class="plane">
		<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1240 880">
			<path style="fill:#fafafa; stroke:none;" d="M22 490C35.3403 497.029 50.8846 501.101 65 506.425C98.9786 519.241 133.197 531.527 167 544.797C178.584 549.345 190.316 553.659 202 557.947C207.451 559.947 215.301 561.371 219.581 565.499C224.498 570.242 226.073 580.711 228.424 587C235.132 604.94 241.36 623.055 248.05 641C272.321 706.102 291.739 774.544 320 838C333.8 826.767 344.188 807.247 354.873 793L425.373 699L451.526 664C454.525 660.002 458.316 652.18 463.093 650.212C467.945 648.214 476.402 653.43 481 654.997C497.065 660.471 512.904 666.625 529 672C573.917 687.001 618.261 703.813 663 719.344C681.202 725.663 700.97 736.15 720 739L727.718 683L745.718 557L796.282 202L819 42L785 60.1396L722 95.5756L529 204.14L178 401.576L73 460.576L22 490z" />
			<path style="fill:#d5d5d5; stroke:none;" d="M693 204C650.582 238.544 611.58 278.128 571 314.83C509.222 370.705 446.958 426.15 386 482.91C360.728 506.442 335.075 529.936 309 552.576C301.846 558.787 295.1 565.45 288 571.714C285.142 574.237 280.741 576.986 279.929 581C279.139 584.906 282.086 590.363 283.344 594L293.495 623C306.239 659.709 323.245 697.155 332 735L333 735L363.576 652L378.728 612L400.119 584L446.576 524L573.424 360L661.732 246L683.576 218L693 204z" />
		</svg>
	</div>
</div>
              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

.root > svg {
	display: inline-block;
	position: absolute;
	top: -1%;
	left: 10%;
	transform: translateX(2000px);
	animation: float 8s linear infinite forwards;
	opacity: 0.4;
}

html {
	background-color: rgb(163, 163, 244);
}

body {
	margin: 0;
	position: relative;
}

html,
body {
	overflow: hidden;
	height: 100vh;
}

.root {
	height: 100%;
	width: 010%;
	overflow: hidden;

	.plane > svg {
		top: 40%;
		transform-origin: center right;
		animation: fly 11s linear infinite;
		position: absolute;
		max-height: 200px;
		z-index: 999999;
	}
}

@keyframes fly {
	0%,
	100% {
		transform: rotate(45deg) translateX(30%);
	}

	33% {
		transform: rotate(25deg) translateX(50%);
	}

	66% {
		transform: rotate(60deg) translateX(10%);
	}
}

@keyframes float {
	0%,
	100% {
		transform: translateY(10%) translateX(100%);
	}
	80% {
		transform: translateY(10%) translateX(-100%);
	}
	90% {
		transform: translateY(-500%) translateX(-100%);
	}
	95% {
		transform: translateY(-500%) translateX(100%);
	}
}

              
            
!

JS

              
                interface Circle {
	cx: number;
	cy: number;
	r: number;
}

function* CircleGenerator(
	pos: [number, number]
): Generator<{ left: Circle; right: Circle }> {
	// Start with:
	// Position = Center Position
	const [cx, cy] = pos;
	let [x, y] = [cx, cy];
	// Radius = Max Radius
	let radius = 48;
	// Left Angle = 180
	let leftAngle: number = 180;
	// Right Angle = 0
	let rightAngle: number = 0;
	const rand = (min: number, max: number): number => {
		min = Math.ceil(min);
		max = Math.floor(max);
		return Math.floor(Math.random() * (max - min)) + min;
	};
	while (true) {
		// PICK TWO ANGLES: Left and Right
		// Left should be between 155 and 205 degrees
		leftAngle = rand(155, 205);
		// Right should be between -35 and 35 degrees
		rightAngle = rand(-25, 25);
		// get next set of circle centers by:
		// Generating a new, smaller radius for each angle
		let nextRadius: number = radius * 0.8;
		// calculate the distance from current center by adding current radius to this circles radius
		const distanceToNextCenter = radius + nextRadius;
		// use cos & sin to get next point
		const rightPoint = [
			Math.cos(rightAngle * (Math.PI / 180)) * distanceToNextCenter,
			Math.sin(rightAngle * (Math.PI / 180)) * distanceToNextCenter
		];

		const leftPoint = [
			Math.cos(leftAngle * (Math.PI / 180)) * distanceToNextCenter,
			Math.sin(leftAngle * (Math.PI / 180)) * distanceToNextCenter
		];

		yield {
			left: {
				cx: leftPoint[0],
				cy: leftPoint[1],
				r: nextRadius
			},
			right: {
				cx: rightPoint[0],
				cy: rightPoint[1],
				r: nextRadius
			}
		};

		radius = nextRadius;
	}
}

window.addEventListener("load", onLoad);

function createTestCanvas(parent: HTMLElement): CanvasRenderingContext2D {
	const canvas = document.createElement("canvas");

	canvas.width = 460;
	canvas.height = 460 / 1.62;

	parent.appendChild(canvas);

	return canvas.getContext("2d") as CanvasRenderingContext2D;
}

function createCloud(): SVGElement {
	const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
	svg.setAttribute("viewBox", "0 0 400 164");
	svg.style.top = Math.random() * 40 + "%";
	const baseCircle = document.createElementNS(
		"http://www.w3.org/2000/svg",
		"circle"
	);
	baseCircle.setAttribute("cx", "200");
	baseCircle.setAttribute("cy", "82");
	baseCircle.setAttribute("r", "40");
	baseCircle.setAttribute("fill", "white");
	svg.appendChild(baseCircle);
	const gen = CircleGenerator([400, 164]);
	let current = gen.next();

	for (let i = 0; i < 64; i += 1) {
		const { left, right } = current.value;
		const { cx: lx, cy: ly, r: lr } = left;
		const { cx: rx, cy: ry, r: rr } = right;
		const leftCircle = document.createElementNS(
			"http://www.w3.org/2000/svg",
			"circle"
		);
		const rightCircle = document.createElementNS(
			"http://www.w3.org/2000/svg",
			"circle"
		);
		leftCircle.setAttribute("cx", lx + 200);
		leftCircle.setAttribute("cy", ly + 82);
		leftCircle.setAttribute("r", lr);
		leftCircle.setAttribute("fill", "white");
		rightCircle.setAttribute("cx", rx + 200);
		rightCircle.setAttribute("cy", ry + 82);
		rightCircle.setAttribute("r", rr);
		rightCircle.setAttribute("fill", "white");
		svg.style.filter = `blur(6px)`;
		svg.appendChild(leftCircle);
		svg.appendChild(rightCircle);
		current = gen.next();
	}

	return svg;
}

function onLoad(): void {
	const root = document.getElementById("root") || document.body;
	const ctx = createTestCanvas(root);
	let i = 0;
	root.appendChild(createCloud());

	const interval = window.setInterval(() => {
		if (i < 6) root.appendChild(createCloud());
		else window.clearInterval(interval);

		i += 1;
	}, 2100);
}

              
            
!
999px

Console