Javascript 绘制 sin 曲线代码如下 :
<! Doctype html> <html> <éadf> <style type = "text / css"> #mycanvas {background-color: CornflowerBlue; } nous var contenu = my_canvas.getContext ("2d"); content.beginPath (); contenu.moveto (10, 100); pour (var i = 1; i <200; i + = 0,1) {var x = i * 10; var y = math.sin (i) * 10 + 100; contenu.lineto (x, y); } content.stroke (); content.closepath (); } </ script> </ head> <body onload = "draw ()"> <canvas id = "myCanvas"> </ canvas> </body> </html>:
<! Doctype html> <html> <éadf> <style type = "text / css"> #mycanvas {background-color: CornflowerBlue; } </ style> <script type = "text / javascript"> var i = 1; var x = 1; var y = 100; function moveSIn () {var my_canvas = document.getElementById ("myCanvas"); var contenu = my_canvas.getContext ("2d"); content.beginPath (); contenu.moveto (x, y); i + = 0,1; x = i * 10; y = math.sin (i) * 10 + 100; contenu.lineto (x, y); contenu.stroke (); content.closepath (); } setInterval (movesIn, 10); </cript> </ head> <body onload = "movesIn ()"> <canvas id = "myCanvas"> </ canvas> </body> </html>