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.

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

              
                <div id="wrapper">	
	<div id="washingMachine" class="isFilled isOpen">
		<div id="controls">READY</div>
		<div id="door"></div>
		<div id="tub">
			<span class="clothes"></span>
			<span class="clothes"></span>
			<span class="clothes"></span>
		</div>
	</div>
	
	<div id="playground">
		<button id="content">EMPTY</button>
		<button id="opening">CLOSE</button>
		<button id="power" disabled>START</button>
	</div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Nova+Mono&display=swap');

// GLOBAL ―――――――――――――――――――――――――

* {
	box-sizing: border-box;
	padding: 0;
	margin: 0;
}

body {
	display: flex;
	height: 100vh;
	background:	#92bfd1;
	font-size: 14px;
	font-family: 'Nova Mono', monospace;
}

#wrapper {
	margin: auto;
	display: flex;
	flex-direction: column;
	align-items: center;
}


// VARIABLES (Have fun) ―――――――――――――――――――――――――

// Machine

$WM-width: 300px;
$WM-height: $WM-width + $WM-width / 3.4;
$WM-borderRadius: 15px;
$WM-topHeight: 70px;
$WM-bottomHeight: 30px;
$WM-roationSpeed: 0.6s; // If changed, need to be updated in the JS as well

// Colors

$WM-mainColor: #ececf4; // White
$WM-secondaryColor: #c4c4d2; // Light grey
$WM-tertiaryColor: #80819c; // Dark grey
$WM-tubBackground: #453e57;

// Effects

$WM-insetShadowColor: rgba($WM-secondaryColor, 0.3);
$WM-insetShadowSize: 15px;

// Controls

$WM-controlsRatio: 2.2; // Higher numbers produce smaller size
$WM-screenTextSize: 1em;
$WM-screenTextColor: lightgreen;

// Door

$WM-doorRatio: 1.5; // Higher numbers produce smaller size
$WM-doorBorderSize: 25px;


// WASHING-MACHINE ―――――――――――――――――――――――――

