Find Image Files via Filesize Tutorial

Find Image Files via Filesize Tutorial

Find Image Files via Filesize Tutorial

The last time we talked about our inhouse PHP Image File Finder web application (we nickname “Kevin” around here) was with Relative Image URL Data URI Relationship Primer Tutorial and am sure you’d agree with me regarding today’s sentiment …

Kevin … we need to talk

… because we think PHP Image File Finder web application … you need to …

Bring home the Bacon,
Lest we feel inKlined,
Within the Spacey realms twixt …
Rudderless sea and air,
We lose Heart,
Jaime‘s, to thee …
Thy true Love of thine,
In pursuit of Durant in ‘mongst thy throng,
Counting the Costnear of supine …
Pollaxked perfidididity

… because we know you get where we are coming at here.

But just in case, we wanted to offer two new “filtering” functionalities in front of the “image scrutiny via dimensions” paradigm currently happening, that being …

  • allow case insensitive file specifications
  • allow filesize user control

… via new initialization PHP code as per …

<?php

$casei=false;
$sizei="";
$minusname=" -name '";
$plusname="'";
$optthbit="<th id=thvarious><select onchange=\"document.getElementById('tdvarious').innerHTML='&#10060;';\" id=svarious><option value=casei>Case Insensitive?</option><option value=sizei>Size Match?</option></select></th>";
$opttdbit="<th id=tdvarious title='Click to toggle' onclick=\" this.innerHTML=(eval('' + this.innerHTML.length) != 1 ? '&#10060;' : maybenotjusttick('&#10004; ')); if (eval('' + this.innerHTML.length) > 1) { document.getElementById('divmyrform').innerHTML+='<input type=hidden name=' + document.getElementById('svarious').value + ' value=' + encodeURIComponent(this.innerHTML) + '></input>'; } else { document.getElementById('divmyrform').innerHTML=document.getElementById('divmyrform').innerHTML.replace(' name=' + String.fromCharCode(34) + document.getElementById('svarious').value, ' data-name=' + String.fromCharCode(34) + document.getElementById('svarious').value); document.getElementById('divmyrform').innerHTML+='<input type=hidden name=' + document.getElementById('svarious').value + ' value=></input>'; }\">&#10060;</th>";
if (isset($_GET['casei'])) { if ($_GET['casei'] != '') { $casei=true; $minusname=" -iname '"; $plusname="' "; } }
if (isset($_GET['sizei'])) { if (str_replace('%25E2%259C%2594%2520%2520%2520','',$_GET['sizei']) != '') {
$sizei=str_replace('%2B', '+',str_replace('%252B', '+', $_GET['sizei']));
$plusname="' -size " . str_replace('%2B', '+',str_replace('%252B', '+', $_GET['sizei'])) . " ";
$optthbit="<th id=thvarious><select onchange=\"document.getElementById('tdvarious').innerHTML='&#10060;';\" id=svarious><option value=sizei>Size Match?</option><option value=casei>Case Insensitive?</option></select></th>";
$opttdbit="<th id=tdvarious title='Click to toggle' onclick=\" this.innerHTML=(eval('' + this.innerHTML.length) != 1 ? '&#10060;' : maybenotjusttick('&#10004; ')); if (eval('' + this.innerHTML.length) > 1) { document.getElementById('divmyrform').innerHTML+='<input type=hidden name=' + document.getElementById('svarious').value + ' value=' + encodeURIComponent(this.innerHTML) + '></input>'; } else { document.getElementById('divmyrform').innerHTML=document.getElementById('divmyrform').innerHTML.replace(' name=' + String.fromCharCode(34) + document.getElementById('svarious').value, ' data-name=' + String.fromCharCode(34) + document.getElementById('svarious').value); document.getElementById('divmyrform').innerHTML+='<input type=hidden name=' + document.getElementById('svarious').value + ' value=></input>'; }\">" . $sizei . "</th>";
}
}

?>

… augmented by new PHP functions …

<?php

function maybesizewrong($inspc) {
global $sizei;
$ourvv=0;
if (trim($sizei) != "") {
$vss=filesize($inspc);
if (substr($sizei,0,1) == '+') {
if (strpos($sizei, "G") !== false) {
$ourvv=(1073741824 * explode("G", substr($sizei,1))[0]);
} else if (strpos($sizei, "M") !== false) {
$ourvv=(1048576 * explode("M", substr($sizei,1))[0]);
} else if (strpos($sizei, "k") !== false) {
$ourvv=(1024 * explode("k", substr($sizei,1))[0]);
} else if (strpos($sizei, "c") !== false) {
$ourvv=(1 * explode("c", substr($sizei,1))[0]);
} else {
$ourvv=(1 * explode("c", substr($sizei,1))[0]);
}
//echo $ourvv . ' and vss=' . $vss;
//exit;
if ($vss <= $ourvv) { return false; }
} else if (substr($sizei,0,1) == '-') {
if (strpos($sizei, "G") !== false) {
$ourvv=(1073741824 * explode("G", substr($sizei,1))[0]);
} else if (strpos($sizei, "M") !== false) {
$ourvv=(1048576 * explode("M", substr($sizei,1))[0]);
} else if (strpos($sizei, "k") !== false) {
$ourvv=(1024 * explode("k", substr($sizei,1))[0]);
} else if (strpos($sizei, "c") !== false) {
$ourvv=(1 * explode("c", substr($sizei,1))[0]);
} else {
$ourvv=(1 * explode("c", substr($sizei,1))[0]);
}
if ($vss >= $ourvv) { return false; }
} else {
if (strpos($sizei, "G") !== false) {
$ourvv=(1073741824 * explode("G", substr($sizei,0))[0]);
} else if (strpos($sizei, "M") !== false) {
$ourvv=(1048576 * explode("M", substr($sizei,0))[0]);
} else if (strpos($sizei, "k") !== false) {
$ourvv=(1024 * explode("k", substr($sizei,0))[0]);
} else if (strpos($sizei, "c") !== false) {
$ourvv=(1 * explode("c", substr($sizei,0))[0]);
} else {
$ourvv=(1 * explode("c", substr($sizei,0))[0]);
}
if ($vss != $ourvv) { return false; }
}
}
return true;
}

function maybecasei($inspc) { // wrapper for PHP glob file specification
global $casei;
$arrlc = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
$outspc=$inspc;
if ($casei) {
if (strpos($inspc, "[") === false && strpos($inspc, "]") === false) {
foreach ($arrlc as $value) {
if (strpos($outspc, strtoupper($value)) !== false) {
$outspc=str_replace(strtoupper($value), '!@~', $outspc);
$outspc=str_replace($value, "[" . $value . strtoupper($value) . "]", $outspc);
$outspc=str_replace('!@~', "[" . strtoupper($value) . $value . "]", $outspc);
} else {
$outspc=str_replace($value, "[" . $value . strtoupper($value) . "]", $outspc);
}
}
}
}
return $outspc;
}

?>

… and by one new PHP writes Javascript function …

<?php echo ”

function maybenotjusttick(indef) {
var outdef=indef;
if (document.getElementById('svarious').value == 'sizei') {
outdef=prompt('Matching size value where + (first character) for larger than and - (first character) for smaller than and neither for exact match. Suffix c is bytes and k is kilobytes and M is megabytes and G is gigabytes.', '+-1c');
if (outdef == null) { return indef; } else if (outdef.trim() != '') { return outdef; } else { return indef; }
}
return indef;
}

“; ?>

… to add to web browser address bar $_GET form created arguments for “casei” and “savei” respectively in newly changed find_images_via_size.php web application.


Previous relevant Relative Image URL Data URI Relationship Primer Tutorial is shown below.

Relative Image URL Data URI Relationship Primer Tutorial

Relative Image URL Data URI Relationship Primer Tutorial

Yesterday’s Notes PDF Email Attachments Primer Tutorial, “under the hood”, had an interesting piece of HTML regarding that “snippety” mid-posting image (shortened regarding that image’s data URI)

<!–img src=’http://www.rjmprogramming.com.au/Mac/iPhone/bitof.jpg’></img–>
<img src=[data URI of image]></img>

… which reads, to me, that …

  • we initially called a Relative Image URL (presented in an Absolute guise) (ie. a file existed on our RJM Programming web server called bitof.jpg) … methodology undone in favour of …
  • substitute the Relative Image URL with that Relative Image URL’s Data URI for the image you see on this blog posting

… with these implications, where …

  • you save on our Linux web server’s inode count … at the expense of …
  • you further burden the MySql database with a larger blog posting

… and at the moment, for us, the former beats the latter for priority.

But, how did we arrive at the real data for [data URI of image]? We decided to tweak PHP ImageMagick Image Dimensions Primer Tutorial‘s and PDF Image and Text Nodes Windows Files Tutorial‘s newly changed find_images_via_size.php web application, by adding double click event logic on any image hovered over. That double click causes a popup window to open, whereby an image element HTML (featuring a data URI image “src” attribute (ie. decoupled from any web server ties)) is presented ready for any user Select All/Copy/Paste/Cut user arrangements.


Previous relevant Notes PDF Email Attachments Primer Tutorial is shown below.

Notes PDF Email Attachments Primer Tutorial

Notes PDF Email Attachments Primer Tutorial

Have you ever been asked to send PDF document(s), filled in, via email, and you “roll” with iOS (ie. using an iPhone or iPad)? Have you considered the “Notes approach”? It being a “total Apple solution”, it feels like a “planned for” approach that may stick in your mind.

So, first off, you create a note in Notes made up of PDF document(s), filled in, as applicable …


… via the “Scan Documents” input choice option. Then use the Share button’s Mail option to create an Email containing those Notes note PDF attachments, and just Send that off to the relevant recipients. The way the recipient receives this email is bound to please, as PDF(s) separately attached.

By the way, this way of sending sensitive information ticks all the “Document Fidelity” boxes, as PDF does not leave any traceable parts for a hacker to exploit. Good all around, we think!

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Operating System, Tutorials | Tagged , , , , , , , , , , , , , , , , , | Leave a comment

Experimental Drag and Drop Game Tutorial

Experimental Drag and Drop Game Tutorial

Experimental Drag and Drop Game Tutorial

