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.

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

              
                .canvas
	.grid
		- for (var i = 1; i <= 42; i++)
			span(class='grid__cell')
              
            
!

CSS

              
                :root {
	--c_bg: hotpink;
	--c1: #191919; // black
	--c2: white;
	
	// Original Color Palette:
	// --c_bg: #1b1b1b; // black
	// --c1: #cfb53b; // gold
	// --c2: #ebecf0; // silver
}

$cell_size: 3rem; // Resize pattern by editing this variable
$grid_gap: ($cell_size / 2);
$grid_padding: 8%;
$border: 3px;

@mixin size($w, $h: $w) {
	width: $w;
	height: $h;
}

body {
	height: 100vh;
	background-color: var(--c_bg);
	margin: 0;
}

::selection {
	background-color: transparent;
}

// Patterns for shape classes
.p-reg-size {
	@include size($cell_size / 1.3);
}

.p-circle {
	@extend .p-reg-size;
	border-radius: 50%;
	border: $border solid var(--c1);
}

.p-diagonal {
	@include size($cell_size / 1.1);
	border-right: $border solid var(--c1);
}

// General styles
.canvas {
	min-height: 100%; // In case the window is too narrow vertically
	@include size(100%, auto);
	cursor: pointer;
	display: flex; // To center child elem horizontally + vertically 
	transition: transform 0.05s ease-in-out; // To work with added transform styles via JS
}

.grid {
	@include size(100%);
	max-width: calc(#{$grid_padding * 2} + #{$cell_size * 6} + #{$grid_gap * 5});
	box-sizing: border-box;
	
	display: grid;
	grid-template-columns: repeat(auto-fit, $cell_size);
	grid-template-rows: repeat(auto-fit, $cell_size);
	grid-gap: $grid_gap;
	justify-content: center; // To center if window is resized

	margin: auto; // Horizontal + vertical center magic after parent's display flex
	padding: $grid_padding;

	&__cell {
		@include size(100%);
		display: flex;
		align-items: center;
		justify-content: center;

		&::before {
			content: '';
		}

		// Shape classes for generative pattern
		&--1::before {
			@extend .p-circle;
			border-bottom-left-radius: 0;
			border-bottom-right-radius: 0;
			border-bottom: 0;
		}

		&--2::before {
			@extend .p-circle;
			border-top-left-radius: 0;
			border-top-right-radius: 0;
			border-top: 0;
		}

		&--3::before {
			@extend .p-circle;
		}

		&--4::before {
			@extend .p-reg-size;
			border-left: $border solid var(--c1);
			border-bottom: $border solid var(--c1);
		}

		&--5::before {
			@extend .p-reg-size;
			border-right: $border solid var(--c1);
			border-bottom: $border solid var(--c1);
		}

		&--6::before {
			@extend .p-reg-size;
			border-left: $border solid var(--c1);
			border-top: $border solid var(--c1);
		}

		&--7::before {
			@extend .p-reg-size;
			border-right: $border solid var(--c1);
			border-top: $border solid var(--c1);
		}

		&--8::before {
			@extend .p-diagonal;
			transform: rotateZ(45deg) translateX($cell_size / -2.2);
		}

		&--9::before {
			@extend .p-diagonal;
			transform: rotateZ(-45deg) translateX($cell_size / -2.2);
		}
	}
}

// Color classes for generative pattern
@for $i from 1 through 2 {
	.c#{$i}::before {
		border-color: var(--c#{$i});
	}
}
              
            
!

JS

              
                /* 
 * SILVER-GOLD PATTERNS
 * Generative patterns based on 9 geometrical shapes.
 * Click/tap on your screen to stop/play generating a new pattern.
 *
 * #009 - #100DaysOfCode
 * By ilithya | 2019
 */

const getRandomIntInclusive = (minNum, maxNum) => {
	const min = minNum;
	const max = Math.floor(maxNum);

	return Math.floor(Math.random() * (max - min + 1)) + min;
};

const colorClass = {
	options: ["c1", "c2"],
	addRandom: function(el) {
		const randomColorClass = getRandomIntInclusive(0, colorClass.options.length - 1);
		const selectedClass = colorClass.options[randomColorClass];

		el.classList.add(selectedClass);
	}
};

const generativePattern = {
	set: function(el) {
		el.forEach(item => {
			// Let us first remove all classes, to reset them later
			item.className = "";

			/* Reset Class Names */
			// Let's create the shared class and random shape class
			const sharedClass = "grid__cell";
			const totalShapeClasses = 9;
			const randomShapeClass = getRandomIntInclusive(1, totalShapeClasses);
			item.classList.add(sharedClass, `${sharedClass}--${randomShapeClass}`);

			// Let's create the random color class
			colorClass.addRandom(item);
		});
	},
	create: function() {
		const cell = document.querySelectorAll(".grid__cell");
		generativePattern.set(cell);
	}
};

const styleTimeout = {
	set: function(el) {
		setTimeout(() => el.style = '', 50);
	},
	cancel: function() {
		clearTimeout(styleTimeout.set);
	}
};

let animationInterval;
const patternAnimation = {
	timing: 450, // 650
	start: function() {
		animationInterval = setInterval(generativePattern.create, patternAnimation.timing);
	},
	toggle: function () {
		const thisEl = this;

		if (!animationInterval) {
			thisEl.style = `transform: scale(1.1)`;
			patternAnimation.start();
		} else {
			thisEl.style = `transform: scale(0.9)`;
			clearInterval(animationInterval);
			animationInterval = null;
		}
		
		styleTimeout.cancel();
		styleTimeout.set(thisEl);
	},
};

patternAnimation.start();

const canvas = document.querySelector(".canvas");
canvas.addEventListener("click", patternAnimation.toggle);
              
            
!
999px

Console