cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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
	background: rgb(144, 142, 143)

canvas
	position: absolute
	top: 50%
	left: 50%
	transform: translate(-50%, -50%)

            
          
!
            
              const size = 400;
const diff = 20;
const canvas1 = document.createElement('canvas');
const canvas2 = document.createElement('canvas');
const ctx1 = canvas1.getContext('2d');
const ctx2 = canvas2.getContext('2d');
[canvas1, canvas2].forEach(canvas => {
    canvas.height = canvas.width = size * 2;
	canvas.style.height = canvas.style.width = `${size}px`;
	document.body.appendChild(canvas);
	canvas.style.border = `${diff / 8}px solid rgb(8, 7, 8)`;
});

[ctx1, ctx2].forEach(ctx => {
	ctx.lineWidth = diff / 4;
	ctx.strokeStyle = 'rgb(8, 7, 8)';
	ctx.translate(size, size);
});

let toggle = true;
function loop () {
	const ctx = toggle ? ctx1 : ctx2;
	const canvas = toggle ? canvas2 : canvas1;
	ctx.globalAlpha = 0.96;
	ctx.rotate(0.001);
	
	ctx.clearRect(-size, -size, size * 2, size * 2);
	ctx.drawImage(canvas, diff / 2 - size, diff / 2 - size, size * 2 - diff, size * 2 - diff);
	ctx.beginPath();
	ctx.arc(0, 0, size + diff / 4, 0, 2 * Math.PI);
	ctx.stroke();
	toggle = !toggle;
	window.requestAnimationFrame(loop);
}

loop();

            
          
!
999px
Loading ..................

Console