Creating an HTML5 page using canvas and javascript to draw a set number of musical staves on the page, spaced a pre-determined amount in between.
What I have is re-drawn on top of the canvas 10 times, and what I really need is something that's spaced out apart every time the loop is drawn.
I tried to create a JSFiddle, but it doesn't draw anything (which I'm sure is user-error), so here's the js file:
window.onload = function(){
var canvas = document.getElementById('sheetmusic');
c = canvas.getContext('2d');
c.fillStyle = 'white';
c.fillRect(0,0, canvas.width, canvas.height);
// Draw staves
for (var i=0; i<10; i++){
c.strokeStyle = 'black';
c.beginPath();
c.moveTo(0,10);
c.lineTo(canvas.width,10);
c.stroke();
c.moveTo(0,20);
c.lineTo(canvas.width,20);
c.stroke();
c.moveTo(0,30);
c.lineTo(canvas.width,30);
c.stroke();
c.moveTo(0,40);
c.lineTo(canvas.width,40);
c.stroke();
c.moveTo(0,50);
c.lineTo(canvas.width,50);
c.stroke();
// staff whitespace
c.fillStyle = 'white';
c.fillRect(0,52, canvas.width, 50);
}
};
I'm just not certain how to append i
from my loop
into the height
attribute of my stroke
.