123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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.

            
              <div class="scene-container">
	<div class="scene">
		<div class="skybox" id="skybox">
			<div class="sun"></div>
		</div>
		<div class="background">
		</div>
		<div class="background two">
		</div>
		<div class="background three">
		</div>
		<div class="foreground">
			<div class="track">
				<div class="catenary"></div>
				<div class="train">
					<div class="pantograph">
						<div class="spark"></div>
					</div>
					<div class="cars">
						<div class="car"></div>
						<div class="car"></div>
						<div class="car"></div>
					</div>
					<div class="undercarriage">
						<div class="carriage">
							<div>
								<div class="wheel"></div>
								<div class="wheel"></div>
							</div>
							<div>
								<div class="wheel"></div>
								<div class="wheel"></div>
							</div>
						</div>
						<div class="carriage">
							<div>
								<div class="wheel"></div>
								<div class="wheel"></div>
							</div>
							<div>
								<div class="wheel"></div>
								<div class="wheel"></div>
							</div>
						</div>
						<div class="carriage">
							<div>
								<div class="wheel"></div>
								<div class="wheel"></div>
							</div>
							<div>
								<div class="wheel"></div>
								<div class="wheel"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="road"></div>
			<div class="crossing-guard">
				<div class="crossbars"></div>
				<div class="arm"></div>
			</div>
			<div class="crossing-guard mirrored">
				<div class="crossbars"></div>
				<div class="arm"></div>
			</div>
		</div>
	</div>
</div>
            
          
!
            
              //desert color palette
$timberwolf: #d9d4ce;
$wafer: #ddd1c3;
$coldturkey: #c7b7b7;
$rodeodust: #c8a995;
$graychateau: #9ea5ad;
$ghost: #c9c9d6;
$aquaisland: #a3c7dd;
$goldenrod: #fcd667;
$fire: #ab3400;
$aliceblue: #f0f8ff;

$sky: lighten($aquaisland, 3);
$cloud: $aliceblue;
$background: $graychateau;
$foreground: $timberwolf;
$glass: desaturate($sky, 30);

$gray: #ccc;

$scene-width: 60rem;
$scene-height: 34rem;

$train-length: 24rem;
$train-time: 18;

$animation-time: 200;

@mixin mountain {
	clip-path: polygon(
		0% 59%,
		4% 55%,
		7% 55%,
		10% 56%,
		13% 53%,
		15% 53%,
		18% 52%,
		22% 50%,
		27% 46%,
		29% 44%,
		32% 43%,
		36% 43%,
		38% 43%,
		40% 45%,
		42% 46%,
		45% 42%,
		46% 41%,
		48% 42%,
		52% 40%,
		56% 40%,
		59% 41%,
		63% 41%,
		65% 42%,
		68% 41%,
		69% 41%,
		75% 44%,
		80% 47%,
		84% 49%,
		87% 50%,
		89% 50%,
		91% 52%,
		94% 52%,
		96% 54%,
		100% 56%,
		100% 58%,
		100% 100%,
		0% 100%
	);
}

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

	&::before,
	&::after {
		content: "";
		display: block;
		position: absolute;
	}
}

html {
	font-size: 100%;
}

.scene-container {
	display: flex;
	justify-content: center;
	align-items: center;
	overflow-x: hidden;
	width: 100vw;
	min-height: 100vh;
	padding: 1rem;
}

.scene {
	border: 3rem solid desaturate($graychateau,25);
	border-radius: 0.5rem;
	box-shadow: 0 0.25rem 0 darken($graychateau,10);
	background-color: transparent;
	width: $scene-width;
	height: $scene-height;
	flex-shrink: 0;
	overflow: hidden;
	position: relative;
}

.skybox {
	background-image: linear-gradient(
		to bottom,
		lighten($sky, 15),
		darken($sky,5)
	);
	width: 100%;
	height: 100%;
	z-index: 5;
}

.sun {
	width: 6rem;
	height: 6rem;
	background: lighten($wafer, 18);
	border-radius: 50%;

	filter: blur(1px);

	position: absolute;
	top: 1rem;
	right: 0.5rem;

	&::before {
		background: lighten($wafer, 18);
		border-radius: 50%;
		width: 200%;
		height: 200%;
		left: -50%;
		top: -50%;
		filter: blur(4rem);
	}
}

$cloud-desat: desaturate($cloud, 50);

.cloud {
	animation: animateclouds ($animation-time + s) infinite linear;
	background-color: $cloud;
	border-radius: 3rem;
	border-left: 3px solid darken($cloud-desat, 3);
	border-bottom: 3px solid darken($cloud-desat, 6);
	box-shadow: -1px 3px 1rem 0px rgba(0, 0, 0, 0.05);
	left: -16rem;
	width: 12rem;
	height: 4rem;
	position: absolute;

	&::before,
	&::after {
		background: $cloud;
		border-radius: 50%;
		border-left: 3px solid darken($cloud-desat, 3);
	}

	&::before {
		width: 100px;
		height: 100px;
		top: -45px;
		left: 70px;
		z-index: 2;
	}

	&::after {
		width: 60px;
		height: 60px;
		top: -20px;
		left: 30px;
	}

	@for $i from 1 through 10 {
		&__#{$i} {
			animation-delay: -($animation-time - random($animation-time)) + s;
			top: (random(300) + px);
			transform: scale((random(10)/10) + 0.75);
		}
	}
}