It can be interesting turning a “concept” (or even a “proof of concept” web application) into an, on the side, “game” web application, and that way, learn what’s possible via user action. This is how we felt about yesterday’s Experimental Drag and Drop Primer Tutorial and that teamed with the wonder about how we could add some useful complexity to our “Experimental Drag and Drop” web application’s …

Drop Zone

Can “inheritance” be harnessed to make it work for some complexity of nested HTML elements inside that “Drop Zone” element when the document.body’s onload event happens? We wondered whether a Brady Bunch style 3×3 table could be the go? And whether the nine cells could have a “score” associated with them, and that set of scores be changing over time to make the game more challenging and interesting? Well …

Yes

… is the answer regarding making a game out of a proof of concept with our experimental_drag_and_drop.html HTML and Javascript and CSS game web application (also shown below) using these techniques, about which we think some of you readers will be interested?!


Previous relevant Experimental Drag and Drop Primer Tutorial is shown below.

Experimental Drag and Drop Primer Tutorial

Experimental Drag and Drop Primer Tutorial

We’ve added the word experimental into today’s blog posting title, mainly because our first of two inspirational webpage sources (last modified on 23/02/2023) regarding somewhat alternative “Drag and Drop” functionalities told us, regarding the DataTransfer object informational “DataTransfer” webpage …

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

… but our testing of the methodologies on various platforms hasn’t totally failed yet on any of the several desktop and mobile platform scenarios we’ve tried. On mobile, we just held on for a sustained touch (down) to make it possible. So maybe the industry has caught up with the ideas? We’re hoping so, because “drag and drop” is a kind of natural thing online users think of to do, and people associate it with “getting things done” we reckon.

Anyway, we relied on the great source code of the second of two inspirational webpages DataTransfer: setData() method, thanks …

The DataTransfer.setData() method sets the drag operation’s drag data to the specified data and type. If data for the given type does not exist, it is added at the end of the drag data store, such that the last item in the types list will be the new type. If data for the given type already exists, the existing data is replaced in the same position. That is, the order of the types list is not changed when replacing data of the same type.

… to get us going with our “proof of concept” web application (also shown below) using these techniques, about which we think some of you readers will be interested?!

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Games, Tutorials | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Experimental Drag and Drop Primer Tutorial

Experimental Drag and Drop Primer Tutorial

Experimental Drag and Drop Primer Tutorial

We’ve added the word experimental into today’s blog posting title, mainly because our first of two inspirational webpage sources (last modified on 23/02/2023) regarding somewhat alternative “Drag and Drop” functionalities told us, regarding the DataTransfer object informational “DataTransfer” webpage …

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

… but our testing of the methodologies on various platforms hasn’t totally failed yet on any of the several desktop and mobile platform scenarios we’ve tried. On mobile, we just held on for a sustained touch (down) to make it possible. So maybe the industry has caught up with the ideas? We’re hoping so, because “drag and drop” is a kind of natural thing online users think of to do, and people associate it with “getting things done” we reckon.

Anyway, we relied on the great source code of the second of two inspirational webpages DataTransfer: setData() method, thanks …

The DataTransfer.setData() method sets the drag operation’s drag data to the specified data and type. If data for the given type does not exist, it is added at the end of the drag data store, such that the last item in the types list will be the new type. If data for the given type already exists, the existing data is replaced in the same position. That is, the order of the types list is not changed when replacing data of the same type.

… to get us going with our “proof of concept” web application (also shown below) using these techniques, about which we think some of you readers will be interested?!

If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , | Leave a comment

Applying Onpageshow and Onpagehide and Onvisibilitychange Events Tutorial

Applying Onpageshow and Onpagehide and Onvisibilitychange Events Tutorial

Applying Onpageshow and Onpagehide and Onvisibilitychange Events Tutorial

Yesterday’s Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial was held off for a while by us, because we couldn’t think of a good and useful application of these events. But one occurred to us when we saw …

  • on a webpage … that was …
  • playing a video … when we …
  • left it to open another tab’s webpage for that web browser … then …
  • on revisiting the first webpage its Javascript had paused the video that was playing (and waited for us to restart, as required)

… to inspire us to use newly introduced onpageshow and onpagehide and onvisibilitychange events in Video File Browse Preview Tutorial‘s web application in its changed video_browse_preview.html form, except our version goes

  • on web application webpage … that can be
  • playing a video … when we …
  • left it to open another tab’s webpage for that web browser … then …
  • on revisiting the first webpage its Javascript had paused the video that was playing (and we restart the playing video, rather than have it be that we waited for us to restart, as required)

The status of all this is reflected by our webpage’s document.title on its web browser tab.


Previous relevant Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial is shown below.

Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial

Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial

Today, we discuss alternative event ideas to document.body onload and onunload events tracing the navigating to and from a webpage, respectively.

The three event types we’ve experimented with, today, in our proof of concept HTML and Javascript pageTransitions.html, are, with mixed success …

  1. onpageshow (at same time as document.body onload event) … opening … versus … closing …
  2. onpagehide (we had little success with this event) … and we had more success with …
  3. onvisibilitychange (in conjunction with document.visibilityState === “hidden” we succeeded)


<html>
<head>
<title>Page Transitions - RJM Programming - June, 2023 ... thanks to https://www.w3schools.com/jsref/event_onpageshow.asp and https://www.w3schools.com/jsref/event_onpagehide.asp</title>
<script type=text/javascript>

function myFunction(opening) {
if (opening) {
document.getElementById("mya").href = document.URL.split('?')[0].split('#')[0] + '?rand=' + Math.floor(Math.random() * 19877654);
document.title='You got to ' + document.URL + ' at ' + ('' + new Date()) + '.';
document.getElementById("myh1").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='lightgreen';
} else {
document.title='You left ' + document.URL + ' at ' + ('' + new Date()) + '.';
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
}
}

function myCloseFunction() {
if (document.visibilityState === "hidden") {
document.title='You Left ' + document.URL + ' At ' + ('' + new Date()) + '.';
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
} else {
myFunction(true);
}
}

document.onvisibilitychange = function() {
if (document.visibilityState === "hidden") {
document.title='You Left ' + document.URL + ' At ' + ('' + new Date()) + '.'
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
} else {
myFunction(true);
}
};

document.onpagehide = function() {
if (document.visibilityState === "hidden") {
document.title='You Left ' + document.URL + ' at ' + ('' + new Date()) + '.';
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
} else {
myFunction(true);
}
};

</script>
</head>
<body onvisibilitychange="myCloseFunction();" onpagehide="myFunction(false);" onpageshow="myFunction(true);">
<h1 id=myh1></h1><br><br>
<a target=_blank id=mya href=''>Open new webpage incarnation ...</a><br><br>
<h4 id=solong></h4><br><br>
</body>
</html>

So feel free to try these means by which you can welcome and plan for leaving respectively in web application.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in Animation, eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial

Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial

Onpageshow and Onpagehide and Onvisibilitychange Events Primer Tutorial

Today, we discuss alternative event ideas to document.body onload and onunload events tracing the navigating to and from a webpage, respectively.

The three event types we’ve experimented with, today, in our proof of concept HTML and Javascript pageTransitions.html, are, with mixed success …

  1. onpageshow (at same time as document.body onload event) … opening … versus … closing …
  2. onpagehide (we had little success with this event) … and we had more success with …
  3. onvisibilitychange (in conjunction with document.visibilityState === “hidden” we succeeded)


<html>
<head>
<title>Page Transitions - RJM Programming - June, 2023 ... thanks to https://www.w3schools.com/jsref/event_onpageshow.asp and https://www.w3schools.com/jsref/event_onpagehide.asp</title>
<script type=text/javascript>

function myFunction(opening) {
if (opening) {
document.getElementById("mya").href = document.URL.split('?')[0].split('#')[0] + '?rand=' + Math.floor(Math.random() * 19877654);
document.title='You got to ' + document.URL + ' at ' + ('' + new Date()) + '.';
document.getElementById("myh1").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='lightgreen';
} else {
document.title='You left ' + document.URL + ' at ' + ('' + new Date()) + '.';
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
}
}

function myCloseFunction() {
if (document.visibilityState === "hidden") {
document.title='You Left ' + document.URL + ' At ' + ('' + new Date()) + '.';
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
} else {
myFunction(true);
}
}

document.onvisibilitychange = function() {
if (document.visibilityState === "hidden") {
document.title='You Left ' + document.URL + ' At ' + ('' + new Date()) + '.'
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
} else {
myFunction(true);
}
};

document.onpagehide = function() {
if (document.visibilityState === "hidden") {
document.title='You Left ' + document.URL + ' at ' + ('' + new Date()) + '.';
document.getElementById("solong").innerHTML+='<br>' + document.title;
document.body.style.backgroundColor='yellow';
} else {
myFunction(true);
}
};

</script>
</head>
<body onvisibilitychange="myCloseFunction();" onpagehide="myFunction(false);" onpageshow="myFunction(true);">
<h1 id=myh1></h1><br><br>
<a target=_blank id=mya href=''>Open new webpage incarnation ...</a><br><br>
<h4 id=solong></h4><br><br>
</body>
</html>

So feel free to try these means by which you can welcome and plan for leaving respectively in web application.

If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , | Leave a comment

Ants Up a Wall Game Top Border Tutorial

Ants Up a Wall Game Top Border Tutorial

Ants Up a Wall Game Top Border Tutorial

Today’s aim, onto yesterday’s Ants Up a Wall Game Background Tutorial, entailed …

… among anything else we achieve, in amongst that, place a slim “platform” up the top of the wall, to place the food, and distinctly separate any realia from game elements …

… if you get our gist?!

Now, we’ve researched “border image” functionality before, but even so, these ideas don’t always work. Today we had a …

… any “border image” solution must only affect “border top” …

… and, believe it or not, this did cause us grief enough, so that our favoured “border image” with a “linear gradient” preferred solution was just out of reach, in favour of a solution just with a straight “border top colour” solution, only, working for us. So sad! Even so, we find an aesthetic improvement looking at the end results (each animal has its own coloured “platform”).

In picking a suitable “platform” colour we found more use for macOS’s Digital Colour Meter desktop application, as we talked about at Digital Colour Meter on Mac Laptop Tutorial, in finding suitable colours hovering over those third party background images (with our mouse (not the animal)).

In the end we almost got to that “border image” solution via CSS …

<style>

