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

              
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/p5.js"></script>
<script src=https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/p5.dom.js></script>

<script src= "https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/Tone.min.js"></script>

<script src=https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/draggabilly.js></script>

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/StartAudioContext.js"></script>

<script src=https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/Interface.js></script>

<script type="text/javascript" src="https://tonejs.github.io/Logo/build/Logo.js"></script>

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/255459/qwerty-hancock.js"></script>



	<style type="text/css">

	</style>
	<div id="Content">
		<!-- <div id="Title">MonoSynth</div>
		<div id="Explanation">
			<a href="https://tonejs.github.io/docs/#MonoSynth">Tone.MonoSynth</a> 
			is composed of one oscillator, one filter, and two envelopes.
	 		Both envelopes are triggered simultaneously when a note is triggered. 
	 	   	<img src="https://docs.google.com/drawings/d/1gaY1DF9_Hzkodqf8JI1Cg2VZfwSElpFQfI94IQwad38/pub?w=924&h=240"> -->
		</div>
		<div id="Keyboard"></div>
	</div>





              
            
!

CSS

              
                /* FOR MOBILES */
@media (max-width: 400px) {
  #TopBar #Homepage a {
    font-size: 16px !important; }

  #Content {

    font-size: 10px !important;
    max-width: calc(100% - 6px) !important; }

  #Content * {
    font-size: 14px !important; } }
html, body {
  padding: 0px;
  margin-right: 20px;
  height: calc(100% - 4px); }

/**
 *  
 *  TOP BAR
 *  
 */

#MobileStart {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 10000;
  top: 0px;
  left: 0px;
  background-color: rgba(0, 0, 0, 0.8); }
  #MobileStart #Button {
    position: absolute;
    left: 50%;
    top: 50%;
    background-color: #7F33ED;
    color: white;
    font-family: monospace;
    border-radius: 3px;
    margin-top: -40px;
    margin-left: -40px;
    width: 80px;
    height: 80px;
    text-align: center;
    line-height: 80px; }
  #MobileStart #Button:hover {
    background-color: #7F33ED;
    color: white; }
  #MobileStart #Button:hover:active {
    background-color: #ED33CF;
    color: #22DBC0; }

#Content {
  font-family: monospace;
  position: absolute;
  left: 3px;
  width: calc(100% - 6px);
  margin-bottom: 15px; }
  #Content #Title {
    height: 23px;
    line-height: 23px;
    font-size: 1.2em;
    color: white;
    width: calc(100% - 15px);
    padding-left: 15px;
    background-color: black; }
  #Content #Explanation {
    position: relative;
    font-family: monospace;
    padding: 15px;
    color: black;
    font-size: 14px;
    box-sizing: border-box;
    border: 3px solid black;
    border-top-width: 0px;
    width: 100%; }
    #Content #Explanation img {
      width: 80%;
      max-width: 700px;
      margin-left: auto;
      margin-right: auto;
      display: block; }
  #Content a {
    color: black;
    font-family: monospace;
    font-size: 14px;
    font-weight: bold;
    text-decoration: none; }
  #Content a:hover {
    color: #1EDF3E; }
  #Content a:hover:active {
    color: #ED33CF; }
  #Content #DragContainer {
    margin-left: 3px;
    margin-top: 3px;
    margin-bottom: 15px;
    width: calc(100% - 3px);
    height: 400px;
    position: relative;
    color: white; }
  #Content .Slider.x {
    position: relative;
    height: 94px;
    width: 100%;
    margin-top: 3px; }
    #Content .Slider.x .Axis {
      top: 50%;
      margin-top: -1.5px; }
  #Content .Slider.y {
    position: relative;
    width: 94px;
    height: 400px; }
    #Content .Slider.y .Axis {
      left: 50%;
      margin-left: -1.5px; }
  #Content .Dragger {
    width: 90px;
    height: 90px;
    position: absolute;
    background-color: black;
    border-radius: 50%;
    z-index: 1;
    margin-top: -2px;
    border: 2px solid white;
    cursor: -webkit-grab; }
    #Content .Dragger #Name {
      width: 100%;
      height: 100%;
      position: relative;
      text-align: center;
      font-size: 12px;
      font-family: monospace;
      line-height: 90px;
      color: white; }
  #Content .Dragger:hover {
    background-color: #3833ED;
    color: white; }
  #Content .Dragger.is-pointer-down {
    cursor: -webkit-grabbing;
    background-color: #ED33CF; }
    #Content .Dragger.is-pointer-down #Name {
      color: #1EDF3E; }
  #Content .Axis {
    position: absolute;
    background-color: black;
    width: 3px;
    height: 3px;
    top: 3px;
    left: 3px;
    border-radius: 1.5px;
    z-index: 0; }
  #Content #xAxis {
    width: calc(100% - 6px); }
  #Content #yAxis {
    height: calc(100% - 6px); }
  #Content .Button {
    width: 100%;
    margin-top: 3px;
    height: 90px;
    background-color: black;
    line-height: 90px;
    color: white;
    border-radius: 10px;
    text-align: center;
    cursor: pointer; }
  #Content .Button:hover {
    color: white;
    background-color: #3833ED; }
  #Content .Button:hover:active, #Content #Content .Button:hover:active.Active {
    color: #22DBC0;
    background-color: #ED33CF; }
  #Content .Button.Toggle.Active {
    box-sizing: border-box;
    border: 3px solid black;
    line-height: 84px;
    color: black;
    background-color: white; }
  #Content .Transport {
    width: 100%;
    height: 30px;
    background-color: black;
    line-height: 30px;
    color: white;
    border-radius: 10px;
    margin-top: 3px;
    position: relative; }
    #Content .Transport #Position {
      width: 70px;
      left: 50%;
      margin-left: -35px;
      text-align: left;
      height: 100%;
      position: absolute;
      color: white; }

