我決定要踏上元素,我可以說到目前爲止它已經是噩夢讓它工作。我只想繪製正弦圖。所以在閱讀好後,我仍然不能得到出處,也不能得到它的陰謀。下面是我試過的(我第一次用這個標籤,所以原諒我的無知)。我想知道的是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之間,這就是爲什麼你只能看到一個點。 –