about summary refs log tree commit diff
path: root/scripts/ccharter.js
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@gmail.com>2018-03-20 20:55:59 -0400
committerZach DeCook <zachdecook@gmail.com>2018-03-20 20:55:59 -0400
commit7f1d966165c912b9386eea97faa6434e036dab58 (patch)
tree53f97a086725a1e5258114cfb545c4808aafbf49 /scripts/ccharter.js
parentdffd1beac4f5fa588efd324924c9e55a22e7d57d (diff)
downloadccharter-c-7f1d966165c912b9386eea97faa6434e036dab58.tar.gz
* Allow variable number of frets (2 - n)
(Specified by the length of the chordFrets parameter)
Diffstat (limited to 'scripts/ccharter.js')
-rw-r--r--scripts/ccharter.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/scripts/ccharter.js b/scripts/ccharter.js
index 353c081..fdd895e 100644
--- a/scripts/ccharter.js
+++ b/scripts/ccharter.js
@@ -6,7 +6,9 @@ var ChordCharter = {
 			name: chordName,
 			frets: chordFrets
 		};
-	
+
+		fretsCount = chord.frets.length;
+
 		var c=document.getElementById(canvasId);
 		var ctx=c.getContext("2d");
 		ctx.fillStyle="#000";
@@ -26,10 +28,9 @@ var ChordCharter = {
 		}
 	
 		// verts
-	
-		for (counter in new Array(0, 1, 2, 3, 4, 5)) {
-			ctx.moveTo(origin.x + (counter * props.width / 5), origin.y);
-			ctx.lineTo(origin.x + (counter * props.width / 5), origin.y + props.height);
+		for ( i = 0; i < fretsCount; i++ ) {
+			ctx.moveTo(origin.x + (i * props.width / (fretsCount - 1)), origin.y);
+			ctx.lineTo(origin.x + (i * props.width / (fretsCount - 1)), origin.y + props.height);
 			ctx.stroke();
 		}
 	
@@ -73,7 +74,7 @@ var ChordCharter = {
 		for (j=0; j < chord.frets.length; j++) {
 	
 			ctx.alignText = "left";
-			ctx.fillText(chord.frets.charAt(j), origin.x + (i * props.width / 5), origin.y + props.height + 12);
+			ctx.fillText(chord.frets.charAt(j), origin.x + (i * props.width / (fretsCount - 1)), origin.y + props.height + 12);
 	
 			if (chord.frets.charAt(j) == 0) {
 	
@@ -82,7 +83,7 @@ var ChordCharter = {
 	
 			} else {
 				ctx.beginPath();
-				ctx.arc(origin.x + (i * props.width / 5), origin.y - 7.5 + (15 * (chord.frets.charAt(j) - baseFret)), dotsize, 0, Math.PI*2,true);
+				ctx.arc(origin.x + (i * props.width / (fretsCount -1)), origin.y - 7.5 + (15 * (chord.frets.charAt(j) - baseFret)), dotsize, 0, Math.PI*2,true);
 				ctx.closePath();
 				ctx.fill();
 			}