@keyframes animateclouds {
	100% {
		transform: translateX(100rem);
	}
}

.background {
	@include mountain;
	background-color: lighten($background, 10);
	bottom: 0;
	position: absolute;
	height: 100%;
	width: 100%;
	z-index: 10;

	&.two {
		transform: translate(25rem, 2rem);
		z-index: 9;
	}

	&.three {
		transform: translate(-30rem, 2rem);
		z-index: 9;
	}

	&::before {
		@include mountain;
		background: linear-gradient(
			to bottom,
			lighten($background, 10),
			lighten($background, 10) 45%,
			$background,
			darken($background, 10)
		);
		bottom: 0;
		height: 100%;
		width: 100%;
		transform: translateY(0.25rem);
		z-index: -1;
	}
}

.foreground {
	background: linear-gradient(
		to top,
		$foreground,
		$foreground 9rem,
		desaturate(darken($foreground, 12), 35)
	);
	bottom: 0;
	position: absolute;
	height: 40%;
	width: 100%;
	z-index: 20;
}

.road {
	background: linear-gradient(
	to top,
	$timberwolf,
	darken($timberwolf,10),
	desaturate(darken($foreground, 12), 35)
	);
	
	filter: blur(0.5px);
	width: 2.25rem;
	height: 16rem;
	left: 31.25rem;
	bottom: 0;
	position: absolute;
	transform: perspective(0.5rem) rotatex(5deg);
	z-index: -1;
}

.track {
	background: $gray;
	border-bottom: 3px solid darken($gray, 3);

	height: 1rem;
	width: 100%;

	position: absolute;
	bottom: 6rem;

	&::before {
		background: repeating-linear-gradient(
			to right,
			transparent 0,
			transparent 2px,
			desaturate($rodeodust, 50) 2px,
			desaturate($rodeodust, 50) 4px
		);

		border-bottom: 1px solid lighten($graychateau, 10);
		border-top: 1px solid lighten($graychateau, 10);

		width: 100%;
		height: 5px;

		top: 3px;
	}
	
	&::after {
		background-color: desaturate($wafer, 5);

		height: 1.25rem;
		width: 100%;

		position: absolute;

		filter: blur(2px);
		z-index: -1;		
	}
}

.catenary {
	background: repeating-linear-gradient(
		to right,
		lighten($graychateau, 8) 0,
		$gray 3px,
		transparent 3px,
		transparent 80px
	);

	height: 2rem;
	width: 100%;

	position: absolute;

	top: -2rem;
	
	z-index: 50;

	&::before {
		background-color: $graychateau;
		width: 100%;
		height: 1px;
		top: 0.25rem;
	}
}

.train {
	animation: ($train-time + s) linear infinite train-movement;

	height: 1.5rem;
	width: $train-length;

	position: absolute;
	bottom: 0.5rem;
	left: -$train-length;

	z-index: 100;
}

.pantograph {
	background: $graychateau;

	width: 2rem;
	height: 0.2rem;

	left: 0;
	right: 0;
	top: -0.1rem;

	margin: 0 auto;
	position: absolute;

	&::before,
	&::after {
		background: darken($graychateau, 10);
		width: 0.1rem;
		height: 0.5rem;
		transform-origin: bottom center;
	}

	&::before {
		transform: rotatez(70deg);

		top: -0.5rem;
		left: 1rem;
	}

	&::after {
		transform: rotatez(-70deg);

		top: -0.7rem;
		left: 1.5rem;
	}
}

.spark {
	animation: 1s spark infinite linear;
	background-color: $cloud;
	border-radius: 50%;
	width: 4px;
	height: 4px;

	opacity: 0;
	position: absolute;
	top: -0.5rem;
	left: 1rem;

	z-index: 1;
}

.cars {
	animation: 1s car-bounce infinite ease;
	display: flex;
	justify-content: space-between;

	height: 100%;
	width: 100%;
}