#washingMachine {
	background: $WM-mainColor;
	width: $WM-width;
	height: $WM-height;
	border-radius: $WM-borderRadius;
	border-top: 15px solid $WM-tertiaryColor;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	overflow: hidden;
	box-shadow: inset -#{$WM-insetShadowSize} -#{$WM-insetShadowSize} 0 0 $WM-insetShadowColor;
	padding: ($WM-topHeight + 15px) 0 $WM-bottomHeight + 15px;

	&:before, &:after {
		content: "";
		position: absolute;
		border: 4px solid transparent;
		width: 150%;
	}
	
	&:before {
		border-bottom-color: $WM-secondaryColor;
		height: $WM-topHeight;
		top: 0;
		border-radius: 50%;
		box-shadow: inset 0 -#{$WM-insetShadowSize} 0 0 $WM-insetShadowColor;
	}

	&:after {
		border-top-color: $WM-secondaryColor;
		height: $WM-bottomHeight;
		bottom: 0;
	}

	#controls {
		$WM-roundButtonSize: $WM-topHeight / $WM-controlsRatio;
		$WM-elementsWidth: $WM-width / 5;
		$WM-shift: $WM-insetShadowSize + 15px;
		
		// Screen
	
		top: ($WM-topHeight - $WM-roundButtonSize) / 2;
		text-align: center;
		right: $WM-shift;
		background: #242527;
		color: $WM-screenTextColor;
		border-radius: 5px;
		padding: 3px 10px;
		font-weight: 500;
		font-size: $WM-screenTextSize;
		justify-content: center;
		
		&, &:before, &:after { position: absolute; }
		
		&, &:after {
			height: $WM-roundButtonSize - ($WM-roundButtonSize / 4);
			min-width: $WM-elementsWidth;
		}
		
		&, &:before {
			display: flex;
			align-items: center;
			transition: all 0.2s cubic-bezier(.56,.35,0,1.35);
		}
		
		// Round button

		&:before {
			content: "━━";
			font-size: 14px;
			color: $WM-tertiaryColor;
			box-shadow: inset 0px -#{$WM-insetShadowSize} 0px 0px $WM-insetShadowColor;
			height: $WM-roundButtonSize;
			width: $WM-roundButtonSize;
			border: 3px solid $WM-secondaryColor;
			border-radius: 100%;
			transform: rotate(0deg);
			left: calc(100% + #{$WM-shift - $WM-width / 2 - $WM-roundButtonSize / 2});
		}
		
		// Washing powder compartment
		
		&:after {
			content: "";
			left: calc(100% + #{$WM-shift - $WM-width + $WM-shift});
			background: $WM-insetShadowColor;
			border-radius: 3px 3px 10px 10px;
			border: 3px solid $WM-secondaryColor;
			box-shadow: inset 0 10px 0 0 $WM-secondaryColor;
		}
	}

	// Reused values ――

		$WM-tubBaseShadow: 0 0 0 7px $WM-insetShadowColor; // Light grey

		@function doorShadows($inside:transparent, $outside:transparent) {
			@return inset 5px 10px 0 0 $inside, 5px -1px 0 0  $outside;
		};

	// ――

	#door, #tub { transition: all 0.2s ease-in-out; }
	
	#door {
		width: $WM-width / $WM-doorRatio;
		height: $WM-width / $WM-doorRatio;
		border: $WM-doorBorderSize solid $WM-tertiaryColor;
		border-radius: 50%;
		position: absolute;
		z-index: 1;
		box-shadow: doorShadows(rgba(black, 0.1));
		transform-origin: 0% 0%;
		transform: rotateY(0deg);
		
		&:before, &:after {
			content: "";
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
		}
		
		// Door handle
		
		&:after {
			background: darken($WM-tertiaryColor, 10%);
			height: 50%;
			width: 17%;
			right: 0;
			border-radius: 40% 30% 30% 40% / 50% 45% 45% 50%;
			transition: all 0.2s ease-in-out;
			z-index: 3;
		}
		
		// Reflection
		
		&:before {
			width: 60%;
			height: 60%;
			left: 0;
			right: 0;
			margin: auto;
			border-radius: 50%;
			border: 5px solid transparent;
			border-left: 15px solid white;
			transform: translateY(-50%) rotate(45deg);
			opacity: 0.2;
			box-shadow: inset -10px 10px 0 0 rgba(white, 0.2);
			border-radius: 40% 30% 30% 40% / 50%;
			z-index: 2;
		}
  }

	#tub {
		width: $WM-width / $WM-doorRatio - $WM-doorBorderSize;
		height: $WM-width / $WM-doorRatio - $WM-doorBorderSize;
		background: $WM-tubBackground;
		position: relative;
		border-radius: 50%;
		overflow: hidden;
		z-index: 0;
		box-shadow: $WM-tubBaseShadow;

		.clothes {
			position: absolute;
			opacity: 0;
			transition: all 0.1s ease-in-out;
		}

		.clothes:nth-child(1) {
			background: linear-gradient(#48873e, #7b9f17);
			width: 70%;
			height: 25%;
			bottom: 10%;
			right: -20%;
			transform: rotate(-20deg);
			border-radius: 49% 38% 65% 8% / 30% 12% 51% 36%;
		}

		.clothes:nth-child(2){
			background: linear-gradient(#c22323, #e15050);
			width: 100%;
			height: 20%;
			border-radius: 64% 40% 27% 47% / 63% 63% 32% 36%;
			bottom: 0;
		}

		.clothes:nth-child(3) {
			background: linear-gradient(#5a5589, #4f46b4);
			width: 70%;
			height: 25%;
			transform: rotate(40deg);
			border-radius: 41% 38% 71% 8% / 51% 36% 51% 24%;
			bottom: 0;
			left: -10%;
		}
	}

	// ACTIONS

	&.isOpen {
		#door {
			transform: rotateY(45deg);
			box-shadow: doorShadows($outside: lighten($WM-tertiaryColor, 20%));
			
			// Door handle
			&:after { box-shadow: 5px -1px 0 0 darken($WM-tertiaryColor, 20%); }
		}
		
		#tub { box-shadow: inset 5px 10px 0 0 rgba(black, 0.1), $WM-tubBaseShadow; }
	}

	&.isWashing {
		animation-name: shake;
		animation-duration: 100ms;
		animation-timing-function: ease-in-out;
		animation-iteration-count: infinite;
		
		#controls:before { transform: rotate(45deg); }
		
		#tub {
			animation-name: rotate;
			animation-duration: $WM-roationSpeed;
			animation-timing-function: linear;
			animation-iteration-count: infinite;
		}
	}

	&.isFilled #tub .clothes { opacity: 1; }

	&.isStarting {
		animation-duration: 100ms * 2;
		animation-timing-function: cubic-bezier(0,-0.01,.61,.01);
		
		#tub {
			animation-duration: $WM-roationSpeed * 2;
			animation-timing-function: cubic-bezier(0,-0.01,.61,.01);
		}
	}
}


