Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <div id="app" class='app'>
	<canvas id="world"></canvas>
	<svg id="svg"></svg>
	<ul class="controls">
	<li class="control">
	<ul class='series'>
		<transition-group name="list" tag="div">
			<li class='row' v-for="(row, index) in rows" v-bind:key="index">
				<div class='row-content'>
					<select v-on:change="draw" v-model="row.currentValue">
						<option disabled value="">Please select one</option>
						<option v-for="(interval, key, index) in intervals" v-bind:value="key">{{ key }}</option>
				</select>
				</div>
				<div class='row-action'>
					<button v-on:click="removeRow(index)" id="removeRow">Delete</button>
				</div>
			</li>
			<div class="table-actions" key='actions'>
				<button id="addRow">Add Series</button>
			</div>
		</transition-group>
	</ul>
		</li>
	<li class="control">
		<label for="paper-width">Width</label>
		<input type="number" v-on:change="draw" v-model='paperWidth' id="paper-width" name='paper-width'>
	</li>
	<li class="control">
		<label for="paper-width">Height</label>
		<input type="number" v-on:change="draw" id="paper-height" v-model='paperHeight' name='paper-height'>
	</li>
	<li class="control">
		<label for="speed">Speed</label>
		<input type="range" v-on:input="draw" id="speed" v-model='speed' min='.1' max='20' step='.1' name='speed'>
	</li>
	<li class="control">
		<label for="sliceHeight">Slice Height</label>
		<input type="number" v-on:input="draw" id="sliceHeight" v-model='sliceHeight'name='sliceHeight'>
	</li>
	<li class="control">
		<label for="multiplier">Point Multiplier</label>
		<input type="range" v-on:input="draw" id="multiplier" v-model='multiplier' min='1' max='25' step='1' name='sliceHeight'>
	</li>
	<li class="control">
		<h2>Rendering Mode</h2>
		<div class="radio">
		<label for="renderMode-canvas">Bitmap</label>
		<input type="radio" value='canvas' v-on:input="draw" id="renderMode-canvas" v-model='renderMode' name='renderMode'>
		<label for="renderMode-svg">Vector</label>
		<input type="radio" v-on:input="draw" id="renderMode-svg" v-model='renderMode' checked value='svg' name='renderMode'>
			</div>
	</li>
			<li class="control checkbox">
		<label for="reverse">Reverse Scale</label>
		<input type="checkbox" value='true' v-on:input="draw" id="reverse" v-model='reverseScale' name='reverseScale'>
	</li>
</ul>
</div>

              
            
!

CSS

              
                $fast: 250ms;
$sans: 'IBM Plex Sans', sans-serif;
$lightgray: rgb(230,230,230);

$track-w: 10em;
$track-h: 0.2em;
$thumb-d: 1em;
$track-c: lightgray;
$filll-c: red;

@mixin track($fill: 0) {
	box-sizing: border-box;
	border: none;
	width: $track-w;
	height: $track-h;
	background: $track-c;

	@if $fill == 1 {
		.js & {
			background: linear-gradient($filll-c, $filll-c) 0/ var(--sx) 100% no-repeat $track-c;
		}
	}
}

@mixin fill() {
	height: $track-h;
	background: white;
}

@mixin thumb() {
	box-sizing: border-box;
	border: none;
	width: $thumb-d;
	height: $thumb-d;
	border-radius: 50%;
	background: white;
	border: 1px solid black;
}

