css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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, body
	height: 100%

	margin: 0
	display: flex
	align-items: center
	justify-content: center
	background: #989080

	display: flex
	flex-flow: row wrap
	align-items: space-between
	justify-content: space-between
	width: 580px
	height: 580px

	height: 120px
	width: 120px
	flex-grow: 0
	flex-shrink: 0
	box-shadow: 0 0 40px rgba(#323, 0.3)
	&:nth-child(3n), &:nth-child(5n)
		border-radius: 50%
		transform: rotate(-30deg)

              const NUM_SUNS = 16;

const {random} = Math;

const container = document.createElement('div');
container.className = 'container';

// Util.
const randomColor = () => `#${(~~(random() * (1<<24))).toString(16)}000000`.slice(0, 7);

class Sun {
    constructor () {
		const canvas = document.createElement('canvas');
		this.width = canvas.width = 1;
		this.height = canvas.height = canvas.offsetHeight * 2;
		this.ctx = canvas.getContext('2d');
	redrawLoop () {
		setTimeout(() => this.redrawLoop(), 1000 + Math.random() * 2000);
		if (blockDrawing) return;
    assignVars () {
		this.ctx.fillStyle = randomColor();
		this.ctx.canvas.style.background = randomColor();
		this.numLines = ~~(6 + random() * 8);
		// Initial line height : full yStep height.
		this.ratio = random() * random();
	draw () {
		const {ctx, height, numLines, ratio} = this
		const yStep = height / numLines;
		ctx.clearRect(0, 0, 1, height);
		for (let i = 0; i < numLines; ++i) {
			const progress = i / (numLines - 1);  // [0, 1]
			// Eek. Linear Bezier curve between full and final heights.
			// Simplification of:
			//     a + (1 - b) + (1 - a) * b
			// where `a` is initial height and `b` is `progress`.
			const lineHeight = yStep * (ratio - progress * (2 * ratio - 1));
			ctx.fillRect(0, i * yStep, 1, lineHeight);

// Click to block re-drawing in case you come across a color combo you love.
let blockDrawing = false;
document.addEventListener('click', () => blockDrawing = !blockDrawing, false);

const suns = Array.from({length: NUM_SUNS}, () => new Sun());
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................