-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
84 lines (69 loc) · 1.92 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const gridColor = "black";
const bigAccentColor = "red";
const tripletColor = "blue";
const quintColor = "gray";
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.fillStyle = bigAccentColor;
const wholeWidth = 1000;
const noteWidth = 15;
const height = 15;
const padding = 10;
const numBeats = 8;
const spacing = 2;
// 4 over 5 polyrhythm
let numNotes = (4 / 5) * numBeats;
draw(0, numNotes);
// Quarters
ctx.fillStyle = gridColor;
draw(1, numBeats)
ctx.fillStyle = bigAccentColor;
// 4 over 3 polyrhythm
numNotes = (4 / 3) * numBeats;
draw(2, numNotes);
// 1/2 triplets (3 over 2 polyrhythm)
numNotes = (3 / 2) * numBeats;
ctx.fillStyle = tripletColor;
draw(3, numNotes)
ctx.fillStyle = bigAccentColor;
// half notes
numNotes = (4 / 2) * numBeats;
ctx.fillStyle = gridColor;
draw(4, numNotes)
ctx.fillStyle = bigAccentColor;
// 5 over 2 polyrhythm
numNotes = (5 / 2) * numBeats;
ctx.fillStyle = quintColor;
draw(5, numNotes);
ctx.fillStyle = bigAccentColor;
// quarter note triplets
numNotes = (6 / 2) * numBeats;
ctx.fillStyle = tripletColor;
draw(6, numNotes);
ctx.fillStyle = bigAccentColor;
// sixteenths
numNotes = (8 / 2) * numBeats;
ctx.fillStyle = gridColor;
draw(7, numNotes);
// quintuplets
numNotes = (10 / 2) * numBeats;
ctx.fillStyle = quintColor;
draw(8, numNotes);
// 8th note triplets
numNotes = (12 / 2) * numBeats;
ctx.fillStyle = tripletColor;
draw(9, numNotes);
ctx.fillStyle = gridColor;
numNotes = (16 / 2) * numBeats;
// 32nd notes
draw(10, numNotes);
function draw(row, numNotes, tick = false){
console.log(numNotes);
for(i = 0; i <= numNotes; i++){
const distanceBetweenNotes = wholeWidth / numNotes;
const x = i * distanceBetweenNotes;
const y = row * height;
ctx.fillRect(padding + x, tick ? + (padding + y + height/2) : (padding + y), tick ? noteWidth/2 : noteWidth - spacing, tick ? height/2 : height - spacing);
ctx.stroke();
}
}