Now if I replace the lines :
for(i = 25;i<1000;i*=2){
pen.DrawStar(i,ctx);
}
To this:
pen.DrawStar(25,ctx);
pen.DrawStar(50,ctx);
pen.DrawStar(100,ctx);
pen.DrawStar(200,ctx);
pen.DrawStar(400,ctx);
pen.DrawStar(800,ctx);
I get the desired output (as opposed to a broken page), although as I understand it the 2 snippets are functionally identical...
So here's the rest of the code the code. I have a pretty simple hello world js program that draws a doodle and an html file which references it.
the Java script is here:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var pen = {
DrawStar : function (size,ctx){
ctx.lineWidth = 1;
ctx.fillStyle = "black";
for (i = 0; i < size/2; i+=10) {
ctx.moveTo(size/2,i);
ctx.lineTo(size/2-i,size/2);
ctx.stroke();
}
for (i = 0; i < size/2; i+=10) {
ctx.moveTo(size-i,size/2);
ctx.lineTo(size/2,size/2-i);
ctx.stroke();
}
for (i = 0; i < size/2; i+=10) {
ctx.moveTo(i,size/2);
ctx.lineTo(size/2,size/2+i);
ctx.stroke();
}
for (i = 0; i < size/2; i+=10) {
ctx.moveTo(size/2,size-i);
ctx.lineTo(size/2+i,size/2);
ctx.stroke();
}
}
}
for(i = 25;i<1000;i*=2){ // This is the loops that seems to cause problems..
pen.DrawStar(i,ctx);
}
ctx.font = "30px Arial";
ctx.fillText("Hello, World!",477,30);
I also tried with a while loop and seemed to get hung up in the same way.
here is the html:
<!DOCTYPE html>
<html>
<head>
<h1>This is some JavaScript</h1>
</head>
<body>
<link rel='stylesheet' type='text/css' href='stylesheet.css'/>
<canvas id='myCanvas' width='800' height='800'>
Displayed if your browser does not support HTML5 Canvas.
</canvas>
<script type='text/javascript' src="first.js"></script>
</body>
</html>
and the real long read, my style sheet...
canvas {
border: 1px dotted black;
}