我决定要踏上元素,我可以说到目前为止它已经是噩梦让它工作。我只想绘制正弦图。所以在阅读好后,我仍然不能得到出处,也不能得到它的阴谋。下面是我试过的(我第一次用这个标签,所以原谅我的无知)。我想知道的是the guy here有它,但对于像我这样的初学者来说代码很难理解。使用HTML5画布绘图
HTML
<!DOCTYPE html>
<html>
<head>
<title>Graphing</title>
<link type="text/css" rel="Stylesheet" href="graph.css" />
<script type="text/JavaScript" src="graph.js" ></script>
</head>
<body>
<canvas id="surface">Canvas not Supported</canvas>
</body>
</html>
CSS
#surface
{
width:300;
height:225;
border: dotted #FF0000 1px;
}
JavScript
window.onload = function()
{
var canvas = document.getElementById("surface");
var context = canvas.getContext("2d");
arr = [0,15, 30,45,60, 90,105, 120, 135, 150, 165, 180 ];
var x=0;
var y = 0;
for(i=0; i<arr.length; i++)
{
angle = arr[i]*(Math.PI/180); //radians
sine = Math.sin(angle);
context.moveTo(x,y);
context.lineTo(angle,sine);
context.stroke();
//set current varibles for next move
x = angle;
y = sine;
}
}
看看这个答案在这里,应该给你的东西继续:http://stackoverflow.com/questions/6032998/how-to-draw-a-curve-that-could-move-to-left-with -canvas –
我能够用代码减去一些html元素生成jsfiddle。看这里。 http://jsfiddle.net/franktudor/4wv9r/ –
好吧,'sin'的域名在-1和1之间,这就是为什么你只能看到一个点。 –