JavaScript 数値演算 新しいページはコチラ
提供: yonewiki
738行: | 738行: | ||
/* 円を描く */ | /* 円を描く */ | ||
function draw3() { | function draw3() { | ||
+ | var canvas = document.getElementById('c3'); | ||
+ | if ((! canvas) || (! canvas.getContext) ) { return false; } | ||
+ | var ctx = canvas.getContext('2d'); | ||
+ | ctx.beginPath(); | ||
+ | ctx.moveTo(200, 0); | ||
+ | ctx.lineTo(200, 400); | ||
+ | ctx.stroke(); | ||
+ | |||
+ | /* | ||
+ | ctx.beginPath(); | ||
+ | ctx.strokeText("sin x", 130 + 65, 70 - 60 * Math.sin(0) - 30); | ||
+ | |||
+ | ctx.moveTo(130, 70 - 60 * Math.sin(0)); | ||
+ | for (var i = 1; i <= 480; i += 1) { | ||
+ | ctx.lineTo(i + 130, 70 - 60 * Math.sin( Math.PI * i / 60)); | ||
+ | } | ||
+ | ctx.stroke(); | ||
+ | |||
+ | ctx.beginPath(); | ||
+ | ctx.moveTo(55 + 130, 70 - 60 * Math.sin(Math.PI * 55 / 60)); | ||
+ | ctx.lineTo(130 + 63, 70 - 60 * Math.sin(0) - 32); | ||
+ | ctx.stroke(); | ||
+ | |||
+ | |||
+ | ctx.beginPath(); | ||
+ | ctx.strokeStyle = 'rgb(192, 80, 77)'; | ||
+ | |||
+ | ctx.moveTo(130, 70 - 60 * Math.cos(0)); | ||
+ | ctx.strokeText("cos x", 130 + 50, 70 - 60 * Math.cos(0) + 10); | ||
+ | |||
+ | for (var i = 1; i <= 480; i += 1) { | ||
+ | ctx.lineTo(i + 130, 70 - 60 * Math.cos( Math.PI * i / 60)); | ||
+ | } | ||
+ | ctx.stroke(); | ||
+ | |||
+ | ctx.beginPath(); | ||
+ | ctx.strokeStyle = 'rgb(192, 80, 77)'; | ||
+ | ctx.moveTo(20 + 130, 70 - 60 * Math.cos(Math.PI * 20 / 60)); | ||
+ | ctx.lineTo(130 + 48, 70 - 60 * Math.cos(0) + 8 ); | ||
+ | ctx.stroke(); | ||
+ | */ | ||
+ | |||
} | } | ||
</yjavascript> | </yjavascript> | ||
+ | |||
+ | |||
+ | <ycanvas id="c3" width="1098" height="400"></ycanvas> | ||
=== 乱数 random === | === 乱数 random === | ||