cos curve on html Canvas
angle is variable in degree More about Math.sin() with radian or degree as input Drawing Curves , Graphs , Grids on Canvas
var my_canvas=$('#my_canvas').get(0) var gctx = my_canvas.getContext("2d"); /////// Axis ////// gctx.beginPath(); gctx.lineWidth=3; gctx.shadowColor = '#ffffff'; gctx.strokeStyle= '#0060c0'; gctx.moveTo(0, 125); gctx.lineTo(595,125); // Horizontal X Axis gctx.moveTo(10, 2); gctx.lineTo(10,248); // Vertical Y Axis gctx.stroke(); ////////Axis end/// gctx.beginPath(); for (var angle = 0; angle <590; angle+=5){ var y =125 - 120*( Math.cos(( Math.PI/180 ) * angle)) var x=10 + angle; gctx.lineTo(x,y); } gctx.strokeStyle= '#f00000'; gctx.stroke();
This article is written by plus2net.com team.
| ||||||||||