// ANIMATIONS ―――――――――――――――――――――――――

@keyframes shake {
  0%, 100% { transform:  translate(0, 0) rotate(0); }
  25%  { transform:  translate(-1.5px, 1.5px) rotate(0.5deg); }
  50%  { transform:  translate(-0.5px, -0.5px) rotate(0.5deg); }
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}


// PLAYGROUND ―――――――――――――――――――――――――

#playground {
	margin-top: 25px;
	width: $WM-width;
	display: flex;
	
	button {
		flex: 1;
		background: #ececf4;
		border: none;
		outline: none;
		border-radius: 6px;
		padding: 7px 10px;
		box-shadow: -1px 2px 0 0 rgba(black, 0.2);
		transition: background 0.2s ease-in-out;
		font: inherit;
		font-size: 0.8em;
		
		&#opening { margin: 0 15px; }
		
		&:hover:not(:disabled) {
			background: white;
			cursor: pointer;
		}
		
		&::-moz-focus-inner { border:0; }
		&:active:not(:disabled) { box-shadow: 0px 1px 0 0 rgba(black, 0.2); }
	}
}
              
            
!

JS

              
                // VARIABLES ―――――――――――――――――――――――――

const washSpeed = 600; // If changed, need to be updated in the CSS as well
const washingMachine = document.getElementById('washingMachine');
const screen = document.getElementById('controls');

const status = {
	opening: {
		isActive: true,
		statusClass: 'isOpen',
		controller: document.getElementById('opening'),
		controllerLabel: ["CLOSE", "OPEN"]
	},
	content: {
		isActive: true,
		statusClass:'isFilled',
		controller: document.getElementById('content'),
		controllerLabel: ["EMPTY", "FILL"]
	},
	power: {
		isActive: false,
		statusClass: 'isWashing',
		controller: document.getElementById('power'),
		controllerLabel: ["STOP", "START"]
	}
};


// PLAYGROUND ―――――――――――――――――――――――――

for (let action in status) {
	const { statusClass, controller, controllerLabel } = status[action];
	
	controller.addEventListener('click', function(event) {
		const { isActive } = status[action];
		washingMachine.classList.toggle(statusClass);
		this.innerHTML = controllerLabel[isActive*1];
		
		if(action === "power" && !isActive) { // Slow start
			washingMachine.classList.add(statusClass);
			washingMachine.classList.add("isStarting");
			setTimeout(() => { washingMachine.classList.remove("isStarting"); }, washSpeed * 2);
		}
		
		status[action].isActive = !isActive;
		
		setTimeout(function() {
			updateMachine();
		}, 100); // Timeout needed because of a bug on FF when updating innerHTML
	});
}

function updateMachine() {	
	const { opening, content, power } = status;
	
	// Update playground
	
	opening.controller.disabled = power.isActive;
	content.controller.disabled = !opening.isActive;
	power.controller.disabled = opening.isActive || !content.isActive;
	
	// Update screen text
	
	if(power.isActive) {
		screen.innerHTML = "💦"
	} else if(!content.isActive) {
		screen.innerHTML = "EMPTY";
	} else if (opening.isActive) {
			screen.innerHTML = "🙃";
	} else {
		screen.innerHTML = "READY";
	}
}
              
            
!
999px

Console