#Keyboard {
top: 60%;
  width: 95%;
position:absolute;
/*   z-index:1; */
  margin: 3px !important; }

code {
  background-color: #ECECEC;
  color: #333;
  padding: 1px; }

#Loading {
  font-family: monospace;
  z-index: 100000;
  position: absolute;
  background-color: rgba(140, 140, 140, 0.5);
  width: 100%;
  height: calc(100% - 37.5px);
  top: 37.5px;
  left: 0px;
  opacity: 1;
  -webkit-transition: opacity 0.4s;
          transition: opacity 0.4s; }
  #Loading #Text {
    color: white;
    position: absolute;
    text-align: center;
    top: 50%;
    left: 50%;
    width: 300px;
    margin-left: -150px;
    height: 60px;
    margin-top: -30px;
    line-height: 60px;
    font-size: 42px; }

#Loading.Loaded {
  pointer-events: none;
  opacity: 0; }

              
            
!

JS

              
                var distances = [];
var maxDistance;
var spacer;	
var synth;
		var keyboard;
var bassPart;
var c;
function preload(){
	synth = new Tone.MonoSynth({
			"portamento" : 0.01,
			"oscillator" : {
				"type" : "square"
			},
			"envelope" : {
				"attack" : 0.005,
				"decay" : 0.2,
				"sustain" : 0.4,
				"release" : 1.4,
			},
			"filterEnvelope" : {
				"attack" : 0.005,
				"decay" : 0.1,
				"sustain" : 0.05,
				"release" : 0.8,
				"baseFrequency" : 300,
				"octaves" : 4
			}
		}).toMaster();
		// .toMaster();

		 bassPart = new Tone.Sequence(function(time, note){
			synth.triggerAttackRelease(note, "16n", time);
		}, ["C2", ["C3", ["C3", "B2"]], "E2", ["G2", "C1"]]).start(0);
		// "0", ["12", ["12", "11"]], "4", ["7", "-12"]].start(0);

		// C2+12 =  

		// bassPart.probability = 0.7;

		//set the transport 
		Tone.Transport.bpm.value = 90;
  
			keyboard = new QwertyHancock({
				id: "Keyboard",
				width: $("#Content").width()-50,
				height: 150,
				octaves: Interface.isMobile ? 1.26 : 3,
				startNote: "C3",
				whiteKeyColour: "white",
				blackKeyColour: "#2D885E",
				activeColour : "#FFFC65"
			});

			keyboard.keyDown = function (note, frequency) {
			    	
      synth.triggerAttack(frequency);
			Tone.Transport.start();
        // drawCircle(width/2, 36, 6);
			    
			    // noLoop();
			};

			keyboard.keyUp = function () {
				Tone.Transport.stop();
			    synth.triggerRelease();
         // loop();
			};
}

function setup() {
	c = createCanvas(windowWidth, windowHeight-200, WEBGL);
	c.position(0,0);
  noStroke();
  // noLoop();
}
function draw() {
	background(45, 136, 94);

	// Orange point light on the right
	pointLight(150, 100, 0, 500, 0, 200);

	// Blue directional light from the left
	directionalLight(0, 102, 255, -1, 0, 0);

	// Yellow spotlight from the front
	pointLight(255, 255, 109, 0, 0, 300);

	rotateY(map(mouseX, 0, width, 0, PI));
	rotateX(map(mouseY, 0, height, 0, PI));
	box(200);


			
}

function drawCircle(x, radius, level) {                    
  var tt = 126 * level/4.0;
  fill(tt);
  ellipse(x, height/2, radius*2, radius*2);      
  if(level > 1) {
    level = level - 1;
    drawCircle(x - radius/2, radius/2, level);
    drawCircle(x + radius/2, radius/2, level);
  }
}
              
            
!
999px

Console