cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              body
	font-size: 0
	background: #eee

.container
	position: absolute
	top: 50%
	left: 50%
	transform: translate3d(-50%, -50%, 0)
	background: #fff
	box-shadow: 0 0 24px 8px rgba(0, 0, 0, 0.2)
	cursor: pointer

	p
		position: absolute
		bottom: -2.5em
		left: 0
		right: 0
		margin: 0
		text-align: center
		font: 16px monospace
		color: #444

            
          
!
            
              // Play with these!
const PX = 600;
const N = 20;
const SPEED = 6;
const RANGE = [40, 400];

let a, b, c, d;
setCoefficients();
const fn = (x, y) => [a * x + b * y, c * x + d * y];

// Derived.
const SPACING = PX / N;
const HALF_PX = PX / 2;
const HALF_N = Math.floor(N / 2) + 1;
if (RANGE[0] < SPEED) RANGE[0] = SPEED;

const container = document.querySelector('.container');
const canvas = document.createElement('canvas');
canvas.height = canvas.width = PX;
canvas.style.height = canvas.style.width = `${HALF_PX}px`;
container.appendChild(canvas);

const ctx = canvas.getContext('2d');
ctx.translate(HALF_PX, HALF_PX);
ctx.globalCompositeOperation = 'xor';

let dir = 1;
let lw = RANGE[0] + SPEED;
(function draw () {
	if (lw <= RANGE[0] || lw > RANGE[1]) dir = -dir;
	lw = ctx.lineWidth = lw + dir * SPEED;
	
	ctx.clearRect(-HALF_PX, -HALF_PX, PX, PX);
	for (let y = -HALF_N; y < HALF_N; ++y) {
		const yPx = y * SPACING;
		ctx.beginPath();
		for (let x = -HALF_N; x < HALF_N; ++x) {
			const xPx = x * SPACING;
			ctx.moveTo(xPx, yPx);
			ctx.lineTo(...fn(xPx, yPx));
		}
		ctx.stroke();
	}
	
	requestAnimationFrame(draw);
})();

function setCoefficients () {
	a = (Math.random() < 0.5) * 2 - 1;
	b = (Math.random() < 0.5) * 2 - 1;
	c = (Math.random() < 0.5) * 2 - 1;
	d = (Math.random() < 0.5) * 2 - 1;
}

container.addEventListener('click', setCoefficients, false);

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console