[type="range"] {
	&,
	&::-webkit-slider-thumb {
		-webkit-appearance: none;
	}

	--range: calc(var(--max) - var(--min));
	--ratio: calc((var(--val) - var(--min))/var(--range));
	--sx: calc(0.5*#{$thumb-d} + var(--ratio)*(100% - #{$thumb-d}));
	margin: 0;
	padding: 0;
	width: $track-w;
	height: $thumb-d;
	background: transparent;
	font: 1em/1 arial, sans-serif;

	&::-webkit-slider-runnable-track {
		@include track(1);
	}
	&::-moz-range-track {
		@include track;
	}
	&::-ms-track {
		@include track;
	}

	&::-moz-range-progress {
		@include fill;
	}
	&::-ms-fill-lower {
		@include fill;
	}

	&::-webkit-slider-thumb {
		margin-top: 0.5*($track-h - $thumb-d);
		@include thumb;
	}
	&::-moz-range-thumb {
		@include thumb;
	}
	&::-ms-thumb {
		margin-top: 0;
		@include thumb;
	}

	&::-ms-tooltip {
		display: none;
	}
}

body {
	padding: 1rem;
	font-family: $sans;
}

.app {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-evenly;
}

canvas {
//	display: none;
}

polyline {
	fill: none;
	stroke: black;
	stroke-width: .5px;
}

.list-leave-to {
	opacity: 0; 
	transform: scaleY(0);
}

.list-enter {
  opacity: 0;
  transform: translateX(30px);
}
.list-leave-active {
  position: absolute;
}

.row {
	padding: .5rem 0rem;
	display: flex;
	transition: transform $fast, opacity $fast * .7;
	transform-origin: top center;
	width: 100%;
	button {
		display: inline-block;
		margin-left: 1rem;
	}
}
.table-actions {
	transition: transform $fast, opacity $fast * .7;
	transform-origin: top center;
	padding: .5rem 0rem;
}

.controls {
	padding: 1rem;
	input, select {
		font-family: $sans;
		width: 100%;
		flex-basis: 100%;
		padding: .5rem;
		font-size: 1rem;
		flex-grow: 2;
		margin-right: .5em;
		display: inline-block;
	}
	.control {
		margin-bottom: 1rem;
	}
	label, h2 {
		display: block;
		margin-bottom: .5em;
	}
	.radio input {
		display: inline-block;
		width: auto;
	}
	.radio label {
		display: inline-block;
	}
}

.control {
	display: block;
	.checkbox {
		display: flex;
	}
}

button {
	appearance: none;
	background: $lightgray;
	border: 0;
	font-size: .9rem;
	padding: .5rem;
	display: inline-block;
	border-radius: 3px;
}
              
            
!

JS

              
                let config = {
	series: ["minor2", "major3"]
};
let c, snap;

const Series = function() {
	this.currentValue = "sin";
};
const addRow = function() {
	console.log("hi");
	let newRow = new Series();
	app.rows.push(newRow);
};

function init() {
	snap = Snap('svg');
	let el = document.getElementById("world");
	document.querySelector("#addRow").addEventListener("click", addRow);
	c = el.getContext("2d");
}

var app = new Vue({
	el: "#app",
	data: {
		intervals: {
			prime: 1,
			minor2: 1.067,
			major2: 1.125,
			minor3: 1.2,
			major3: 1.25,
			perfect4: 1.333,
			dim5: 1.414,
			perfect5: 1.5,
			minor6: 1.6,
			major6: 1.667,
			minor7: 1.778,
			major7: 1.875,
			octave: 2
		},
		paperWidth: 840,
		paperHeight: 1100,
		speed: 10,
		sliceHeight: 10,
		renderMode: 'svg',
		multiplier: 15,
		reverseScale: true,
		rows: [[{ interval: "perfect5" }]]
	},
	methods: {
		removeRow: function(index) {
			this.rows.splice(index, 1);
			this.draw();
		},
		clearSVG: function() {
			let elements = document.querySelectorAll("svg *");
			for (let i = 0; i < elements.length; i++) {
				elements[i].parentNode.removeChild(elements[i]);
			}
		},
		drawCanvas: function() {
			let series = this.rows;
			c.canvas.height = this.paperHeight;
			c.canvas.width = this.paperWidth;
			let width = this.paperWidth / series.length;
			let count = this.paperHeight / this.sliceHeight;
			for (let s = 0; s < series.length; s++) {
				let goingUp = true;
				let value = this.speed; // This can be used to adjust the 'speed'
				for (let i = 0; i < count; i++) {
					if (value > 255) {
						goingUp = false;
					} else if (value < this.speed) {
						goingUp = true;
					}
					if (goingUp) {
						value *= this.intervals[series[s].currentValue];
					} else {
						value /= this.intervals[series[s].currentValue];
					}
					c.fillStyle = "rgb(" + value + "," + value + "," + value + ")";
					c.fillRect(width * s, i * this.sliceHeight, width, this.sliceHeight);
				}
			}
		},
		drawSVG: function() {
			this.clearSVG();
			let c = snap;
			c.attr({
   			width: this.paperWidth,
				height: this.paperHeight
  			})
			let series = this.rows;
			let width = this.paperWidth / series.length;
			let count = this.paperHeight / this.sliceHeight;
			console.log(count)
			for (let s = 0; s < series.length; s++) {
				let goingUp = true;
				let value = this.speed; 
				for (let i = 0; i < count; i++) {
					if (value > 255) {
						if (this.reverseScale){
							goingUp = false;
						} else {
							value = 0;
						}
					} else if (value < this.speed) {
						goingUp = true;
					}
					if (goingUp || this.reverseScale === false) {
						value *= this.intervals[series[s].currentValue];
					} else {
						value /= this.intervals[series[s].currentValue];
					}
					//Let's generate the points
					let path = []
					let _value = value * this.multiplier;
					for (let j = 0; j < _value; j++){
						let x = (s * width) + (j * (width / _value));
						let y = i * this.sliceHeight;
						if (j % 2 == 0){ //even
							y += this.sliceHeight
						}
						path.push([x,y])
					}
					c.polyline(path)
				}
			}
		},
		draw: function() {
			this.drawCanvas();
			this.drawSVG();
		}
	}
});

document.addEventListener("DOMContentLoaded", function() {
	init();
});

              
            
!
999px

Console