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

              
                a.download Download Image
.instruction Generate New Mountain 
              
            
!

CSS

              
                *
	margin 0
	padding 0
	box-sizing border-box

body
	overflow hidden
	height 100%
	font-family Arial
	background black
	letter-spacing 0.15em
	text-transform uppercase
	
.download, .instruction
	position absolute 
	top 0
	background #222
	padding 1vw
	border-radius 3px
	margin 1vw
	cursor pointer 
	opacity 0.5
	color white
	font-size 1vw
	text-decoration none
	&:hover
		opacity 1
	
		
.instruction
	left 0
	&.generating
		background white 
		color black 
		pointer-events none
	
.download
	right 0
              
            
!

JS

              
                let limit;
let count;
let space;
let min;
let anchorHue;
let hueRange;
let smoothness;
let mappingDirection;

function setup() {
	createCanvas(innerWidth, innerHeight, WEBGL);
	noLoop();
	noStroke();
	angleMode(DEGREES);
	reset();
	colorMode(HSB, 360, 100, 100);
}

function reset() {
	min = innerWidth < innerHeight ? innerWidth : innerHeight;
	limit = min / random(1.3, 2);
	count = random(100, 150); // resolution
	space = innerWidth / count;
	hueRange = random(160, 300);
	anchorHue = random(360);
	smoothness = random(10, 15);
	mappingDirection = random([true, false]);
}

const getNoise = (i, j) => {
	const value = noise(i / smoothness, j / smoothness);
	return map(value, 0, 1, -limit / 3, limit);
};

function mountainMaker() {
	for (let i = 0; i < count; i += 1) {
		for (let j = 0; j < count; j += 1) {
			let from, to;
			if (mappingDirection) {
				from = -limit / 3;
				to = limit;
			} else {
				from = limit;
				to = -limit / 3;
			}
			const hue = map(
				getNoise(i, j),
				from,
				to,
				anchorHue - hueRange,
				anchorHue + hueRange
			);

			fill(hue, 100, 100);
			beginShape();
			vertex((i + 1) * space, (j + 1) * space, getNoise(i + 1, j + 1));
			vertex((i + 1) * space, (j - 1) * space, getNoise(i + 1, j - 1));
			vertex((i - 1) * space, (j - 1) * space, getNoise(i - 1, j - 1));
			vertex((i - 1) * space, (j + 1) * space, getNoise(i - 1, j + 1));
			endShape();
		}
	}
}

function draw() {
	background(0);
	push();
	translate(-innerWidth / 2, min / 10);
	rotateX(random(50, 65));
	mountainMaker();

	pop();
}

function windowResized() {
	resizeCanvas(innerWidth, innerHeight);
	reset();
}

document.querySelector(".download").addEventListener("click", function () {
	this.download = "crystal-mountain.png";
	this.href = document.querySelector("canvas").toDataURL();
});

document.querySelector(".instruction").addEventListener("click", (e) => {
	if (e.target.classList.contains("generating")) return;
	const original = e.target.textContent;
	e.target.classList.add("generating");
	e.target.textContent = "Generating ...";
	setTimeout(() => {
		reset();
		clear();
		draw();
		e.target.textContent = original;
		e.target.classList.remove("generating");
	}, 0);
});

              
            
!
999px

Console