.car {
	background: linear-gradient(
		to top,
		$rodeodust,
		$rodeodust 2px,
		desaturate($goldenrod, 25) 2px,
		desaturate($goldenrod, 25) 4px,
		lighten($graychateau, 5) 4px,
		$gray
	);

	border-top: 3px solid darken($gray, 7);
	border-bottom: 4px solid $graychateau;
	border-right: 1px solid $graychateau;
	border-left: 1px solid $graychateau;
	border-top-right-radius: 4px;
	border-top-left-radius: 4px;

	position: relative;

	width: (($train-length / 3) - 0.1rem);
	height: 100%;

	&::before,
	&::after {
		background: linear-gradient(
			to right,
			$glass 0,
			$glass 1rem,
			$rodeodust 1rem,
			$rodeodust 1.25rem,
			$glass 1.25rem,
			$glass 2.25rem,
			$rodeodust 2.25rem,
			$rodeodust 2.5rem,
			$glass 2.5rem
		);
		border: 1px solid lighten($graychateau, 8);
		border-radius: 2px;
		box-shadow: -1px 0px 1px rgba(black, 0.2) inset;
		width: ((($train-length / 3) - 0.1rem) * 0.425);
		height: 0.5rem;
		top: 0.1rem;
	}

	&::before {
		left: 0.2rem;
	}

	&::after {
		right: 0.2rem;
	}
}

.undercarriage {
	display: flex;
	justify-content: space-between;
	width: 100%;
}

.carriage {
	display: flex;
	justify-content: space-between;
	padding: 0 0.2rem;
	width: (($train-length / 3) - 0.1rem);

	position: relative;
	bottom: 0.2rem;

	z-index: -1;

	&::before {
		background: darken($graychateau, 15);
		width: 2rem;
		height: 0.5rem;
		bottom: 0.1rem;
		left: 3rem;
	}

	&::after {
		background: rgba(black, 0.2);
		width: 100%;
		height: 0.4rem;
		filter: blur(0.2rem);
		left: -0.2rem;
		top: 0.2rem;

		z-index: -2;
	}

	> div {
		display: flex;
		flex-direction: row;
	}
}

.wheel {
	animation: 0.8s rotate-wheels infinite linear;
	background: darken($graychateau, 20);
	border-radius: 50%;
	border-bottom: 1px solid $graychateau;
	width: 0.5rem;
	height: 0.5rem;
	margin: 0 0.05rem;
}

.crossing-guard {
	background: linear-gradient(
		to right,
		lighten($graychateau, 8) 0,
		$gray
	);
	height: 3rem;
	width: 0.2rem;
	
	position: absolute;
	bottom: 4rem;
	left: 34.75rem;
	z-index: 200;
	
	&::before,
	&::after {
		background: $fire;
		border-radius: 50%;
		border: 0.2rem solid darken($graychateau,25);
		width: 0.3rem;
		height: 0.3rem;
		top: 1.1rem;
		z-index: -1;
	}
	
	&::before {
		left: -0.6rem;
	} 
	
	&::after {
		right: -0.6rem;
	}
	
	&.mirrored {
		bottom: 7.5rem;
		left: 30.5rem;
		transform: scale(-0.75,0.75);
		z-index: 1;
		
		.arm {
			animation-delay: 0.25s;
		}
	}
}

.crossbars {
	background: $cloud;
	width: 1rem;
	height: 0.2rem;
	transform: rotatez(45deg);
	left: -0.4rem;
	top: 0.5rem;
	position: absolute;
	
	&::before {
		background: $cloud;
		width: 0.2rem;
		height: 1rem;
		left: 0.4rem;
		top: -0.4rem;
		z-index: -1;
	}
}

.arm {
	animation: ($train-time + s) drop-gate ease-in-out infinite;
	background: repeating-linear-gradient(
		to right,
		desaturate($fire,25),
		desaturate($fire,25) 0.25rem,
		$cloud 0.25rem,
		$cloud 0.5rem
		);
	width: 3.5rem;
	height: 0.2rem;
	transform-origin: 3rem center;
	transform: rotatez(70deg);
	position: absolute;
	right: -0.5rem;
	top: 2rem;
	
	&::before {
		width: 0.5rem;
		height: 0.5rem;
		background: $graychateau;
		border-radius: 0.1rem;
		right: -0.25rem;
	}
}

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

@keyframes train-movement {
	100% {
		transform: translatex(($scene-width) + (2 * $train-length));
	}
}

@keyframes car-bounce {
	0%,
	50%,
	60% {
		transform: translatey(0);
	}
	55% {
		transform: translatey(0.5px);
	}
}

@keyframes spark {
	0%,
	70%,
	73% {
		opacity: 0;
	}
	71%,
	72% {
		opacity: 1;
	}
}

@keyframes drop-gate {
	0%,10%,70%,100% {
		transform: rotatez(70deg);
	}
	20%,60% {
		transform: rotatez(0deg);
	}
}
            
          
!
            
              const CLOUD_COUNT = 10;

function initScene() {
	this.generateClouds(CLOUD_COUNT);
}

function generateClouds(cloudCount) {
	for (let i = 1; i < cloudCount; i++) {
		let cloud = document.createElement("div");
		cloud.classList.add("cloud", `cloud__${i}`);

		this.document.getElementById("skybox").appendChild(cloud);
	}
}

initScene();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console