{"id":24400,"date":"2016-10-13T03:01:51","date_gmt":"2016-10-12T17:01:51","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=24400"},"modified":"2019-11-09T18:18:43","modified_gmt":"2019-11-09T08:18:43","slug":"simon-says-device-motion-orientation-game-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/simon-says-device-motion-orientation-game-primer-tutorial\/","title":{"rendered":"Simon Says Device Motion Orientation Game Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/simon_says.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Simon Says Device Motion Orientation Game Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/simon_says.jpg\" title=\"Simon Says Device Motion Orientation Game Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Simon Says Device Motion Orientation Game Primer Tutorial<\/p><\/div>\n<p>Did you ever play &#8220;Simon Says&#8221; at school?  Perhaps we should have asked, are you still playing &#8220;Simon Says&#8221; as an adult?  It&#8217;s a game of trust where you do well by mimicing &#8220;Simon&#8221; and what they decide you should do.   Unsurprisingly, for such a simple concept game, it&#8217;s got a history, as you can read about here at <a target=_blank title='Simon Says game information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Simon_Says'>Wikipedia<\/a>.<\/p>\n<p>Our game today rewards the accuracy of the &#8220;mimicry&#8221; a player can achieve of the other Simon.  In other words, &#8220;will the real Simon please stand up&#8221;.  Yes, two players try to be the best mimicer of the other Simon player.<\/p>\n<p>But it&#8217;s not so much &#8220;Simon Says&#8221;, so far with the development of this game, but more, &#8220;Simon Does&#8221;.  We go back to those HTML5 Device Orientation and Device Motion events suitable for many mobile devices out there to have a game collecting motion data of the &#8220;first Simon cab off the rank&#8221; and ask the &#8220;second Simon cab off the rank&#8221; to mimic the actions of their competitor, for that same period of live motion action they took.  Behind the scenes the computer game compares motion data sets and if they are close you lose less points from your 100000 starting points in order to survive longer in the game &#8230; survival of the fittest &#8220;Simon&#8221;.<\/p>\n<p>We fully get the irony of &#8220;a copycat making it in this world&#8221;, but isn&#8217;t that the way of game strategy, if you sit down and analyze what amuses us in a game.  After all, do you think the most reliable friends can be judged via their Monopoly prowess?  We rest our cases.<\/p>\n<p>We hope you like the &#8220;Simon Says&#8221; <a target=_blank title='Simon Says game' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/simon_says.html'>game<\/a> we&#8217;ve done a first draft for with the HTML and Javascript code you could call <a target=_blank title='simon_says.html' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/simon_says.html-GETME'>simon_says.html<\/a> and which used many of the ideas from the fabulous <a target=_blank title='Device Orientation and Device Motion events' href='http:\/\/www.html5rocks.com\/en\/tutorials\/device\/orientation\/'>webpage here<\/a>, as we also used at <a title='HTML5 Device Motion Events Game Tutorial' href='#hdmegt'>HTML5 Device Motion Events Game Tutorial<\/a> and <a title='HTML5 Device Orientation Events Game Tutorial' href='#hdoegt'>HTML5 Device Orientation Events Game Tutorial<\/a> as shown below.<\/p>\n<hr>\n<p id='hdmegt'>Previous relevant <a target=_blank title='HTML5 Device Motion Events Game Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/html5-device-motion-events-game-tutorial\/'>HTML5 Device Motion Events Game Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/momentum_etc.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"HTML5 Device Motion Events Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/momentum_etc.jpg\"  \/><\/a><p class=\"wp-caption-text\">HTML5 Device Motion Events Game Tutorial<\/p><\/div>\n<p>Yesterday we drew attention to the great HTML5 Device Orientation events when we presented <a title='HTML5 Device Orientation Events Game Tutorial' href='#hdoegt'>HTML5 Device Orientation Events Game Tutorial<\/a> as shown below.  Related to those mobile device Device Orientation event possibilities are the Device Motion event possibilities to relate your mobile device motion relative to the Earth beneath it &#8230; <font size=1>unless you know something we don&#8217;t know?!<\/font><\/p>\n<p>So with this HTML5 Device Motion event functionality, to understand what&#8217;s going on &#8220;under the hood&#8221; you&#8217;ll need to (go back?) to your physics at school, perhaps, and we saw great links at the <a target=_blank title='Device Orientation and Device Motion events' href='http:\/\/www.html5rocks.com\/en\/tutorials\/device\/orientation\/'>same great source link as used yesterday<\/a> for matters concerning gravity and motion and acceleration.<\/p>\n<p>So what is in a modern mobile device that the laptops can&#8217;t work these events?  Well, have read it is all possible these days because of inbuilt <a target=_blank title='Gyroscope information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Gyroscope'>gyroscopes<\/a> in these devices, which beggars the question for us &#8230; &#8220;How the heck do they fit gyroscopes into those really thin mobile phones and tablets?&#8221;<\/p>\n<p>As with the Device Orientation work matters are measured in the three co-ordinate dimensions that we are used to &#8230; x,y,z &#8230; and as with the way we can, simplistically, define a distance in space as &#8230;<\/p>\n<p><code><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><msqrt><mi>(x * x) + (y * y) + (z * z)<\/mi><\/msqrt><\/math><\/code><\/p>\n<p> &#8230; we base a game on the gravitational force components being so close to that <a target=_blank title='Gravity information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Gravity'>9.80665<\/a> m\/s<sup>2<\/sup> (gravity acceleration) measurement, perhaps, ingrained into you at school physics, to say that if you break &#8220;10&#8221; with a calculation of motion, as above for the x,y,z equivalent of motion acceleration readings from the device, and available via the Device Motion events, then we say that you are &#8220;moving&#8221; else we remind you of your &#8220;slothfulness&#8221; &#8230; <font size=1>but no sloths were hurt in the making of our game<\/font>.<\/p>\n<p>The HTML and Javascript programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/momentum_etc.html--GETME\">momentum_etc.html<\/a> does not have to be played as a game in its <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/momentum_etc.html\">live run<\/a> form, and in that &#8220;non-game&#8221; mode of use, just gets you used to the way the motion measurements &#8220;shape&#8221; for mobile devices where the Javascript &#8230;<\/p>\n<p><code><br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\nif (window.DeviceMotionEvent) {<br \/>\n  \/\/ You're in business with HTML5 Device Motion Events<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n<\/code> <\/p>\n<p> &#8230; which, happily, is the case for the <a target=_blank title='iPad screenshot' href='http:\/\/www.rjmprogramming.com.au\/Mac\/iPad\/siri_setup.jpg'>iPad screenshot<\/a> of today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/momentum_etc.jpg\" title='Tutorial picture is screenshot off iPad'>tutorial picture<\/a>.<\/p>\n<hr>\n<p id='hdoegt'>Previous relevant <a target=_blank title='HTML5 Device Orientation Events Game Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/html5-device-orientation-events-game-tutorial\/'>HTML5 Device Orientation Events Game Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/yaw_etc.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"HTML5 Device Orientation Events Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/yaw_etc.jpg\"  \/><\/a><p class=\"wp-caption-text\">HTML5 Device Orientation Events Game Tutorial<\/p><\/div>\n<p>Today we&#8217;ve written a web application suiting mobile devices, but probably not many laptops. That is because we are harnessing the power of the Device Orientation (today) and Device Motion (at a later date) events new to HTML5, and very well explained at this <a target=_blank title='Device Orientation and Device Motion events' href='http:\/\/www.html5rocks.com\/en\/tutorials\/device\/orientation\/'>tremendous link<\/a>, thanks.<\/p>\n<p>If you use a mobile device regularly, you&#8217;ll probably have seen mobile and web applications making use of the fact that the mobile device being used is moving itself, and has its screen orientation an option, rather than an awkwardly controlled hardware setting.  These dynamisms of what we are talking about harnessing today, and we closely follow the leads of the code supplied in the link above, and build a &#8220;Device Orientation&#8221; game based on these HTML5 and Javascript based smarts.<\/p>\n<p>The bottom line of this is that with this functionality we can glean the 3 rotations of the mobile device relative to the world around it, termed as &#8230;<\/p>\n<ul>\n<li>&#8220;Alpha&#8221; &#8230; or Direction, or Bearing, or in shipping &#8220;motion&#8221; terms, <a target=_blank href=\"https:\/\/en.wikipedia.org\/wiki\/Ship_motions\" title='Ship motion information from Wikipedia ... thanks'>&#8220;yaw&#8221;<\/a><\/li>\n<li>&#8220;Beta&#8221; &#8230; or Tilt Front\/Back, or in shipping &#8220;motion&#8221; terms, <a target=_blank href=\"https:\/\/en.wikipedia.org\/wiki\/Ship_motions\" title='Ship motion information from Wikipedia ... thanks'>&#8220;pitch&#8221;<\/a><\/li>\n<li>&#8220;Gamma&#8221; &#8230; or Tilt Left\/Right, or in shipping &#8220;motion&#8221; terms, <a target=_blank href=\"https:\/\/en.wikipedia.org\/wiki\/Ship_motions\" title='Ship motion information from Wikipedia ... thanks'>&#8220;roll&#8221;<\/a><\/li>\n<\/ul>\n<p>Defining those, our game can take you into the cockpit of a plane, perhaps, to set you tasks you try to achieve as accurately as possible, in a &#8220;seconds survived&#8221; game of skill and perseverance.<\/p>\n<p>The HTML and Javascript programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/yaw_etc.html--GETME\">yaw_etc.html<\/a> does not have to be played as a game in its <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/yaw_etc.html\">live run<\/a> form, and in that &#8220;non-game&#8221; mode of use, just gets you used to the way the three rotations above happen for mobile devices where the Javascript &#8230;<\/p>\n<p><code><br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\nif (window.DeviceOrientationEvent) {<br \/>\n  \/\/ You're in business with HTML5 Device Orientation Events<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n<\/code> <\/p>\n<p> &#8230; which, happily, is the case for the <a target=_blank title='iPad screenshot' href='http:\/\/www.rjmprogramming.com.au\/Mac\/iPad\/siri_setup.jpg'>iPad screenshot<\/a> of today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/yaw_etc.jpg\" title='Tutorial picture is screenshot off iPad'>tutorial picture<\/a>.<\/p>\n<p>Image helping websites we&#8217;d like to thank are &#8230;<\/p>\n<ul>\n<li><a target=_blank title='Cockpit image' href='http:\/\/www.mobogenie.com\/download-ship-parking-simulation-3d-489590.html'>Cockpit<\/a><\/li>\n<li><a target=_blank title='Thanks to this compass needle image resource ... http:\/\/marylandlearninglinks.org\/wp-content\/themes\/learning-links\/img\/compass-needle.png' href='\/\/www.rjmprogramming.com.au\/HTMLCSS\/compass-needle.png'>Compass Needle<\/a><\/li>\n<\/ul>\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='#d24134' onclick='var dv=document.getElementById(\"d24134\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/html5\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d24134' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\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='#d24163' onclick='var dv=document.getElementById(\"d24163\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/science\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d24163' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\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='#d24400' onclick='var dv=document.getElementById(\"d24400\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=game\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d24400' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Did you ever play &#8220;Simon Says&#8221; at school? Perhaps we should have asked, are you still playing &#8220;Simon Says&#8221; as an adult? It&#8217;s a game of trust where you do well by mimicing &#8220;Simon&#8221; and what they decide you should &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/simon-says-device-motion-orientation-game-primer-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,15,37],"tags":[1973,1970,281,1971,354,400,476,477,1799,576,578,590,630,652,795,1969,1974,1972,889,940,997,1072,1100,1776,1319,1402],"class_list":["post-24400","post","type-post","status-publish","format-standard","hentry","category-elearning","category-games","category-tutorials","tag-acceleration","tag-bearing","tag-css","tag-direction","tag-dom","tag-event","tag-game","tag-games-2","tag-gravity","tag-html","tag-html5","tag-image","tag-ipad","tag-javascript","tag-mobile","tag-mobile-device","tag-momentum","tag-motion","tag-orientation","tag-physics","tag-programming","tag-rotation","tag-science","tag-screenshot","tag-tutorial","tag-web-application"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/24400"}],"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=24400"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/24400\/revisions"}],"predecessor-version":[{"id":47122,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/24400\/revisions\/47122"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=24400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=24400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=24400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}