Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play songs #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 118 additions & 1 deletion screentunes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,102 @@
var start = null;
var t = null;

var tones = {
REST: 0,
GbelowC: 196,
A: 220,
Asharp: 233,
B: 247,
C: 262,
Csharp: 277,
D: 294,
Dsharp: 311,
E: 330,
F: 349,
Fsharp: 370,
G: 392,
Gsharp: 415
};

var whole = 1000;

var durations = {
whole: whole,
half: whole / 2,
quarter: whole / 4,
eighth: whole / 8,
sixteenth: whole / 16
};

var songs = {
mary: [
[tones.E, durations.quarter],
[tones.D, durations.quarter],
[tones.C, durations.quarter],
[tones.D, durations.quarter],
[tones.E, durations.quarter],
[tones.E, durations.quarter],
[tones.E, durations.half],
[tones.D, durations.quarter],
[tones.D, durations.quarter],
[tones.D, durations.half],
[tones.E, durations.quarter],
[tones.G, durations.quarter],
[tones.G, durations.half],
[tones.E, durations.quarter],
[tones.D, durations.quarter],
[tones.C, durations.quarter],
[tones.D, durations.quarter],
[tones.E, durations.quarter],
[tones.E, durations.quarter],
[tones.E, durations.quarter],
[tones.E, durations.quarter],
[tones.D, durations.quarter],
[tones.D, durations.quarter],
[tones.E, durations.quarter],
[tones.D, durations.quarter],
[tones.C, durations.whole]
],
scale: [
[tones.A, durations.quarter],
[tones.B, durations.quarter],
[tones.C, durations.quarter],
[tones.D, durations.quarter],
[tones.E, durations.quarter],
[tones.F, durations.quarter],
[tones.G, durations.quarter]
],
nyan: [
// measure 1
[tones.Fsharp, durations.eighth],
[tones.Gsharp, durations.eighth],
[tones.D, durations.sixteenth],
[tones.Dsharp, durations.eighth],
[tones.Csharp, durations.sixteenth],
[tones.D, durations.sixteenth],
[tones.Csharp, durations.sixteenth],
[tones.B, durations.eighth],
[tones.B, durations.eighth],
[tones.Csharp, durations.eighth],
// measure 2
[tones.D, durations.eighth],
[tones.D, durations.sixteenth],
[tones.Csharp, durations.sixteenth],
[tones.B, durations.sixteenth],
[tones.Csharp, durations.sixteenth],
[tones.Dsharp, durations.sixteenth],
[tones.Fsharp, durations.sixteenth],
[tones.Gsharp, durations.sixteenth],
[tones.Dsharp, durations.sixteenth],
[tones.Fsharp, durations.sixteenth],
[tones.Csharp, durations.sixteenth],
[tones.Dsharp, durations.sixteenth],
[tones.B, durations.sixteenth],
[tones.Csharp, durations.sixteenth],
[tones.B, durations.sixteenth]
]
};

var AnimationFrame = (function() {
var FPS = 16.6666666667; // 1000 / 60 = Frames Per Second
var RAF = window.requestAnimationFrame
Expand Down Expand Up @@ -50,9 +146,30 @@
}
}

var incrTime = 0;
var noteCount = 0;
var song = songs.nyan;
var play = true;
function render() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
var magic = 5 + (Math.sin(t / 2000)+1)*7;

if (!play) {return;}

var lastNote = song[noteCount];
if (t/2 - incrTime > lastNote[1]) {
incrTime += lastNote[1];
noteCount++;
if (noteCount == song.length) {
play = false;
return;
}
}

var note = song[noteCount];
var magic = -note[0] * .105 + 60;

//var magic = 5 + (Math.sin(t / 2000)+1)*7;

bars(magic, magic);
}

Expand Down