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.

            
              // Work in progress!
// TODO:
// - support for scales
// - support for detuning
// - support for arbitrary number of strings
// - make it playable!

- strings = 6
- frets   = 21
- octave  = 3 // starting octave

- tones   = ['e','f','f#', 'g', 'g#', 'a', 'a#', 'b', 'c', 'c#', 'd', 'd#']
- tuning  = ['e', 'b', 'g', 'd', 'a', 'e', 'b', 'f#', 'c#', 'g#', 'd#', 'a#'] // tuning of the guitar, starting from top to buttom strings
- count   = tones.length - 1

// temp; will refactor
- tune = { 'e': 0, 'f': 1, 'f#': 2, 'g': 3, 'g#': 4,'a': 5, 'a#': 6, 'b': 7, 'c': 8, 'c#': 9, 'd': 10, 'd#': 11 }

.wrap
  h1 Guitar scale thing!
  p Guitar scale finder thing. Work in progress!
  
  .string.top
    select.scale

    select.key
       each tone in tones
         option(value=tone)=tone


  .guitar
    .string.top
      .controls
      .frets
        - for (var fret = 0; fret < frets; fret++)
          .fret= fret

    // loop through strings
    - for (var string = 0; string < strings; string++)
      .string

        // get base tone
        - t = tune[tuning[string]]

        // controls
        .controls= tuning[string]

        // loop through frets
        .frets
          - c = 0

          - for (var fret = 0; fret < frets; fret++)
            - l = c + t // current tuning of fret of the current string

            // output the fret
            .fret(class=' tone-' + l)=tones[l]

            // increment tone
            - ++c
            - ++l

            // reset tone if needed (ie. next octave)
            - if(l > count) 
              - c = 0
              - l = 0
              - t = 0
              - ++ octave
            
          
!
            
              body 
  background #212121
  font 122% Helvetica, arial, sans-serif
  
.wrap
  width: 100%
  min-height: 100vh
  display flex
  align-items center
  justify-content center
  flex-direction: column
  
.guitar
  width 100%
  max-width auto
  display flex
  flex-direction column
  background #f9f9f9
  max-width: 1300px
  
.string
  // border 1px solid #ccc
  flex-basis 100%
  display flex
  
.controls
  font-weight bold
  flex-basis 80px
  text-align center
  text-transform uppercase
  
.frets
  display flex
  flex 1 1 auto
  align-items center
  justify-content center
  text-transform uppercase
  
.fret
  flex 20px
  border 1px solid #333
  text-align center

.top.frets.fret
  border: 1px solid #ddd
  
.top .fret:nth-child(2n+3) 
  background #ebebeb

.fret, .controls
  padding .25em
  
.top, .top div
  font-size 88%
  
select
  max-width 105px
  
.key option
  text-transform uppercase
  
// iteration
for row in 0..11
	.tone-{row}
		background spin(#33f, (row * (360/12))deg)
  
// helpers
.checked 
  background #444
  color #fff
  
  &:hover
    background red
    content wat
    
  &:after
    content wut
    width 40px
    height 40px
    border 1px solid red
    background red

.hover
  background blue 
    
.main
  background #000
  
.fret
  transition background 400ms ease-out
  

h1, p
  color: white

            
          
!
            
              // scales are defined in intervals (in semitones) from the last tone in the scale. 
// TODO: fix incorrect scales
var scales = {
  minor:            [2,1,2,2,1,2],
  major:            [2,2,1,2,2,2],
  pentatonic:       [3,2,2,3,2,2],
  blues:            [3,2,1,1,3,2], 
  diminished:       [3],
  test:             [2],
  weird:            [4],
  arabian:          [2,1,2,1,2,2,15], // !
  persian:          [1,3,1,1,2,2],
  japanese:         [1,4,2,1],
  locrian:          [1,2,2,1,2,2,2], // !
  pentat_major:     [2,2,3,2,3],
  gypsy:            [1,3,1,2,1,3],
  lydian:           [2, 2, 2, 1, 2], 
  phrygian:         [1,3,1,2,1,3,4], // !
  byzantine:        [1,3,1,2,1,2], // !
  x:                [2,1,3,1,2,1,2], // !
  chromatic:        [1], // all tones
};

var tones = ['e','f','f#','g','g#','a','a#','b','c','c#','d','d#'];
var keys = Object.keys(tones);
var diff;
console.log('keys > ' + keys);

function getScale(scale, key) {
  var outNotes = [0], c = 0, o = 11; 
  getDiff(key);
  
  console.log('Diff is: ' + diff);
  
  while(c < o) {
    for (var x in scales[scale]) {
      c += scales[scale][x];
      outNotes.push(c);
    }
   }
  
  
  var secondNotes = [];
  
  for (var x in outNotes) {
    let c = outNotes[x];
    if(c > 11) c = c - 12;
    secondNotes.push(c + diff);
  }
  
  
  console.log('Outnotes: ');
  console.log(outNotes);
  console.log(secondNotes);
  // return outNotes;
  return secondNotes;
}

function getDiff(key) {
   // return 0; // kakke
  
  diff = 0;
  return true;
  for(var i = 0; i < tones.length; ++i) {
     if(tones[i] == key) {
       return diff;
     }
    
    ++diff; 
  }
  
  return diff; 
}

function setScale(scale, key) {
  $('.fret').removeClass('checked main');
  getScale(scale, key).forEach(markTone);
  $('.tone-' + (0 + diff)).addClass('main');  // ! extra 
}

function markTone(tone) {
  $('.tone-' + tone).addClass('checked');
}

$('.scale, .key').change(function() {
  setScale($('.scale').val(), $('.key').val()); 
});

// set scales
(function init() {
  var output = [], s;
  
  $.each(scales, function(scale) {
    output.push('<option value="' + scale + '">' + scale + '</option>');
    s = scale;
  });

  $('select.scale').html(output.join('')).val(s);

  setScale('blues', 'a'); // set initial scale

})();

            
          
!
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