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.zdog-canvas
button.btn-reset(
	type='button'
) reset
              
            
!

CSS

              
                $bg_color: hotpink;
// $bg_color: #908efc; // light purple
$btn_color: #7c4de1;
// $btn_color: #000; // black
$btn_font_color: #fff;
$btn_focus: #e89e21;

html,
body {
	width: 100%;
	height: 100%;
}

body {
	background-color: $bg_color;
	margin: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	overflow: hidden;
}

.zdog-canvas {
	background-color: transparent;
	cursor: move;
}

.btn-reset {
	$size: 0.7rem;
	background-color: $btn_color;
	border: 0;
	color: $btn_font_color;
	cursor: pointer;
	font-family: 'Press Start 2P', cursive;
	font-size: $size;
	letter-spacing: 0.15rem;
	outline: none;
	padding: $size $size $size ($size * 1.25);
	text-transform: uppercase;
	-webkit-tap-highlight-color: transparent;
	
	&:focus {
		color: $btn_focus;
	}
}
              
            
!

JS

              
                /* 
 * ZDOG - NES SHROOM
 * Made with Zdog - Enjoy!
 * Inspired by the classic Mario Bros video game. 
 * https://zzz.dog/
 *
 * Drag the shroom to rotate it manually.
 *
 * #003 - #100DaysOfCode
 * By ilithya | 2019
 */

const illoElem = document.querySelector('canvas');
const illoSize = 230;
const minWindowSize = Math.min(window.innerWidth, window.innerHeight);
const zoomSize = (minWindowSize / illoSize);
const zoom = (zoomSize < 1) ? zoomSize : Math.floor(zoomSize);
const sceneStartRotation = { x: 0.25, y: 0.2};
const TAU = Zdog.TAU;
let isSpinning = true;

illoElem.setAttribute('width', window.innerWidth);
illoElem.setAttribute('height', (illoSize * zoom) - 20);

const illo = new Zdog.Illustration( {
	rotate: sceneStartRotation,
	element: illoElem,
	zoom: zoom,
	dragRotate: true,
	onDragStart: function() {
		isSpinning = false;
	},
	onDragEnd: function() {
		isSpinning = true;
	},
});

const c_01 = '#7c4de1'; // purple
const c_02 = '#ffffff'; // white
const c_03 = '#fffffd'; // dark white
const c_04 = '#906fd8'; // light purple
const c_05 = '#fae3d9'; // creamy
// Original color palette:
// const c_01 = '#e89e21'; // mustard
// const c_02 = '#b52f24'; // dark red
// const c_03 = '#fffffd'; // dark white
// const c_04 = '#713b39'; // brown
// const c_05 = '#fae3d9'; // creamy

const shroom = new Zdog.Anchor({
	addTo: illo,
	rotate: { x: TAU/4 },
});

const cap = new Zdog.Hemisphere({
	addTo: shroom,
	diameter: 160,
	stroke: 10,
	color: c_01,
	backface: c_04,
});
// Let's draw the schroom's gills as well
new Zdog.Ellipse({
	addTo: shroom,
	diameter: 160,
	stroke: 10,
	color: c_04,
	fill: true,
});

const stem = new Zdog.Cylinder({
	addTo: shroom,
	diameter: 80,
	length: 70,
	stroke: false,
	color: c_03,
	translate: { z: -30 },
	backface: c_05,
});

const scalesZ = (cap.diameter / 2);
const scalesAnchor = new Zdog.Anchor({
	addTo: cap,
	translate: { z: scalesZ },
});
const aScale = new Zdog.Shape({
	addTo: scalesAnchor,
	stroke: 12,
	color: c_02,
	translate: { z: 5 },
	backface: c_02,
});
aScale.copy({
	stroke: 20,
	translate: { 
		x: (scalesZ / 1.3), 
		y: 40,
		z: (scalesZ / -1.8) 
	},
});
aScale.copy({
	stroke: 30,
	translate: { 
		x: -75, 
		y: -10,
		z: (scalesZ / -1.7) 
	},
});
aScale.copy({
	stroke: 15,
	translate: { 
		y: 73,
		z: (scalesZ / -2)
	},
});
aScale.copy({
	stroke: 18,
	translate: { 
		x: (scalesZ / -2.7),
		y: (scalesZ / -1.1), 
		z: (scalesZ / -1.3) 
	},
});
aScale.copy({
	stroke: 25,
	translate: { 
		x: (scalesZ / -1.8),
		y: (scalesZ * 0.75),
		z: (scalesZ / -1.5) 
	},
});
aScale.copy({
	stroke: 30,
	translate: { 
		x: (scalesZ / 1.8),
		y: (scalesZ * -0.75),
		z: (scalesZ / -1.7) 
	},
});
aScale.copy({
	stroke: 20,
	translate: { 
		x: 53,
		y: -10,
		z: -20
	},
});
aScale.copy({
	stroke: 17,
	translate: { 
		x: -34,
		y: -40,
		z: -15
	},
});
aScale.copy({
	stroke: 20,
	translate: { 
		x: -40,
		y: 20,
		z: -10
	},
});
aScale.copy({
	stroke: 13,
	translate: { 
		x: 30,
		y: 30,
		z: -8
	},
});
// This scale is good only with the following anim:
// illo.rotate.y = (Math.cos(theta) / -32);
// aScale.copy({
// 	stroke: 14,
// 	translate: { 
// 		x: 80,
// 		z: -60
// 	},
// });
aScale.copy({
	stroke: 22,
	translate: { 
		x: 10,
		y: -50,
		z: -17
	},
});

let t = 0;
function animate() {
	if (isSpinning) {		
		t += 1/140;
		const theta = Zdog.easeInOut(t % 1) * TAU;
		illo.rotate.y = (Math.cos(theta) / -8);
		// Lighter spinning anim:
		// illo.rotate.y = (Math.cos(theta) / -32);
	}
	illo.updateRenderGraph();
	requestAnimationFrame(animate);
}
illo.updateRenderGraph();
animate();

const reset = document.querySelector('.btn-reset');
reset.onclick = function () {
	this.blur();
	illo.rotate.set(sceneStartRotation);
};
              
            
!
999px

Console