#wall {
position: absolute;
left: 0px;
top: calc(100% - 550px);
width: 100%;
z-index: 0;
border-style: solid;
border-width: 3px 0px 0px 0px;
border-image-slice: 1;
border-image-repeat: stretch none none none;
border-image-source: linear-gradient(to left, rgba(0,0,0,1) 1%,rgba(0,0,0,1) 50%,rgba(0,0,0,1) 100%) transparent transparent transparent;

border-bottom: 550px solid rgba(127,0,0,0.3);
background-color: rgba(192,192,192,0.1);
background-image: linear-gradient(335deg, rgba(176,0,0,0.1) 23px, transparent 23px),
linear-gradient(155deg, rgba(208,0,0,0.1) 1px, transparent 23px),
linear-gradient(335deg, rgba(176,0,0,0.1) 23px, transparent 23px),
linear-gradient(155deg, rgba(208,0,0,0.1) 23px, transparent 23px);
background-size: 58px 58px;
background-position: 0px 2px, 4px 5px, 29px 31px, 34px 6px;
/* border-top-image-slice: 1;
border-top-style: solid;
border-top-width: 3px;
-webkit-border-top-image: -webkit-linear-gradient(left,rgba(0,0,0,1) 1%,rgba(0,255,255,1) 50%,rgba(0,0,0,1) 100%) 0 0 100% 0/0 0 3px 0 stretch;
-moz-border-top-image: -moz-linear-gradient(left,rgba(0,0,0,1) 1%,rgba(0,255,255,1) 50%,rgba(0,0,0,1) 100%) 0 0 100% 0/0 0 3px 0 stretch;
-o-border-top-image: -o-linear-gradient(left,rgba(0,0,0,1) 1%,rgba(0,255,255,1) 50%,rgba(0,0,0,1) 100%) 0 0 100% 0/0 0 3px 0 stretch;
border-top-image: linear-gradient(to left,rgba(0,255,0,1) 1%,rgba(0,255,255,1) 50%,rgba(0,255,0,1) 100%) 0 0 100% 0/0 0 3px 0 stretch;
*/
/*
border-top: 2px solid #cccccc;
*/
border-top-color: rgba(176,0,0,0.1);
}

</style>

… and applied the individualized “animal” sensitive styling via Javascript DOM, like (the caterpillar’s) …


document.getElementById('dnewst').innerHTML+='<style> #wall { border-top-color: rgba(0,255,0,0.6); } </style>';

And as a way to not have the background imagery “take over”, on occasions, we started applying “background image only” opacity, as with the Javascript DOM (for the sloth) like …


document.getElementById('wall').style.opacity='0.7';

… possible, as this simple idea, because the “wall” element is separate to the element containing the “animal emojis” and header parts of the webpage, in the changed ants_up_the_wall.html “Ants Up a Wall” game, we hope. And again, you might want to look at those recent Javascript variables again in a oteote and plural “tell a story” code difference report.


Previous relevant Ants Up a Wall Game Background Tutorial is shown below.

Ants Up a Wall Game Background Tutorial

Ants Up a Wall Game Background Tutorial

Further to yesterday’s Ants Up a Wall Game Genericization Tutorial we wanted to point out, regarding many online games, how important backgrounds are. We’ve got seven featured emoji animals now with our “genericization drive”, as it stands today, and each animal has a different background (involving Javascript DOM code) we are going to tabularize for your scrutiny, and interest (in that you can click white cells to show a version of the backgrounding here), below …

