master
Matt Huntington 5 years ago
parent 788e755657
commit 916038fd50

@ -10,21 +10,22 @@ renderer.resize(1200, 1200);
// And get a drawing context: // And get a drawing context:
const context = renderer.getContext(); const context = renderer.getContext();
const randomNote = () => { const randomArrayElement = (array) => {
const pitches = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; const randomIndex = Math.floor(Math.random()*array.length);
const randomPitchIndex = Math.floor(Math.random()*pitches.length); return array[randomIndex];
const pitch = pitches[randomPitchIndex];
}
const octaves = ['4', '5']; const randomNote = () => {
const randomOctaveIndex = Math.floor(Math.random()*octaves.length); const pitch = randomArrayElement(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
const octave = octaves[randomOctaveIndex]; const octave = randomArrayElement(['4', '5']);
return `${pitch}/${octave}`; return `${pitch}/${octave}`;
} }
const returnNewNote = () => { const returnNewNote = () => {
const newNote = new VF.StaveNote({clef: "treble", keys: [randomNote()], duration: "8" }) const newNote = new VF.StaveNote({clef: "treble", keys: [randomNote()], duration: "8" })
if(Math.random() > 0.5){ if(Math.random() > 0.6){
const accidentals = ['b', '#'] const accidentals = ['b', '#']
const randomAccidentalIndex = Math.floor(Math.random()*accidentals.length); const randomAccidentalIndex = Math.floor(Math.random()*accidentals.length);
const accidental = accidentals[randomAccidentalIndex]; const accidental = accidentals[randomAccidentalIndex];

Loading…
Cancel
Save