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

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

              
                - var img="https://56.media.tumblr.com/649785949a860601eb4dab9fd54cecd4/tumblr_mmj8shdv7C1qb7rifo1_1280.jpg"
- var twitter="https://twitter.com/rileyjshaw"

.container
	.cite
		p click to toggle colors | mouse x controls spacing | mouse y controls gap
		p source: <a target="_blank" href=#{img}>Unknown</a> | remix by: <a target="_blank" href=#{twitter}>rileyjshaw</a>
	
              
            
!

CSS

              
                .container
	box-shadow: 0 0 18px 6px rgba(#000, 0.25)
	display: none
	left: 50%
	padding: 8px
	position: absolute
	top: 50%
	transform: translate(-50%, -50%)

.cite
	padding-top: 1em
	position: absolute
	right: 0
	text-align: right
	top: 100%

p, a
	color: #222

p
	font-family: monospace
	margin: 0 0 0.5em

              
            
!

JS

              
                // Play with these!
const SCALE = 1;
const MEAN_SPACING = 8;

// Derived...
const PI = Math.PI;
const H = SCALE * Math.min(window.innerHeight * 0.7, 600) * 2;
const W = SCALE * Math.min(window.innerWidth * 0.7, 800) * 2;
const BASE_SPACING = MEAN_SPACING / 1.5;
const R_MAX = Math.ceil(Math.sqrt(Math.pow(W, 2) + Math.pow(H / 2, 2)));

const container = document.querySelector('.container');
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.height = H;
canvas.width = W;
canvas.style.height = H / 2 + 'px';
canvas.style.width = W / 2 + 'px';
ctx.lineWidth = SCALE * 2;
container.appendChild(canvas);

// y => [0, 1)
// x => [0, 1)
let y = 0;
let x = 0.5;
let xPrev, yPrev;
canvas.addEventListener('mousemove', ({clientY, clientX}) => {
	y = 1 - (clientY - ~~canvas.getBoundingClientRect().top) / (H / 2);
	x = (clientX - ~~canvas.getBoundingClientRect().left) / (W / 2);
}, false);

let colored = true;
canvas.addEventListener('click', () => {
	colored = !colored;
	if (!colored) {
		ctx.strokeStyle = '#000';
	}
	xPrev = null;
}, false);

ctx.globalCompositeOperation = 'screen';
(function step() {
	requestAnimationFrame(step);
	if (xPrev === x && yPrev === y) return;
	
	const ROUGH_SPACING = BASE_SPACING * (1 + x) * 2;
	const SPACING = W / Math.round(W / ROUGH_SPACING);
	const min = Math.floor((W - R_MAX) / SPACING);
	const max = Math.ceil(R_MAX / SPACING);
	ctx.clearRect(0, 0, W, H);
	let lastR2;
	for (let i = min; i < max; i++) {
		if (colored) {
			ctx.strokeStyle = 'hsl(' + i / max * 360 + ', 100%, 60%)';
		}

		const R1 = i * SPACING;
		const R2 = W - R1;

		ctx.beginPath();
		if (R1 > 0) ctx.arc(click(y * W / 2, SPACING), H / 2, R1, 0, PI * 2);
		ctx.stroke();
		
		ctx.beginPath();
		if (R2 > 0) ctx.arc(click(W / (1 + y), SPACING), H / 2, R2, PI, -PI, true);
		ctx.stroke();
	}
	
	xPrev = x;
	yPrev = y;
})(0);

container.style.display = 'block';

// Clicks a value to its nearest grid value.
function click(val, spacing) {
	return Math.round(val / spacing) * spacing;
}

              
            
!
999px

Console