🐒 Monkeys
document.getElementById(‘wall’).style.background=’ conic-gradient(from 60deg at 66.5% 100%, #dce9ef 0 30deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 270deg at 33.5% 100%, #7d9099 0 30deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), radial-gradient(circle at 99.5% 53%, #142f3c 0 calc(3.12vmin * 1.65), #fff0 calc(3.12vmin * 1.65 + 1px) 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), radial-gradient(circle at 0.5% 53%, #142f3c 0 calc(3.12vmin * 1.65), #fff0 calc(3.12vmin * 1.65 + 1px) 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), radial-gradient(circle at 50% 100%, #142f3c 0 calc(3.12vmin * 1.65), #fff0 calc(3.12vmin * 1.65 + 1px) 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 120deg at 50% 50%, #2a4856 0 120deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 90deg at 82.85% 50.5%, #142f3c 0 90deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 180deg at 17.15% 50.5%, #142f3c 0 90deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 120deg at 50% 17.5%, #7d9099 0 60deg, #dce9ef 0 120deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), linear-gradient(90deg, #fff0 0 33.5%, #142f3c 0 66.5%, #fff0 0 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 0deg at 50% 50%, #dce9ef 0 60.5deg, #2a4856 0 299.5deg, #7d9099 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71)’;
🦀 Crabs
document.getElementById(‘wall’).style.background=’URL(//www.rjmprogramming.com.au/HTMLCSS/crab_wall_two.jpg)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐝 Bees
document.getElementById(‘wall’).style.background=’URL(//img.freepik.com/free-vector/honey-comb-pattern_225004-641.jpg?w=900&t=st=1688364826~exp=1688365426~hmac=b41d4c8905719fbe44c07a0cac87f4783dccf193f85f79c029a98f9e6c032359)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐞 Ladybirds
document.getElementById(‘wall’).style.background=’URL(//jooinn.com/images/green-leaf-tree-15.jpg)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐨 Koalas
document.getElementById(‘wall’).style.background=’URL(//upload.wikimedia.org/wikipedia/commons/c/c7/Blue_Gum_Forest_Blue_Sky.jpg)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐼 Pandas
document.getElementById(‘wall’).style.background=’URL(//img.freepik.com/free-vector/bamboo_1308-3828.jpg?w=740&t=st=1688368840~exp=1688369440~hmac=431a49cf1c5597e535cf87ef9398dde5dfa74b183130c066fe6bb254245ba28e)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐜 Ants
document.getElementById(‘wall’).style.background=”;

document.getElementById(‘wall’).style.backgroundImage=’ linear-gradient(335deg, rgba(176,0,0,0.1) 23px, transparent 23px),linear-gradient(155deg, rgba(208,0,0,0.1) 1px, transparent 23px),linear-gradient(335deg, rgba(176,0,0,0.1) 23px, transparent 23px),linear-gradient(155deg, rgba(208,0,0,0.1) 23px, transparent 23px)’;

… stretching the concept of a “wall”, but adding to the interest in the changed ants_up_the_wall.html “Ants Up a Wall” game, we hope. And again, you might want to look at those recent Javascript variables again in a oteote and plural “tell a story” code difference report.


Previous relevant Ants Up a Wall Game Genericization Tutorial is shown below.

Ants Up a Wall Game Genericization Tutorial

Ants Up a Wall Game Genericization Tutorial

We think, around here, that it is best to have a web application settled into working on the platforms you want it to, ahead of any “genericization drives”, like we try starting out on today, with the “Ants Up a Wall” web application, of the recent Ants Up a Wall Game Mobile Tutorial.

Our “genericization drive”, as is often the case around here, concerns a “hardcoding” in web application workings or assumptions to “a more multi faceted” or “parametised” and “user controllable” improvement.

Today’s “hardcoding” is “Ants” and the genericizations revolve around … anyone, anyone? … no, Levi … we don’t need that smart a… answer of “pants” … so, anyone, anyone? … yes, David, indeed, a list of animals.

And yes, there are two variables that “tell a story, called oteote and plural regarding what we needed to do to make this happen in our changed ants_up_the_wall.html “Ants Up a Wall” game that are heavily involved in the functionality surrounding a new “user controlled” dropdown (ie. select) element (involving new option “Monkeys”, as our “proof of concept” cab off the rank, here) …


<select title='Thanks to https://werner-zenk.de/css/farbverlauf_mit_css2.php' onclick="event.stopPropagation();" id=sanimal onchange=newanimal(this.value);><option id=oants title='Thanks to https://werner-zenk.de/css/farbverlauf_mit_css2.php' value=''>&#128028; Ants</option><option id=omonkeys title='Thanks to https://codepen.io/josetxu/pen/poLoayv' value=128018>&#128018; Monkeys</option></select>

… where, once, there were just ants!


Previous relevant Ants Up a Wall Game Mobile Tutorial is shown below.

Ants Up a Wall Game Mobile Tutorial

Ants Up a Wall Game Mobile Tutorial

We can’t remember when we first coded the “Ants Up a Wall” game à la Ants Up a Wall Game Snapshots Tutorial, but playing it, as of yesterday’s version, it was “not pretty” on our iPhone device.

The “Wall” in mobile portrait orientation was too low down and too high up in landscape, then “Goldilocks” (more like “very few locks”) has come along today to make the “Wall” just right. And speaking of “right” (or is that “right”), for mobile, the errant ants that wander off to the right caused viewport disruption, as it is very disconcerting on a game asking for you to click ants, be challenged by a “moving Wall”!

The “Wall” (on smaller mobile platforms) positional fix has been made mainly via new CSS …

<style>

/* The rest of the previous CSS here remains untouched ... then ... */

@media only screen and (min-device-width: 320px) and (max-device-width: 865px) and (orientation: portrait) {
.atboXttom {
top: 200px;
}

#wall {
top: 218px;
height: calc(100vh - 218px);
}
}

@media only screen and (min-device-width: 320px) and (max-device-width: 765px) and (orientation: landscape) {
.atboXttom {
top: 200px;
}

#wall {
top: 218px;
height: calc(100vh - 218px);
}
}

</style>

… as a CSS approach to add device dimensions into the mix for the “Cascading” bit of CSS (Cascading Style Sheet).

You can try all this with our changed ants_up_the_wall.html “Ants Up a Wall” game.


Previous relevant Ants Up a Wall Game Snapshots Tutorial is shown below.

Ants Up a Wall Game Snapshots Tutorial

Ants Up a Wall Game Snapshots Tutorial

It occurred to us that …

… to allow our game to optionally record game snapshots into document.body global data attributes, as another way to harness …

  • parent webpage …
  • has document.body global data attribute “snapshots” dynamically created …
  • that can be recalled via a user controllable dropdown … and passed onto …
  • a new game can be “window.open”ed establishing a “window.opener” link in the new game child window (back to the parent) …
  • in order to be able to retain the “snapshots” among “Ants Up the Wall” game runs

Yes, data is passing between webpages, but it is that nuance more sophisticated than your usual “window.open”ed establishing a “window.opener” link arrangement.

You can try all this with our changed ants_up_the_wall.html “Ants Up a Wall” game featuring new Javascript as below …


function showtval(tvalis) {
try {
if (tvalis.trim() != '') {
var woois=window.open('', '_blank', 'top=0,left=0,width=' + screen.width + ',height=' + screen.height);
//woois.document.write('<html><head>' + document.head.innerHTML + '</head><body>' + window.atob(document.body.getAttribute(tvalis)) + '</body></html>');
woois.document.write('<html><head>' + document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head><body>' + decodeURIComponent(document.body.getAttribute(tvalis)) + '</body></html>');
document.getElementById('selsnapshots').value='';
}
} catch(hfgdhg) {
}
}

function involvednewgame() {
//goes=0;
woois=window.open('', '_blank'); //, 'top=0,left=0,width=' + screen.width + ',height=' + screen.height);
//woois.document.write('<html><head>' + document.head.innerHTML + '</head><body>' + window.atob(document.body.getAttribute(tvalis)) + '</body></html>');
woois.document.write('<html><head>' + fixsome(document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head>' + document.body.outerHTML.replace(document.getElementById('custom-alert-1').outerHTML,'')) + '</html>');
//woois.document.write('<html><head>' + document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head>' + document.body.outerHTML.split('>')[0] + '>' + byih + '</body></html>');
}

function makesnapshot() {
if (document.getElementById('selsnapshots') && !woois && !gwoois && notnew) {
var inlabis='' + (new Date());
var labis=('data-' + inlabis).replace(/\:/g,'_').replace(/\//g,'_').replace(/\ /g,'_').replace(/\./g,'_').replace(/\+/g,'_').replace(/\)/g,'_').replace(/\(/g,'_');
//document.body.setAttribute(labis, window.btoa(document.body.innerHTML));
document.body.setAttribute(labis, encodeURIComponent(document.body.innerHTML));
document.getElementById('oreadyfor').innerHTML=document.getElementById('oreadyfor').getAttribute('data-prefix') + 'last was at ' + inlabis + ') of ants at ...';
document.getElementById('selsnapshots').innerHTML+='<option value="' + labis + '">' + inlabis + '</option>';
//ngblurb='<button style=color:orange;z-index:9987; onclick=involvednewgame();>game</button> ';
//ngblurb='game via header link click ';
ngblurb='<a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> (or via header link click above to retain snapshots) ';

document.getElementById('custom-alert-1').onclick=function() { notnew=false; location.href=document.URL.split('#')[0].split('?')[0] + ffa; };
}
}

function doshot(itv) {
if (eval('' + itv) > 0) {
document.getElementById('mysnapshots').innerHTML='<select id=selsnapshots onchange="showtval(this.value);"><option data-prefix="See ' + itv + ' sec' + 'ond snapshots (" id=oreadyfor value="">Se' + 'e ' + itv + ' sec' + 'ond snapshots (first yet to come) of ants at ...</option></select>';
setInterval(makesnapshot, Math.round(eval(1000.0 * eval('' + itv))));
}
}

function fixsome(inidea) {
var outidea=inidea;
var onls=inidea.split('<bo' + 'dy onload="');
var onlstwo=inidea.split('</s' + 'cript>');
var onlstuff='';
if (eval('' + onls.length) > 1 && eval('' + onlstwo.length) > 1) {
onlstuff=onls[1].split('"')[0];
outidea=outidea.replace(onlstwo[0], onlstwo[0] + String.fromCharCode(10) + ' function onlis() { ' + onlstuff + ' } ' + String.fromCharCode(10) + ' setTimeout(onlis, 2000); ' + String.fromCharCode(10));
outidea=outidea.replace('<bo' + 'dy onload="', '<bo' + 'dy data-onload="');
outidea=outidea.replace('cal' + 'c(100% - 10px)', '' + eval(-10 + screen.width) + 'px');
outidea=outidea.replace('cal' + 'c(100% - 28px)', '' + eval(-28 + screen.height) + 'px');
}
return outidea;
}

function lfd() {
var datas=[], idatas=0;
if (window.opener) {
document.getElementById('mysnapshots').innerHTML=window.opener.document.getElementById('mysnapshots').innerHTML;
datas=window.opener.document.body.outerHTML.split('>')[0].split(' data-');
for (idatas=1; idatas<datas.length; idatas++) {
document.body.setAttribute('data-' + datas[idatas].split('=')[0], datas[idatas].split('="')[1].split('"')[0]);
}
setInterval(makesnapshot, Math.round(eval(1000.0 * eval('' + document.getElementById('mysnapshots').innerHTML.split('>Se' + 'e ')[1].split(' ')[0] ))));
//alert('Good');
} else if (document.head.innerHTML.indexOf('calc(1' + '00% - 550px)') == -1) {
//alert('good');
startx=-1;
starty=-1;
goes=20;
score=0;
slowants=1000;
document.getElementById('rest').innerHTML='';
document.getElementById('status').innerHTML='';
document.getElementById('score').innerHTML="Score: 0. Don't mean to scare you but there are 0 ants left looking for 20 food items. Time survived keeping food and clicking ants away: 0 seconds.";
//} else {
//alert('why? ' + document.head.innerHTML.split('<scr')[0]);
}
}


Previous relevant Ants Up a Wall Game Toast Tutorial is shown below.

Ants Up a Wall Game Toast Tutorial

Ants Up a Wall Game Toast Tutorial

Further to Ants Up a Wall Game Fixed Tutorial recent progress with our “Ants Up a Wall” game we have a single word …


"Toast"

… as a means of describing an alternative arrangement to have at the end of the game instead of the Javascript alert popup window we had previously, offering …

  • non-modal and temporary information display …
  • able to show and navigate off links …

We tweaked to this as an issue when we created an HTML iframe off our changed ants_up_the_wall.html “Ants Up a Wall” game within a WordPress blog post, and that WordPress blog “down the line” would be interrupted with an alert box informing them about the “Ants Up a Wall” game status, and the user would be held up doing whatever they were doing at the blog, until they clicked the alert popup window’s OK button. Well, with the Android “toast” inspired …

<style>

.custom-alert {
display: inline-block;
visibility: visible;
background-color: rgba(102,102,102,0.8);
color: #fff;
text-align: enter;
margin: 5% auto;
padding: 12px 28px;
}

</style>

… arrangements (also being placed into the WordPress blog Twenty Ten theme’s good ol’ header.php), that user would no longer be corralled into clicking that OK button in order to proceed, but would still get to see information on the screen regarding the relevant “Ants Up a Wall” game and have links presented to them to navigate to other webpages of interest should they please, before disappearing, as necessary, after some time

<script type=’text/javascript’>

function isecm() {
if (okay) {
isecs++;
document.getElementById('score').innerHTML="Score: " + score + ". Don't mean to scare you but there are " + eval(numants - minus) + " ants left looking for " + goes + " food items. Time survived keeping food and clicking ants away: " + isecs + " seconds.";
if (goes == 0) {
goes=-1;
okay=false;
if (1 == 2) {
alert('Congratulations on keeping some food for ' + isecs + ' seconds.');
location.href=document.URL.split('#')[0].split('?')[0];
} else {
document.getElementById('myh1').title='Click to restart';
document.getElementById('myh1').style.textDecoration='underline';
document.getElementById('myh1').style.cursor='pointer';
if (window.top) {
if (wsprefix == '') {
wsprefix=' ';
var tifs=top.document.getElementsByTagName('iframe');
for (var jtifs=0; jtifs<tifs.length; jtifs++) {
if (('' + tifs[jtifs].src).indexOf('ants_up_the_wall.htm') != -1) {
if (('' + tifs[jtifs].id) != '') {
wsprefix='<a style=color:lightgreen; href="#' + tifs[jtifs].id + '">';
wssuffix='</a>';
} else {
var gbcr=tifs[jtifs].getBoundingClientRect();
wsprefix='<a style="cursor:pointer;text-decoration:underline;color:lightgreen;" onclick=" window.top.scroll(0,' + gbcr.top + '); ">';
wssuffix='</a>';
}
}
}
}
if (top.document.getElementById('custom-alert-1')) {
top.document.getElementById('custom-alert-1').innerHTML="Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.";
top.document.getElementById('custom-alert-1').style.display='inline';
top.document.getElementById('custom-alert-1').style.visibility='visible';
} else {
top.document.body.innerHTML+="<div id='custom-alert-1' class='custom-alert' style='visibility: visible;display: inline;'>Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.</div>";
}
setTimeout(top.document.hideIt, 10000);
} else {
if (document.getElementById('custom-alert-1')) {
document.getElementById('custom-alert-1').innerHTML="Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix + "title" + wssuffix.trim() + " for another game.";
document.getElementById('custom-alert-1').style.display='inline';
document.getElementById('custom-alert-1').style.visibility='visible';
} else {
document.body.innerHTML+="<div id='custom-alert-1' class='custom-alert' style='visibility: visible;display: inline;'>Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.</div>";
}
setTimeout(hideIt, 10000);
}
// setTimeout(hideIt, 10000);
}
// location.href=document.URL.split('#')[0].split('?')[0];

}
}
}

function hideIt() {
if (window.top) {
if (top.document.getElementById('custom-alert-1')) {
top.document.getElementById('custom-alert-1').style.display='none';
top.document.getElementById('custom-alert-1').style.visibility='hidden';
}
} else {
if (document.getElementById('custom-alert-1')) {
document.getElementById('custom-alert-1').style.display='none';
document.getElementById('custom-alert-1').style.visibility='hidden';
}
}
}

function cthen() {
goes=0;
location.href=document.URL.split('#')[0].split('?')[0] + ffa;
}


</script>

Today, also there are “Ants Up a Wall” game modes of play (with Javascript logics working with an “ant production” timer codeline now goes setTimeout(moveants,slowants);) that go …

<script type=’text/javascript’>

var slowants=1000;
var ffa=(location.search.split('ffa=')[1] ? decodeURIComponent(location.search.split('ffa=')[1]).split('&')[0] : '');

function oureval(inev, osel) {
if (inev != '') {
if (inev == '100') {
document.getElementById('adjective').innerHTML='Fewer Faster ';
ffa='?ffa=ffa';
} else if (inev == '500') {
document.getElementById('adjective').innerHTML='Half Paced ';
ffa='?ffa=hp';
} else if (inev == '50') {
document.getElementById('adjective').innerHTML='Hard to Handle ';
ffa='?ffa=hth';
} else if (inev == '1000') {
document.getElementById('adjective').innerHTML='Many Slow ';
ffa='?ffa=ms';
}
slowants=eval(inev);
osel.value='';
}
}

function doffa() {
if (ffa != '') {
if (ffa == 'ffa') {
document.getElementById('adjective').innerHTML='Fewer Faster ';
slowants=eval('100');
ffa='?ffa=ffa';
} else if (ffa == 'hp') {
document.getElementById('adjective').innerHTML='Half Paced ';
slowants=eval('500');
ffa='?ffa=hp';
} else if (ffa == 'hth') {
document.getElementById('adjective').innerHTML='Hard to Handle ';
slowants=eval('50');
ffa='?ffa=hth';
} else if (ffa == 'ms') {
document.getElementById('adjective').innerHTML='Many Slow ';
slowants=eval('1000');
ffa='?ffa=ms';
}
}
}

</script>

… the point being that with some of these modes of play the ant movement feels a bit smoother, and more real!


Previous relevant Ants Up a Wall Game Primer Tutorial is shown below.

Ants Up a Wall Game Primer Tutorial

Ants Up a Wall Game Primer Tutorial

We’d like to thank the brick wall inspiration of this very useful link we talked about yesterday with CSS Style Display and Visibility Tall Poppies Tutorial for the reason to take on our “Ants Up a Wall” game today.

Today, though, we arrange it that the wall sits down the bottom of the screen, where, as you would all know, any self respecting ant will emerge from, if they take an interest in your computer equipment.

Your mission, Jim, should you decide to accept it is to protect your food supplies on the wall from marauding ants. We’ve assembled a crack team for you, Jim, or you can come up with your own Bee Team (chortle, chortle). As always, should you or any of your I.M. Force be caught or killed, the Secretary will disavow any knowledge of your actions.

Aspects of today’s “Ants Up a Wall” game’s HTML and Javascript and CSS ants_up_the_wall.html source code for your perusal …

  • brick wall inspired as above, thanks, and represented as an HTML hr (horizontal rule) element, positioned via use of …
  • CSS calc
  • CSS rotation
  • Javascript Object OOP style syntax … for a …
  • data structure which is an Array of Javascript (Ant) objects … and as for yesterday’s game, all of …
  • (Math.floor(Math.random() * [integerRange]) +/- [integerOffset]) // randomosity aid
  • setTimeout (and setInterval (to derive a “seconds elapsed” idea to the game)) timer methods … and, lately, at least …
  • Emoji usage

The marauding ants need a limit of their numbers, in case users leave the web application running forever, and that is where we relieve memory requirements by using the delete (array member) method of keeping the (array) indexes constant but save on memory requirements over time.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in Animation, eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Ants Up a Wall Game Background Tutorial

Ants Up a Wall Game Background Tutorial

Ants Up a Wall Game Background Tutorial

Further to yesterday’s Ants Up a Wall Game Genericization Tutorial we wanted to point out, regarding many online games, how important backgrounds are. We’ve got seven featured emoji animals now with our “genericization drive”, as it stands today, and each animal has a different background (involving Javascript DOM code) we are going to tabularize for your scrutiny, and interest (in that you can click white cells to show a version of the backgrounding here), below …

🐒 Monkeys
document.getElementById(‘wall’).style.background=’ conic-gradient(from 60deg at 66.5% 100%, #dce9ef 0 30deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 270deg at 33.5% 100%, #7d9099 0 30deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), radial-gradient(circle at 99.5% 53%, #142f3c 0 calc(3.12vmin * 1.65), #fff0 calc(3.12vmin * 1.65 + 1px) 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), radial-gradient(circle at 0.5% 53%, #142f3c 0 calc(3.12vmin * 1.65), #fff0 calc(3.12vmin * 1.65 + 1px) 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), radial-gradient(circle at 50% 100%, #142f3c 0 calc(3.12vmin * 1.65), #fff0 calc(3.12vmin * 1.65 + 1px) 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 120deg at 50% 50%, #2a4856 0 120deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 90deg at 82.85% 50.5%, #142f3c 0 90deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 180deg at 17.15% 50.5%, #142f3c 0 90deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 120deg at 50% 17.5%, #7d9099 0 60deg, #dce9ef 0 120deg, #fff0 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), linear-gradient(90deg, #fff0 0 33.5%, #142f3c 0 66.5%, #fff0 0 100%) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71), conic-gradient(from 0deg at 50% 50%, #dce9ef 0 60.5deg, #2a4856 0 299.5deg, #7d9099 0 360deg) 50%/ calc(3.12vmin * 10) calc(3.12vmin * 5.71)’;
🦀 Crabs
document.getElementById(‘wall’).style.background=’URL(//www.rjmprogramming.com.au/HTMLCSS/crab_wall_two.jpg)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐝 Bees
document.getElementById(‘wall’).style.background=’URL(//img.freepik.com/free-vector/honey-comb-pattern_225004-641.jpg?w=900&t=st=1688364826~exp=1688365426~hmac=b41d4c8905719fbe44c07a0cac87f4783dccf193f85f79c029a98f9e6c032359)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐞 Ladybirds
document.getElementById(‘wall’).style.background=’URL(//jooinn.com/images/green-leaf-tree-15.jpg)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐨 Koalas
document.getElementById(‘wall’).style.background=’URL(//upload.wikimedia.org/wikipedia/commons/c/c7/Blue_Gum_Forest_Blue_Sky.jpg)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐼 Pandas
document.getElementById(‘wall’).style.background=’URL(//img.freepik.com/free-vector/bamboo_1308-3828.jpg?w=740&t=st=1688368840~exp=1688369440~hmac=431a49cf1c5597e535cf87ef9398dde5dfa74b183130c066fe6bb254245ba28e)’;

document.getElementById(‘wall’).style.backgroundRepeat=’no-repeat’;

document.getElementById(‘wall’).style.backgroundSize=’cover’;
🐜 Ants
document.getElementById(‘wall’).style.background=”;

document.getElementById(‘wall’).style.backgroundImage=’ linear-gradient(335deg, rgba(176,0,0,0.1) 23px, transparent 23px),linear-gradient(155deg, rgba(208,0,0,0.1) 1px, transparent 23px),linear-gradient(335deg, rgba(176,0,0,0.1) 23px, transparent 23px),linear-gradient(155deg, rgba(208,0,0,0.1) 23px, transparent 23px)’;

… stretching the concept of a “wall”, but adding to the interest in the changed ants_up_the_wall.html “Ants Up a Wall” game, we hope. And again, you might want to look at those recent Javascript variables again in a oteote and plural “tell a story” code difference report.


Previous relevant Ants Up a Wall Game Genericization Tutorial is shown below.

Ants Up a Wall Game Genericization Tutorial

Ants Up a Wall Game Genericization Tutorial

We think, around here, that it is best to have a web application settled into working on the platforms you want it to, ahead of any “genericization drives”, like we try starting out on today, with the “Ants Up a Wall” web application, of the recent Ants Up a Wall Game Mobile Tutorial.

Our “genericization drive”, as is often the case around here, concerns a “hardcoding” in web application workings or assumptions to “a more multi faceted” or “parametised” and “user controllable” improvement.

Today’s “hardcoding” is “Ants” and the genericizations revolve around … anyone, anyone? … no, Levi … we don’t need that smart a… answer of “pants” … so, anyone, anyone? … yes, David, indeed, a list of animals.

And yes, there are two variables that “tell a story, called oteote and plural regarding what we needed to do to make this happen in our changed ants_up_the_wall.html “Ants Up a Wall” game that are heavily involved in the functionality surrounding a new “user controlled” dropdown (ie. select) element (involving new option “Monkeys”, as our “proof of concept” cab off the rank, here) …


<select title='Thanks to https://werner-zenk.de/css/farbverlauf_mit_css2.php' onclick="event.stopPropagation();" id=sanimal onchange=newanimal(this.value);><option id=oants title='Thanks to https://werner-zenk.de/css/farbverlauf_mit_css2.php' value=''>&#128028; Ants</option><option id=omonkeys title='Thanks to https://codepen.io/josetxu/pen/poLoayv' value=128018>&#128018; Monkeys</option></select>

… where, once, there were just ants!


Previous relevant Ants Up a Wall Game Mobile Tutorial is shown below.

Ants Up a Wall Game Mobile Tutorial

Ants Up a Wall Game Mobile Tutorial

We can’t remember when we first coded the “Ants Up a Wall” game à la Ants Up a Wall Game Snapshots Tutorial, but playing it, as of yesterday’s version, it was “not pretty” on our iPhone device.

The “Wall” in mobile portrait orientation was too low down and too high up in landscape, then “Goldilocks” (more like “very few locks”) has come along today to make the “Wall” just right. And speaking of “right” (or is that “right”), for mobile, the errant ants that wander off to the right caused viewport disruption, as it is very disconcerting on a game asking for you to click ants, be challenged by a “moving Wall”!

The “Wall” (on smaller mobile platforms) positional fix has been made mainly via new CSS …

<style>

/* The rest of the previous CSS here remains untouched ... then ... */

@media only screen and (min-device-width: 320px) and (max-device-width: 865px) and (orientation: portrait) {
.atboXttom {
top: 200px;
}

#wall {
top: 218px;
height: calc(100vh - 218px);
}
}

@media only screen and (min-device-width: 320px) and (max-device-width: 765px) and (orientation: landscape) {
.atboXttom {
top: 200px;
}

#wall {
top: 218px;
height: calc(100vh - 218px);
}
}

</style>

… as a CSS approach to add device dimensions into the mix for the “Cascading” bit of CSS (Cascading Style Sheet).

You can try all this with our changed ants_up_the_wall.html “Ants Up a Wall” game.


Previous relevant Ants Up a Wall Game Snapshots Tutorial is shown below.

Ants Up a Wall Game Snapshots Tutorial

Ants Up a Wall Game Snapshots Tutorial

It occurred to us that …

… to allow our game to optionally record game snapshots into document.body global data attributes, as another way to harness …

  • parent webpage …
  • has document.body global data attribute “snapshots” dynamically created …
  • that can be recalled via a user controllable dropdown … and passed onto …
  • a new game can be “window.open”ed establishing a “window.opener” link in the new game child window (back to the parent) …
  • in order to be able to retain the “snapshots” among “Ants Up the Wall” game runs

Yes, data is passing between webpages, but it is that nuance more sophisticated than your usual “window.open”ed establishing a “window.opener” link arrangement.

You can try all this with our changed ants_up_the_wall.html “Ants Up a Wall” game featuring new Javascript as below …


function showtval(tvalis) {
try {
if (tvalis.trim() != '') {
var woois=window.open('', '_blank', 'top=0,left=0,width=' + screen.width + ',height=' + screen.height);
//woois.document.write('<html><head>' + document.head.innerHTML + '</head><body>' + window.atob(document.body.getAttribute(tvalis)) + '</body></html>');
woois.document.write('<html><head>' + document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head><body>' + decodeURIComponent(document.body.getAttribute(tvalis)) + '</body></html>');
document.getElementById('selsnapshots').value='';
}
} catch(hfgdhg) {
}
}

function involvednewgame() {
//goes=0;
woois=window.open('', '_blank'); //, 'top=0,left=0,width=' + screen.width + ',height=' + screen.height);
//woois.document.write('<html><head>' + document.head.innerHTML + '</head><body>' + window.atob(document.body.getAttribute(tvalis)) + '</body></html>');
woois.document.write('<html><head>' + fixsome(document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head>' + document.body.outerHTML.replace(document.getElementById('custom-alert-1').outerHTML,'')) + '</html>');
//woois.document.write('<html><head>' + document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head>' + document.body.outerHTML.split('>')[0] + '>' + byih + '</body></html>');
}

function makesnapshot() {
if (document.getElementById('selsnapshots') && !woois && !gwoois && notnew) {
var inlabis='' + (new Date());
var labis=('data-' + inlabis).replace(/\:/g,'_').replace(/\//g,'_').replace(/\ /g,'_').replace(/\./g,'_').replace(/\+/g,'_').replace(/\)/g,'_').replace(/\(/g,'_');
//document.body.setAttribute(labis, window.btoa(document.body.innerHTML));
document.body.setAttribute(labis, encodeURIComponent(document.body.innerHTML));
document.getElementById('oreadyfor').innerHTML=document.getElementById('oreadyfor').getAttribute('data-prefix') + 'last was at ' + inlabis + ') of ants at ...';
document.getElementById('selsnapshots').innerHTML+='<option value="' + labis + '">' + inlabis + '</option>';
//ngblurb='<button style=color:orange;z-index:9987; onclick=involvednewgame();>game</button> ';
//ngblurb='game via header link click ';
ngblurb='<a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> (or via header link click above to retain snapshots) ';

document.getElementById('custom-alert-1').onclick=function() { notnew=false; location.href=document.URL.split('#')[0].split('?')[0] + ffa; };
}
}

function doshot(itv) {
if (eval('' + itv) > 0) {
document.getElementById('mysnapshots').innerHTML='<select id=selsnapshots onchange="showtval(this.value);"><option data-prefix="See ' + itv + ' sec' + 'ond snapshots (" id=oreadyfor value="">Se' + 'e ' + itv + ' sec' + 'ond snapshots (first yet to come) of ants at ...</option></select>';
setInterval(makesnapshot, Math.round(eval(1000.0 * eval('' + itv))));
}
}

function fixsome(inidea) {
var outidea=inidea;
var onls=inidea.split('<bo' + 'dy onload="');
var onlstwo=inidea.split('</s' + 'cript>');
var onlstuff='';
if (eval('' + onls.length) > 1 && eval('' + onlstwo.length) > 1) {
onlstuff=onls[1].split('"')[0];
outidea=outidea.replace(onlstwo[0], onlstwo[0] + String.fromCharCode(10) + ' function onlis() { ' + onlstuff + ' } ' + String.fromCharCode(10) + ' setTimeout(onlis, 2000); ' + String.fromCharCode(10));
outidea=outidea.replace('<bo' + 'dy onload="', '<bo' + 'dy data-onload="');
outidea=outidea.replace('cal' + 'c(100% - 10px)', '' + eval(-10 + screen.width) + 'px');
outidea=outidea.replace('cal' + 'c(100% - 28px)', '' + eval(-28 + screen.height) + 'px');
}
return outidea;
}

function lfd() {
var datas=[], idatas=0;
if (window.opener) {
document.getElementById('mysnapshots').innerHTML=window.opener.document.getElementById('mysnapshots').innerHTML;
datas=window.opener.document.body.outerHTML.split('>')[0].split(' data-');
for (idatas=1; idatas<datas.length; idatas++) {
document.body.setAttribute('data-' + datas[idatas].split('=')[0], datas[idatas].split('="')[1].split('"')[0]);
}
setInterval(makesnapshot, Math.round(eval(1000.0 * eval('' + document.getElementById('mysnapshots').innerHTML.split('>Se' + 'e ')[1].split(' ')[0] ))));
//alert('Good');
} else if (document.head.innerHTML.indexOf('calc(1' + '00% - 550px)') == -1) {
//alert('good');
startx=-1;
starty=-1;
goes=20;
score=0;
slowants=1000;
document.getElementById('rest').innerHTML='';
document.getElementById('status').innerHTML='';
document.getElementById('score').innerHTML="Score: 0. Don't mean to scare you but there are 0 ants left looking for 20 food items. Time survived keeping food and clicking ants away: 0 seconds.";
//} else {
//alert('why? ' + document.head.innerHTML.split('<scr')[0]);
}
}


Previous relevant Ants Up a Wall Game Toast Tutorial is shown below.

Ants Up a Wall Game Toast Tutorial

Ants Up a Wall Game Toast Tutorial

Further to Ants Up a Wall Game Fixed Tutorial recent progress with our “Ants Up a Wall” game we have a single word …


"Toast"

… as a means of describing an alternative arrangement to have at the end of the game instead of the Javascript alert popup window we had previously, offering …

  • non-modal and temporary information display …
  • able to show and navigate off links …

We tweaked to this as an issue when we created an HTML iframe off our changed ants_up_the_wall.html “Ants Up a Wall” game within a WordPress blog post, and that WordPress blog “down the line” would be interrupted with an alert box informing them about the “Ants Up a Wall” game status, and the user would be held up doing whatever they were doing at the blog, until they clicked the alert popup window’s OK button. Well, with the Android “toast” inspired …

<style>

.custom-alert {
display: inline-block;
visibility: visible;
background-color: rgba(102,102,102,0.8);
color: #fff;
text-align: enter;
margin: 5% auto;
padding: 12px 28px;
}

</style>

… arrangements (also being placed into the WordPress blog Twenty Ten theme’s good ol’ header.php), that user would no longer be corralled into clicking that OK button in order to proceed, but would still get to see information on the screen regarding the relevant “Ants Up a Wall” game and have links presented to them to navigate to other webpages of interest should they please, before disappearing, as necessary, after some time

<script type=’text/javascript’>

function isecm() {
if (okay) {
isecs++;
document.getElementById('score').innerHTML="Score: " + score + ". Don't mean to scare you but there are " + eval(numants - minus) + " ants left looking for " + goes + " food items. Time survived keeping food and clicking ants away: " + isecs + " seconds.";
if (goes == 0) {
goes=-1;
okay=false;
if (1 == 2) {
alert('Congratulations on keeping some food for ' + isecs + ' seconds.');
location.href=document.URL.split('#')[0].split('?')[0];
} else {
document.getElementById('myh1').title='Click to restart';
document.getElementById('myh1').style.textDecoration='underline';
document.getElementById('myh1').style.cursor='pointer';
if (window.top) {
if (wsprefix == '') {
wsprefix=' ';
var tifs=top.document.getElementsByTagName('iframe');
for (var jtifs=0; jtifs<tifs.length; jtifs++) {
if (('' + tifs[jtifs].src).indexOf('ants_up_the_wall.htm') != -1) {
if (('' + tifs[jtifs].id) != '') {
wsprefix='<a style=color:lightgreen; href="#' + tifs[jtifs].id + '">';
wssuffix='</a>';
} else {
var gbcr=tifs[jtifs].getBoundingClientRect();
wsprefix='<a style="cursor:pointer;text-decoration:underline;color:lightgreen;" onclick=" window.top.scroll(0,' + gbcr.top + '); ">';
wssuffix='</a>';
}
}
}
}
if (top.document.getElementById('custom-alert-1')) {
top.document.getElementById('custom-alert-1').innerHTML="Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.";
top.document.getElementById('custom-alert-1').style.display='inline';
top.document.getElementById('custom-alert-1').style.visibility='visible';
} else {
top.document.body.innerHTML+="<div id='custom-alert-1' class='custom-alert' style='visibility: visible;display: inline;'>Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.</div>";
}
setTimeout(top.document.hideIt, 10000);
} else {
if (document.getElementById('custom-alert-1')) {
document.getElementById('custom-alert-1').innerHTML="Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix + "title" + wssuffix.trim() + " for another game.";
document.getElementById('custom-alert-1').style.display='inline';
document.getElementById('custom-alert-1').style.visibility='visible';
} else {
document.body.innerHTML+="<div id='custom-alert-1' class='custom-alert' style='visibility: visible;display: inline;'>Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.</div>";
}
setTimeout(hideIt, 10000);
}
// setTimeout(hideIt, 10000);
}
// location.href=document.URL.split('#')[0].split('?')[0];

}
}
}

function hideIt() {
if (window.top) {
if (top.document.getElementById('custom-alert-1')) {
top.document.getElementById('custom-alert-1').style.display='none';
top.document.getElementById('custom-alert-1').style.visibility='hidden';
}
} else {
if (document.getElementById('custom-alert-1')) {
document.getElementById('custom-alert-1').style.display='none';
document.getElementById('custom-alert-1').style.visibility='hidden';
}
}
}

function cthen() {
goes=0;
location.href=document.URL.split('#')[0].split('?')[0] + ffa;
}


</script>

Today, also there are “Ants Up a Wall” game modes of play (with Javascript logics working with an “ant production” timer codeline now goes setTimeout(moveants,slowants);) that go …

<script type=’text/javascript’>

var slowants=1000;
var ffa=(location.search.split('ffa=')[1] ? decodeURIComponent(location.search.split('ffa=')[1]).split('&')[0] : '');

function oureval(inev, osel) {
if (inev != '') {
if (inev == '100') {
document.getElementById('adjective').innerHTML='Fewer Faster ';
ffa='?ffa=ffa';
} else if (inev == '500') {
document.getElementById('adjective').innerHTML='Half Paced ';
ffa='?ffa=hp';
} else if (inev == '50') {
document.getElementById('adjective').innerHTML='Hard to Handle ';
ffa='?ffa=hth';
} else if (inev == '1000') {
document.getElementById('adjective').innerHTML='Many Slow ';
ffa='?ffa=ms';
}
slowants=eval(inev);
osel.value='';
}
}

function doffa() {
if (ffa != '') {
if (ffa == 'ffa') {
document.getElementById('adjective').innerHTML='Fewer Faster ';
slowants=eval('100');
ffa='?ffa=ffa';
} else if (ffa == 'hp') {
document.getElementById('adjective').innerHTML='Half Paced ';
slowants=eval('500');
ffa='?ffa=hp';
} else if (ffa == 'hth') {
document.getElementById('adjective').innerHTML='Hard to Handle ';
slowants=eval('50');
ffa='?ffa=hth';
} else if (ffa == 'ms') {
document.getElementById('adjective').innerHTML='Many Slow ';
slowants=eval('1000');
ffa='?ffa=ms';
}
}
}

</script>

… the point being that with some of these modes of play the ant movement feels a bit smoother, and more real!


Previous relevant Ants Up a Wall Game Primer Tutorial is shown below.

Ants Up a Wall Game Primer Tutorial

Ants Up a Wall Game Primer Tutorial

We’d like to thank the brick wall inspiration of this very useful link we talked about yesterday with CSS Style Display and Visibility Tall Poppies Tutorial for the reason to take on our “Ants Up a Wall” game today.

Today, though, we arrange it that the wall sits down the bottom of the screen, where, as you would all know, any self respecting ant will emerge from, if they take an interest in your computer equipment.

Your mission, Jim, should you decide to accept it is to protect your food supplies on the wall from marauding ants. We’ve assembled a crack team for you, Jim, or you can come up with your own Bee Team (chortle, chortle). As always, should you or any of your I.M. Force be caught or killed, the Secretary will disavow any knowledge of your actions.

Aspects of today’s “Ants Up a Wall” game’s HTML and Javascript and CSS ants_up_the_wall.html source code for your perusal …

  • brick wall inspired as above, thanks, and represented as an HTML hr (horizontal rule) element, positioned via use of …
  • CSS calc
  • CSS rotation
  • Javascript Object OOP style syntax … for a …
  • data structure which is an Array of Javascript (Ant) objects … and as for yesterday’s game, all of …
  • (Math.floor(Math.random() * [integerRange]) +/- [integerOffset]) // randomosity aid
  • setTimeout (and setInterval (to derive a “seconds elapsed” idea to the game)) timer methods … and, lately, at least …
  • Emoji usage

The marauding ants need a limit of their numbers, in case users leave the web application running forever, and that is where we relieve memory requirements by using the delete (array member) method of keeping the (array) indexes constant but save on memory requirements over time.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in Animation, eLearning, Event-Driven Programming, Games, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Ants Up a Wall Game Genericization Tutorial

Ants Up a Wall Game Genericization Tutorial

Ants Up a Wall Game Genericization Tutorial

We think, around here, that it is best to have a web application settled into working on the platforms you want it to, ahead of any “genericization drives”, like we try starting out on today, with the “Ants Up a Wall” web application, of the recent Ants Up a Wall Game Mobile Tutorial.

Our “genericization drive”, as is often the case around here, concerns a “hardcoding” in web application workings or assumptions to “a more multi faceted” or “parametised” and “user controllable” improvement.

Today’s “hardcoding” is “Ants” and the genericizations revolve around … anyone, anyone? … no, Levi … we don’t need that smart a… answer of “pants” … so, anyone, anyone? … yes, David, indeed, a list of animals.

And yes, there are two variables that “tell a story, called oteote and plural regarding what we needed to do to make this happen in our changed ants_up_the_wall.html “Ants Up a Wall” game that are heavily involved in the functionality surrounding a new “user controlled” dropdown (ie. select) element (involving new option “Monkeys”, as our “proof of concept” cab off the rank, here) …


<select title='Thanks to https://werner-zenk.de/css/farbverlauf_mit_css2.php' onclick="event.stopPropagation();" id=sanimal onchange=newanimal(this.value);><option id=oants title='Thanks to https://werner-zenk.de/css/farbverlauf_mit_css2.php' value=''>&#128028; Ants</option><option id=omonkeys title='Thanks to https://codepen.io/josetxu/pen/poLoayv' value=128018>&#128018; Monkeys</option></select>

… where, once, there were just ants!


Previous relevant Ants Up a Wall Game Mobile Tutorial is shown below.

Ants Up a Wall Game Mobile Tutorial

Ants Up a Wall Game Mobile Tutorial

We can’t remember when we first coded the “Ants Up a Wall” game à la Ants Up a Wall Game Snapshots Tutorial, but playing it, as of yesterday’s version, it was “not pretty” on our iPhone device.

The “Wall” in mobile portrait orientation was too low down and too high up in landscape, then “Goldilocks” (more like “very few locks”) has come along today to make the “Wall” just right. And speaking of “right” (or is that “right”), for mobile, the errant ants that wander off to the right caused viewport disruption, as it is very disconcerting on a game asking for you to click ants, be challenged by a “moving Wall”!

The “Wall” (on smaller mobile platforms) positional fix has been made mainly via new CSS …

<style>

/* The rest of the previous CSS here remains untouched ... then ... */

@media only screen and (min-device-width: 320px) and (max-device-width: 865px) and (orientation: portrait) {
.atboXttom {
top: 200px;
}

#wall {
top: 218px;
height: calc(100vh - 218px);
}
}

@media only screen and (min-device-width: 320px) and (max-device-width: 765px) and (orientation: landscape) {
.atboXttom {
top: 200px;
}

#wall {
top: 218px;
height: calc(100vh - 218px);
}
}

</style>

… as a CSS approach to add device dimensions into the mix for the “Cascading” bit of CSS (Cascading Style Sheet).

You can try all this with our changed ants_up_the_wall.html “Ants Up a Wall” game.


Previous relevant Ants Up a Wall Game Snapshots Tutorial is shown below.

Ants Up a Wall Game Snapshots Tutorial

Ants Up a Wall Game Snapshots Tutorial

It occurred to us that …

… to allow our game to optionally record game snapshots into document.body global data attributes, as another way to harness …

  • parent webpage …
  • has document.body global data attribute “snapshots” dynamically created …
  • that can be recalled via a user controllable dropdown … and passed onto …
  • a new game can be “window.open”ed establishing a “window.opener” link in the new game child window (back to the parent) …
  • in order to be able to retain the “snapshots” among “Ants Up the Wall” game runs

Yes, data is passing between webpages, but it is that nuance more sophisticated than your usual “window.open”ed establishing a “window.opener” link arrangement.

You can try all this with our changed ants_up_the_wall.html “Ants Up a Wall” game featuring new Javascript as below …


function showtval(tvalis) {
try {
if (tvalis.trim() != '') {
var woois=window.open('', '_blank', 'top=0,left=0,width=' + screen.width + ',height=' + screen.height);
//woois.document.write('<html><head>' + document.head.innerHTML + '</head><body>' + window.atob(document.body.getAttribute(tvalis)) + '</body></html>');
woois.document.write('<html><head>' + document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head><body>' + decodeURIComponent(document.body.getAttribute(tvalis)) + '</body></html>');
document.getElementById('selsnapshots').value='';
}
} catch(hfgdhg) {
}
}

function involvednewgame() {
//goes=0;
woois=window.open('', '_blank'); //, 'top=0,left=0,width=' + screen.width + ',height=' + screen.height);
//woois.document.write('<html><head>' + document.head.innerHTML + '</head><body>' + window.atob(document.body.getAttribute(tvalis)) + '</body></html>');
woois.document.write('<html><head>' + fixsome(document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head>' + document.body.outerHTML.replace(document.getElementById('custom-alert-1').outerHTML,'')) + '</html>');
//woois.document.write('<html><head>' + document.head.innerHTML.replace('calc(10' + '0% - 550px);', '' + document.body.getAttribute('data-walltop') + 'px;') + '</head>' + document.body.outerHTML.split('>')[0] + '>' + byih + '</body></html>');
}

function makesnapshot() {
if (document.getElementById('selsnapshots') && !woois && !gwoois && notnew) {
var inlabis='' + (new Date());
var labis=('data-' + inlabis).replace(/\:/g,'_').replace(/\//g,'_').replace(/\ /g,'_').replace(/\./g,'_').replace(/\+/g,'_').replace(/\)/g,'_').replace(/\(/g,'_');
//document.body.setAttribute(labis, window.btoa(document.body.innerHTML));
document.body.setAttribute(labis, encodeURIComponent(document.body.innerHTML));
document.getElementById('oreadyfor').innerHTML=document.getElementById('oreadyfor').getAttribute('data-prefix') + 'last was at ' + inlabis + ') of ants at ...';
document.getElementById('selsnapshots').innerHTML+='<option value="' + labis + '">' + inlabis + '</option>';
//ngblurb='<button style=color:orange;z-index:9987; onclick=involvednewgame();>game</button> ';
//ngblurb='game via header link click ';
ngblurb='<a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> (or via header link click above to retain snapshots) ';

document.getElementById('custom-alert-1').onclick=function() { notnew=false; location.href=document.URL.split('#')[0].split('?')[0] + ffa; };
}
}

function doshot(itv) {
if (eval('' + itv) > 0) {
document.getElementById('mysnapshots').innerHTML='<select id=selsnapshots onchange="showtval(this.value);"><option data-prefix="See ' + itv + ' sec' + 'ond snapshots (" id=oreadyfor value="">Se' + 'e ' + itv + ' sec' + 'ond snapshots (first yet to come) of ants at ...</option></select>';
setInterval(makesnapshot, Math.round(eval(1000.0 * eval('' + itv))));
}
}

function fixsome(inidea) {
var outidea=inidea;
var onls=inidea.split('<bo' + 'dy onload="');
var onlstwo=inidea.split('</s' + 'cript>');
var onlstuff='';
if (eval('' + onls.length) > 1 && eval('' + onlstwo.length) > 1) {
onlstuff=onls[1].split('"')[0];
outidea=outidea.replace(onlstwo[0], onlstwo[0] + String.fromCharCode(10) + ' function onlis() { ' + onlstuff + ' } ' + String.fromCharCode(10) + ' setTimeout(onlis, 2000); ' + String.fromCharCode(10));
outidea=outidea.replace('<bo' + 'dy onload="', '<bo' + 'dy data-onload="');
outidea=outidea.replace('cal' + 'c(100% - 10px)', '' + eval(-10 + screen.width) + 'px');
outidea=outidea.replace('cal' + 'c(100% - 28px)', '' + eval(-28 + screen.height) + 'px');
}
return outidea;
}

function lfd() {
var datas=[], idatas=0;
if (window.opener) {
document.getElementById('mysnapshots').innerHTML=window.opener.document.getElementById('mysnapshots').innerHTML;
datas=window.opener.document.body.outerHTML.split('>')[0].split(' data-');
for (idatas=1; idatas<datas.length; idatas++) {
document.body.setAttribute('data-' + datas[idatas].split('=')[0], datas[idatas].split('="')[1].split('"')[0]);
}
setInterval(makesnapshot, Math.round(eval(1000.0 * eval('' + document.getElementById('mysnapshots').innerHTML.split('>Se' + 'e ')[1].split(' ')[0] ))));
//alert('Good');
} else if (document.head.innerHTML.indexOf('calc(1' + '00% - 550px)') == -1) {
//alert('good');
startx=-1;
starty=-1;
goes=20;
score=0;
slowants=1000;
document.getElementById('rest').innerHTML='';
document.getElementById('status').innerHTML='';
document.getElementById('score').innerHTML="Score: 0. Don't mean to scare you but there are 0 ants left looking for 20 food items. Time survived keeping food and clicking ants away: 0 seconds.";
//} else {
//alert('why? ' + document.head.innerHTML.split('<scr')[0]);
}
}


Previous relevant Ants Up a Wall Game Toast Tutorial is shown below.

Ants Up a Wall Game Toast Tutorial

Ants Up a Wall Game Toast Tutorial

Further to Ants Up a Wall Game Fixed Tutorial recent progress with our “Ants Up a Wall” game we have a single word …


"Toast"

… as a means of describing an alternative arrangement to have at the end of the game instead of the Javascript alert popup window we had previously, offering …

  • non-modal and temporary information display …
  • able to show and navigate off links …

We tweaked to this as an issue when we created an HTML iframe off our changed ants_up_the_wall.html “Ants Up a Wall” game within a WordPress blog post, and that WordPress blog “down the line” would be interrupted with an alert box informing them about the “Ants Up a Wall” game status, and the user would be held up doing whatever they were doing at the blog, until they clicked the alert popup window’s OK button. Well, with the Android “toast” inspired …

<style>

.custom-alert {
display: inline-block;
visibility: visible;
background-color: rgba(102,102,102,0.8);
color: #fff;
text-align: enter;
margin: 5% auto;
padding: 12px 28px;
}

</style>

… arrangements (also being placed into the WordPress blog Twenty Ten theme’s good ol’ header.php), that user would no longer be corralled into clicking that OK button in order to proceed, but would still get to see information on the screen regarding the relevant “Ants Up a Wall” game and have links presented to them to navigate to other webpages of interest should they please, before disappearing, as necessary, after some time

<script type=’text/javascript’>

function isecm() {
if (okay) {
isecs++;
document.getElementById('score').innerHTML="Score: " + score + ". Don't mean to scare you but there are " + eval(numants - minus) + " ants left looking for " + goes + " food items. Time survived keeping food and clicking ants away: " + isecs + " seconds.";
if (goes == 0) {
goes=-1;
okay=false;
if (1 == 2) {
alert('Congratulations on keeping some food for ' + isecs + ' seconds.');
location.href=document.URL.split('#')[0].split('?')[0];
} else {
document.getElementById('myh1').title='Click to restart';
document.getElementById('myh1').style.textDecoration='underline';
document.getElementById('myh1').style.cursor='pointer';
if (window.top) {
if (wsprefix == '') {
wsprefix=' ';
var tifs=top.document.getElementsByTagName('iframe');
for (var jtifs=0; jtifs<tifs.length; jtifs++) {
if (('' + tifs[jtifs].src).indexOf('ants_up_the_wall.htm') != -1) {
if (('' + tifs[jtifs].id) != '') {
wsprefix='<a style=color:lightgreen; href="#' + tifs[jtifs].id + '">';
wssuffix='</a>';
} else {
var gbcr=tifs[jtifs].getBoundingClientRect();
wsprefix='<a style="cursor:pointer;text-decoration:underline;color:lightgreen;" onclick=" window.top.scroll(0,' + gbcr.top + '); ">';
wssuffix='</a>';
}
}
}
}
if (top.document.getElementById('custom-alert-1')) {
top.document.getElementById('custom-alert-1').innerHTML="Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.";
top.document.getElementById('custom-alert-1').style.display='inline';
top.document.getElementById('custom-alert-1').style.visibility='visible';
} else {
top.document.body.innerHTML+="<div id='custom-alert-1' class='custom-alert' style='visibility: visible;display: inline;'>Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.</div>";
}
setTimeout(top.document.hideIt, 10000);
} else {
if (document.getElementById('custom-alert-1')) {
document.getElementById('custom-alert-1').innerHTML="Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix + "title" + wssuffix.trim() + " for another game.";
document.getElementById('custom-alert-1').style.display='inline';
document.getElementById('custom-alert-1').style.visibility='visible';
} else {
document.body.innerHTML+="<div id='custom-alert-1' class='custom-alert' style='visibility: visible;display: inline;'>Congratulations on keeping some food for " + isecs + " seconds. Click Ants Up the Wall <a target=_blank style=color:orange; href=//www.rjmprogramming.com.au/HTMLCSS/ants_up_the_wall.html>game</a> " + wsprefix.trim() + "title" + wssuffix + " for another game.</div>";
}
setTimeout(hideIt, 10000);
}
// setTimeout(hideIt, 10000);
}
// location.href=document.URL.split('#')[0].split('?')[0];

}
}
}

function hideIt() {
if (window.top) {
if (top.document.getElementById('custom-alert-1')) {
top.document.getElementById('custom-alert-1').style.display='none';
top.document.getElementById('custom-alert-1').style.visibility='hidden';
}
} else {
if (document.getElementById('custom-alert-1')) {
document.getElementById('custom-alert-1').style.display='none';
document.getElementById('custom-alert-1').style.visibility='hidden';
}
}
}

function cthen() {
goes=0;
location.href=document.URL.split('#')[0].split('?')[0] + ffa;
}


</script>

Today, also there are “Ants Up a Wall” game modes of play (with Javascript logics working with an “ant production” timer codeline now goes setTimeout(moveants,slowants);) that go …

<script type=’text/javascript’>

var slowants=1000;
var ffa=(location.search.split('ffa=')[1] ? decodeURIComponent(location.search.split('ffa=')[1]).split('&')[0] : '');

function oureval(inev, osel) {
if (inev != '') {
if (inev == '100') {
document.getElementById('adjective').innerHTML='Fewer Faster ';
ffa='?ffa=ffa';
} else if (inev == '500') {
document.getElementById('adjective').innerHTML='Half Paced ';
ffa='?ffa=hp';
} else if (inev == '50') {
document.getElementById('adjective').innerHTML='Hard to Handle ';
ffa='?ffa=hth';
} else if (inev == '1000') {
document.getElementById('adjective').innerHTML='Many Slow ';
ffa='?ffa=ms';
}
slowants=eval(inev);
osel.value='';
}
}

function doffa() {
if (ffa != '') {
if (ffa == 'ffa') {
document.getElementById('adjective').innerHTML='Fewer Faster ';
slowants=eval('100');
ffa='?ffa=ffa';
} else if (ffa == 'hp') {
document.getElementById('adjective').innerHTML='Half Paced ';
slowants=eval('500');
ffa='?ffa=hp';
} else if (ffa == 'hth') {
document.getElementById('adjective').innerHTML='Hard to Handle ';
slowants=eval('50');
ffa='?ffa=hth';
} else if (ffa == 'ms') {
document.getElementById('adjective').innerHTML='Many Slow ';
slowants=eval('1000');
ffa='?ffa=ms';
}
}
}

</script>

… the point being that with some of these modes of play the ant movement feels a bit smoother, and more real!


Previous relevant Ants Up a Wall Game Primer Tutorial is shown below.

Ants Up a Wall Game Primer Tutorial

Ants Up a Wall Game Primer Tutorial

We’d like to thank the brick wall inspiration of this very useful link we talked about yesterday with CSS Style Display and Visibility Tall Poppies Tutorial for the reason to take on our “Ants Up a Wall” game today.

Today, though, we arrange it that the wall sits down the bottom of the screen, where, as you would all know, any self respecting ant will emerge from, if they take an interest in your computer equipment.

Your mission, Jim, should you decide to accept it is to protect your food supplies on the wall from marauding ants. We’ve assembled a crack team for you, Jim, or you can come up with your own Bee Team (chortle, chortle). As always, should you or any of your I.M. Force be caught or killed, the Secretary will disavow any knowledge of your actions.

Aspects of today’s “Ants Up a Wall” game’s HTML and Javascript and CSS ants_up_the_wall.html source code for your perusal …

  • brick wall inspired as above, thanks, and represented as an HTML hr (horizontal rule) element, positioned via use of …
  • CSS calc
  • CSS rotation
  • Javascript Object OOP style syntax … for a …
  • data structure which is an Array of Javascript (Ant) objects … and as for yesterday’s game, all of …
  • (Math.floor(Math.random() * [integerRange]) +/- [integerOffset]) // randomosity aid
  • setTimeout (and setInterval (to derive a “seconds elapsed” idea to the game)) timer methods … and, lately, at least …
  • Emoji usage

The marauding ants need a limit of their numbers, in case users leave the web application running forever, and that is where we relieve memory requirements by using the delete (array member) method of keeping the (array) indexes constant but save on memory requirements over time.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in Animation, eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment