+ 2
window.onload = function() { stk = document.getElementsByTagName("canvas")[0].getContext("2d"); stk.moveTo(Math.random()
plezz.....explain me this code !!
4 Respostas
+ 2
window.onload Is an event that is triggered when the widow has loaded including its content.
So this function runs after the page loads.
document.getElementsByTagName("canvas")[0] gets all the elements of the tag type <canvas>
and puts them into an array and then gets the first element "[0]" of that array. Then getContext("2d"); gets the 2 dimensional context for that canvas which allows for 2d drawing to now take place on that canvas. This is all put into the variable "stk" (which i'm guessing is supposed to be short for stroke).
When this is created I believe that the "pen" tip aka "stk" would be located at the 0, 0 coordinates (upper left of canvas).
The stk.moveTo(Math.random() <-- Incomplete, this should take both an x and y coordinate.
But, I think the Idea here is to draw to a random location on the canvas.
Maybe like this instead -> stk.moveTo(Math.random(), Math.random());
+ 2
Oh yes... that's the start of your sentence and the breakin line wich confuses me, and so, I was too quickly, not you ^^
0
@ChaoticDawg:
document.getElementsByTagName("canvas") gets all the elements of the tag type <canvas>, but the '[0]' tagert the first element index ;) ( I think you've just write to quickly, but it seems to me needing to accuratly explain the difference for beginner leaners :P )...
And probably these are the three first lines of a much longer function ^^
0
@visph
Nope that's in my answer. Read the sentence agian. ;-)