Here is the code I have.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>
function draw()
{
var diagCanvas = document.getElementById("diag-cnvs");
diagCanvas.height=window.innerHeight;
diagCanvas.width=window.innerWidth;
if (diagCanvas.getContext)
{
var ctx = diagCanvas.getContext("2d");
var h = w = 100;
var color1 = 'rgba(255,0,0,1)';
var color2 = 'rgba(255,0,0,.2)';
var x = y = 0;
while(y<diagCanvas.height)
{
while(x<diagCanvas.width)
{
ctx.fillStyle = color2;
ctx.fillRect( x, y, w, h);
ctx.fillStyle = color1;
ctx.lineTo( x, y);
ctx.lineTo( x+w/2, y);
ctx.lineTo( x, y+h/2);
ctx.lineTo( x, y);
ctx.moveTo( x+w, y);
ctx.lineTo( x+w, y+h/2);
ctx.lineTo( x+w/2, y+h);
ctx.lineTo( x, y+h);
ctx.fill();
ctx.closePath();
x+=w;
}
y+=h;
x=0;
}
}
}
$(function() {
draw();
})
</script>
<style>
canvas {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<canvas height="100" width="100" id="diag-cnvs"></canvas>
</body>
</html>
I would like the height and width dimensions to be the same for the shape of the canvas, but it would be great if this completely fills the browser 100% or basically repeats endlessly, like the CSS value for the background image to repeat on the x and y axis.
In the end, I would like to add two or three colors to the stripes, but I only vaguely understand what is happening in this code, since I'm new to it.
source
share