このスクリプトは正しく表示されません。何か問題がありますか?
これには、ブラウザの表示に行がありません。for ループを使用して 2 次元直交座標系を作成していますが、コードに問題があるかどうかを知りたいです。
<html>
<head>
<script type="text/javascript">
function start() {
var winwidth = window.innerWidth;
var winheight = window.innerHeight;
var canvas=document.getElementById("myCanvas");
var ctx=canvas.getContext("2d");
// Sets size of canvas and interior of canvas to window
ctx.canvas.width = 1200;
ctx.canvas.height = 600;
var cname = "ctx";
// -------------------------------------------
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = '#ff0000';
// Origin Y-Axis
ctx.moveTo(0,300);
ctx.lineTo(1200,300);
// Origin X-Axis
ctx.moveTo(600,0);
ctx.lineTo(600,600);
ctx.stroke();
// -------------------------------------------
// -------------------------------------------
ctx.beginPath();
ctx.lineWidth = 0.5;
ctx.strokeStyle = '#0000ff';
majoraxes = new Array();
j=0;
// Horizontal Major Axes
for (hundreth=0; hundreth<7; hundreth++) {
// Skips past 300
if (hundreth==3) {
hundreth=4;
}
for (c=0; c<2; c++) {
if (c==0) {
majoraxes[j] = cname+".moveTo(0,"+hundreth+"00);";
j = j+1;
}
if (c==1) {
majoraxes[j] = cname+".lineTo(1200,"+hundreth+"00);";
j = j+1;
}
}
}
// Vertical Major Axes
for (hundreth=0; hundreth<13; hundreth++) {
// Skips past 600
if (hundreth==6) {
hundreth=7;
}
for (c=0; c<2; c++) {
if (c==0) {
majoraxes[j] = cname+".moveTo("+hundreth+"00,0);";
j = j+1;
}
if (c==1) {
majoraxes[j] = cname+".lineTo("+hundreth+"00,600);";
j = j+1;
}
}
}
for (t=0; t < majoraxes.length; t++) {
eval(majoraxes[t]);
}
ctx.stroke();
// ---------------------------------------
// ---------------------------------------
ctx.beginPath();
ctx.lineWidth = .2;
ctx.strokeStyle = '#0000ff';
minoraxes = new Array();
j=0;
// Horizontal Minor Axes
for (hundreth=0; hundreth<7; hundreth++) {
for (tenth=1; tenth<10; tenth++) {
for (c=0; c<2; c++) {
if (c==0) {
minoraxes[j] = cname+".moveTo(0,"+hundreth+""+tenth+"0);";
j = j+1;
}
if (c==1) {
minoraxes[j] = cname+".lineTo(1200,"+hundreth+""+tenth+"0);";
j = j+1;
}
}
}
}
// Vertical Minor Axes
for (hundreth=0; hundreth<13; hundreth++) {
for (tenth=1; tenth<10; tenth++) {
for (c=0; c<2; c++) {
if (c==0) {
minoraxes[j] = cname+".moveTo("+hundreth+""+tenth+"0,0);";
j = j+1;
}
if (c==1) {
minoraxes[j] = cname+".lineTo("+hundreth+""+tenth+"0,600);";
j = j+1;
}
}
}
}
for (t=0; t < minoraxes.length; t++) {
eval(minoraxes[t]);
}
ctx.stroke();
// --------------------------------------
}
</script>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0px;
}
#myCanvas {
width:1200;
height:600;
image-rendering:optimize-contrast;
}
</style>
</head>
<body onload="start()">
<canvas id="myCanvas" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
</body>
</html>