{"id":17594,"date":"2015-10-07T05:01:59","date_gmt":"2015-10-06T19:01:59","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=17594"},"modified":"2015-10-06T17:32:40","modified_gmt":"2015-10-06T07:32:40","slug":"htmljavascript-canvas-geometry-tracing-game-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-geometry-tracing-game-tutorial\/","title":{"rendered":"HTML\/Javascript Canvas Geometry Tracing Game Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/geometry_tracing.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript Canvas Geometry Tracing Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/geometry_tracing.jpg\" title=\"HTML\/Javascript Canvas Geometry Tracing Game Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript Canvas Geometry Tracing Game Tutorial<\/p><\/div>\n<p>The Canvas HTML element tag can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management.<\/p>\n<p>In today&#8217;s tutorial we mainly use the <a target=_blank href='http:\/\/www.w3schools.com\/tags\/canvas_drawimage.asp' title='HTML5 Canvas drawImage() method information from w3schools ... thanks'>drawImage<\/a> and <a target=_blank href='http:\/\/www.w3schools.com\/tags\/canvas_lineto.asp' title='HTML5 Canvas lineTo() method information from w3schools ... thanks'>lineTo<\/a> functions to create a webpage where you can draw lines tracing existant images shown on the canvas.<\/p>\n<p>This game illustrates the <a target=_blank title='Mapping information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Mapping'>mapping<\/a> skill known as <a target=_blank title='Digitizing information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Digitizing'>hard copy digitising<\/a>, and though the author claims no expertise here, you score better if you digitise the same way, because the amount out you are will determine how much is taken off your score in a survival game &#8230; the longer you survive with a positive score the better you are.   As a note, if your digitising is diabolically bad, it could be a zooming issue!<\/p>\n<p>With the ellipse and the circle you need to close close to your starting point to get your digitised area evaluated.<\/p>\n<p>You may want to read more at <a target=_blank title='HTML Canvas Reference' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>HTML Canvas Reference<\/a> as a generic reference, or here, at the tutorial <a target=_blank title='javascript - How do I add a simple onClick event handler to a canvas element? - Stack Overflow' href='http:\/\/stackoverflow.com\/questions\/9880279\/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element'>javascript &#8211; How do I add a simple onClick event handler to a canvas element? &#8211; Stack Overflow<\/a>.<\/p>\n<p>You may notice several similarities thinking about today&#8217;s tutorial &#8220;workings&#8221; to that of yesterday&#8217;s <a target=_blank title='HTML\/Javascript Canvas Slope of a Line Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-slope-of-a-line-primer-tutorial\/'>HTML\/Javascript Canvas Slope of a Line Primer Tutorial<\/a>, three of which we&#8217;d like to focus your attention on &#8230;<\/p>\n<ol>\n<li>both use an HTML canvas positioned, nominally within the second column, second row of an HTML table element&#8217;s HTML td &#8220;cell&#8221; (all overseen by an HTML div element horizontally centrally aligned), yet the HTML canvas uses <a target=_blank title='CSS position property information from w3schools' href='http:\/\/www.w3schools.com\/cssref\/pr_class_position.asp'><i>position:absolute;<\/i><\/a> with numerically specified <i>top: and width: and height:<\/i> but percentage specified <i>left:50%;<\/i> &#8230; why? &#8230; to allow for a canvas element not tucked up in the top left corner, but positioned where the table cell would be anyway (and where users are probably more comfortable seeing it), yet &#8230;<\/li>\n<li>both web applications use co-ordinates, used in the context of the functionality of the HTML canvas element, where it is not important &#8220;absolutely&#8221; &#8230; we only need to know co-ordinates &#8220;relatively&#8221; to achieve the functionality we set out to achieve, but must retain &#8220;scale&#8221; to be functional, so &#8230;<\/li>\n<li>the <a target=_blank title='Javascript onresize event information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/event_onresize.asp'><i>onresize<\/i><\/a> event can be handled by restarting the web application via <i>location.href=[URL_of_web_application];<\/i> and the <i>left:50%;<\/i> is &#8220;reworked&#8221; for the new window width that results<\/li>\n<\/ol>\n<p> &#8230; as it may be unusual to see a <i>position:absolute;<\/i> scenario not having all numerically specified <i>top:<sub>s<\/sub> and width:<sub>s<\/sub> and height:<sub>s<\/sub> and left:<sub>s<\/sub><\/i>, and yet am often longing not to be tied down by this totally numerically specified scenario &#8230; so wanted to show that the <i>left:50%;<\/i> seems to work okay for a lot of web browser and platforms here, and yesterday.  Whether it would work if the web application needs an absolute co-ordinate system is doubtful &#8230; there would be a lot more thought needed to achieve the same result for an absolute co-ordinate system web application such as one locating exact objects on Earth, for example.<\/p>\n<p>As you can see, this HTML canvas element, new to HTML5, can be very useful for some practical client-side web functionality.<\/p>\n<p>Here is a link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/geometry_tracing.html_GETME' title='geometry_tracing.html'>geometry_tracing.html<\/a><\/p>\n<p>We hope you enjoy this Mathematical tutorial <a target=_blank title='Canvas HTML element live run tutorial'  href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/geometry_tracing.html\">live run<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d17594' onclick='var dv=document.getElementById(\"d17594\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=geometry\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d17594' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Canvas HTML element tag can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management. In today&#8217;s tutorial we mainly use the drawImage and lineTo functions &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-geometry-tracing-game-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,21,37],"tags":[99,184,1707,281,333,476,477,484,576,652,748,752,1578,894,997,1319],"class_list":["post-17594","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-land-surveying","category-tutorials","tag-area","tag-canvas","tag-co-ordinates","tag-css","tag-digitizing","tag-game","tag-games-2","tag-geometry","tag-html","tag-javascript","tag-mapping","tag-mathematics","tag-onresize","tag-overlay","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/17594"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=17594"}],"version-history":[{"count":14,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/17594\/revisions"}],"predecessor-version":[{"id":17608,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/17594\/revisions\/17608"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=17594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=17594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=17594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}