Can you guess what todayโs tutorial is about if we say โฆ
- yes, itโs about โrotationโ โฆ
- and another word for โrotationโ could be โฆ anyone, anyone โฆ bit cheeky, but, yes, Tad ((it that Low?) โฆ on second thoughts, no โฆ but how about you James Hargreaves?
Yes, am after โspinโ โฆ good work!
- โฆ and then thereโs what we were showing as โspin and rotation type web applicationsโ the day before yesterday, isnโt thereโฆ anyone, anyone?
Yes, Regina, am after โฆ
- todayโschanged missing_two
htmlโs Missing
Two live run that is affected, but two other web applications as per โฆ
- todayโschanged yaw_etc
htmlโs Device
Orientation live run โฆ and โฆ
- todayโschanged simon_says
htmlโs Simon
Says live run
โฆ top supportive!
- todayโschanged missing_two
- โฆ and then thereโs what we were showing as a finishing URL yesterday, isnโt thereโฆ anyone, anyone?
Yes, Orville, am after โyaw_etc.htmlโ โฆ excellent!
- โฆ and a new game to play, perhaps?
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
Okay, Tad Low, youโve had your hand up for ten minutes now!
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
Oh. Well, itโs around the corner, and remember to wash your hands after. You may be excused. Anyone else, anyone?
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ ?
Yes, Kyungjin Lee, am after โSpin the
BottleMobile Device Gameโ โฆ yayyyyyyy!
Yes, be careful how you set it up so that your mobile device will not fall and/or hit anything bad โฆ carpet (with lots of room) is good โฆ but โฆ
- Tap Device
Orientation live run link โฆ
- Tap any โStartโ and/or โAllowโ button(s) presented at the top left (and answer any permissions questions, pending) โฆ
- Tap the new โSpin the Deviceโ button โฆ
- Select number of players โฆ from 1 to 6 โฆ
- Players take it in turns, starting with a score of 36000 each, to be given a nominated clockwise angle in degrees to spin, that player โฆ
- Taps their yellow โNot Readyโ button โฆ to effectively say, โam braced, ready to spin my deviceโ โฆ
- Player then โspins that deviceโ so as to closely match that nominated number of clockwise degrees โฆ then taps their (now) green button for the web applicationโs verdict โฆ
- And the score reduces by any difference between the nominal number of (clockwise) degrees and the playerโs spin number of (clockwise) degrees rotation detected (by good olโ window.DeviceOrientationEvent event logic)
- Next playerโs
turnspin!
The new static HTML table element for the โSpin the Deviceโ game, positioned just below any permissions related buttons up the top of the webpage, initialized to โฆ
<table id=mytable>
</table>
โฆ supported by the new relevant Javascript โSpin the Deviceโ game functions and global variables โฆ
var nump=0;
var spinscores=[];
var spingoes=[];
var spinnext=0;
var degtospin=0;
function amready(whoin) {
var who=eval(eval(whoin) + 0);
//alert('Who=' + who);
if (document.getElementById('b' + who).innerHTML == 'Not Ready') {
document.getElementById('b' + who).style.backgroundColor='green';
document.getElementById('b' + who).innerHTML='Spin close to <font size=4 color=red>' + degtospin + '° clockwise ∱</font>, then tap me again';
initial_yaw=eval('0' + document.getElementById("doBearing").innerHTML);
if (document.getElementById('th0').innerHTML.indexOf('tap your ') != -1) {
document.getElementById('th0').innerHTML=document.getElementById('th0').innerHTML.split('tap your ')[0] + 'spin now. Good luck!';
}
} else if (document.getElementById('b' + who).innerHTML != 'Ready') {
//alert('WHO=' + who);
spingoes[eval(-1 + eval(who))]++;
//alert('' + Math.abs(eval(degtospin - eval(eval(360 + eval('0' + document.getElementById('doBearing').innerHTML) - initial_yaw) % 360))) + ' via initial_yaw=' + initial_yaw + ' and curbrg=' + document.getElementById('doBearing').innerHTML);
spinscores[eval(-1 + eval(who))]-=Math.abs(eval(degtospin - eval(eval(360 + eval('0' + document.getElementById('doBearing').innerHTML) - initial_yaw) % 360)));
document.getElementById('goes' + who).innerHTML='' + spingoes[eval(-1 + eval(who))];
document.getElementById('score' + who).innerHTML='' + spinscores[eval(-1 + eval(who))];
document.getElementById('b' + who).style.backgroundColor='white';
document.getElementById('b' + who).innerHTML='Not Ready';
spinnext++;
if (spinnext == nump) { spinnext=0; }
gospin(spinnext);
}
}
function playspin(cnump) {
var mytih='<thead><tr></tr></thead><tfoot><tr></tr></tfoot>';
if (cnump.trim() != '') {
nump=eval(cnump);
mytih=mytih.replace('<thead>', '<thead><tr><th style="cursor:pointer;" onclick="alert(this.title);" title="Careful how you play so as not to drop your device nor have it hit something. On carpet with lots of room is ideal here." id=th0 colspan=' + nump + '>Welcome to the <font title="Careful how you play so as not to drop your device nor have it hit something. On carpet with lots of room is ideal here." color=purple size=5>Spin the Device</font> game for ' + nump + '<span id=s0></span></th></tr>');
for (var ii=1; ii<=nump; ii++) {
spinscores.push(36000);
spingoes.push(0);
mytih=mytih.replace('</tr></thead>', '<th id=th' + ii + '><div id=div' + ii + ' contenteditable=true>Player ' + ii + '</div></th></tr></thead>');
mytih=mytih.replace('</tr></tfoot>', '<td id=td' + ii + '><span id=score' + ii + '>' + spinscores[eval(-1 + ii)] + '</span><span> / </span><span id=goes' + ii + '>0</span><br><br><button title="Click when ready" id=b' + ii + ' onclick=amready(' + ii + ');>Not Ready</button></th></tr></tfoot>');
}
document.getElementById('mytable').innerHTML=mytih;
document.getElementById('mytable').border='20';
}
gospin(spinnext);
}
function gospin(whoin) {
var who=eval(eval(whoin) + 1);
//alert('who=' + who);
document.getElementById('b' + who).style.backgroundColor='yellow';
degtospin=eval(Math.floor(Math.random() * 358) + 1);
document.getElementById('s0').innerHTML=' ... <font color=blue size=4>' + document.getElementById('div' + who).innerHTML + '</font> ... try to spin close to <font color=red size=4>' + degtospin + '° clockwise ∱</font> & tap your yellow Not Ready button to start';
}
function spingame() {
document.getElementById('dspin').innerHTML="<select onchange='playspin(this.value);'><option value=''>Spin Game number of players below ...</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option></select>";
}
Previous relevant HTML5 Device Orientation Events Game Tutorial is shown below.
Today weโ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 tremendous link, thanks.
If you use a mobile device regularly, youโ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 โDevice Orientationโ game based on these HTML5 and Javascript based smarts.
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 โฆ
- โAlphaโ โฆ or Direction, or Bearing, or in shipping โmotionโ terms, โyawโ
- โBetaโ โฆ or Tilt Front/Back, or in shipping โmotionโ terms, โpitchโ
- โGammaโ โฆ or Tilt Left/Right, or in shipping โmotionโ terms, โrollโ
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 โseconds survivedโ game of skill and perseverance.
The HTML and Javascript programming source code you could call yaw_etchtml does not have to be played as a game in its live
run form, and in that โnon-gameโ mode of use, just gets you used to the way the three rotations above happen for mobile devices where the Javascript โฆ
<script type='text/javascript'>
if (window.DeviceOrientationEvent) {
// You're in business with HTML5 Device Orientation Events
}
</script>
โฆ which, happily, is the case for the iPad screenshot of todayโs tutorial picture.
Image helping websites weโd like to thank are โฆ
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.