javascript - Plotting with HTML5 Canvas -
I decided the day to start the element and I can say that it has been a nightmare to work is. I want to plot a Sean Graff. So after reading good I still can not get the original nor can he get the plot. I have tried that down (sorry for my ignorance with that tag for the first time). I wonder what this is but the code for the beginning of my life is difficult.
HTML CSS JavScript Because the Besides, I see you have an array ranging from 0 to 180. I believe that you are trying to drag the curve from 0 degrees to 180 degrees with We first start by moving the point to the left canvas: In most cases the first point will not be in the middle but this is for sign. (You can fix this later.) This is a loop depicting curve but what should be kept inside us? Well, you can take the number returned by the sign function and increase it, vice versa, and move it in half way. I do this because the coordinate system in Javascript is 0,0 at the top left instead of the bottom left. So this is Viola, you have successfully posted an article in javascript. Oh, yes, do not forget to actually draw it on the canvas, because Demo: PS: I think you are trying to resize the canvas using CSS. Believe me, this will not work :) You have to define the dimension in HTML.
& lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Graphic on & lt; / Title & gt; & Lt; link type = "text / css" rel = "stylesheet" href = "graph.css" /> & Lt; Script type = "text / javascript" src = "graph.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Canvas id = "surface" & gt; Canvas is not supported & lt; / Canvas & gt; & Lt; / Body & gt; & Lt; / Html & gt;
#surface {width: 300; Height: 225; Border: Point # FF 20000 1px; }
window.onload = function () {var canvas = document.getElementById ("surface"); Var reference = 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 & lt; arr.length; i ++) {angle = ar [i] * (Math.PI / 180); // radian sign = monastery sin (angle); context.moveTo (x, y); context.lineTo (angle, sign); Context.stroke (); // next move x set current varibles for angle; y = sign; }}
sin x range
[- 1,1] , it will only return the number between -1 and 1, and this means that the drawing you make is a dot on the screen.
x ? You do not really need to do this (anyway 12 digits are not enough to draw a smooth line) just do it for the
loop, with the number of pieces containing the
lines .
context.moveTo (0, 100 / * somewhere between * /); // starting point
For
(var i = 0; i
var sine = Math.sin (i / scale * 2) * scale; context.lineTo (i * frag, -sine + scale); // i * frag = increase the position of x / - sign = scale = y position, flip, scaled, / i / scale * 2 = put on random scale i understand the correct scale with some math
for loop has done its job:
context.stroke ();
Comments
Post a Comment