Colouring In Drag and Drop Background Image Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Colouring In Drag and Drop Background Image Tutorial

Colouring In Drag and Drop Background Image Tutorial

So far it might have been hard for some users to visualize โ€œcolouring inโ€ a blank canvas. As such, today, onto yesterdayโ€™s Colouring In Drag and Drop Mobile Tutorial weโ€™re now offering โ€ฆ

  • ability to define a tabular background image via a browsed for image โ€ฆ or โ€ฆ
  • ability to define a tabular background image via a user defined image URL

โ€ฆ and add a new โ€œopacityโ€ setting โ€ฆ



function torgba(inc, opa) {

var i, j=0, csess="rgba(:::1.0)", alp="0123456789abcdef", factor=16;

for (i=0; i<=inc.replace('#','').length; i++) {

if (i == 1) {

csess=csess.replace('rgba(:','rgba(' + (j + alp.toLowerCase().indexOf(inc.toLowerCase().replace('#','').substring(i,(i + 1)))) + ':');

j=0;

} else if (i == 3) {

csess=csess.replace('::',':' + (j + alp.toLowerCase().indexOf(inc.toLowerCase().replace('#','').substring(i,(i + 1)))) + ':');

j=0;

} else if (i == 5) {

csess=csess.replace('::',':' + (j + alp.toLowerCase().indexOf(inc.toLowerCase().replace('#','').substring(i,(i + 1)))) + ':');

j=0;

} else {

j=j + (factor * alp.toLowerCase().indexOf(inc.toLowerCase().replace('#','').substring(i,(i + 1))));

}

csess = csess.replace(":1.0)",":" + opa + ")");

}

return csess.replace(/\:/g,',');

}



function opit(ijval) {

if (document.getElementById('opmeter')) {

if (eval(1.00 - document.getElementById('opmeter').value) != 0.00) {

return torgba(ijval, document.getElementById('opmeter').value);

}

}

return ijval;

}

โ€ฆ all of which we can envisage could have users, at the very least, using this โ€œColouring Inโ€ web application for โ€ฆ

  • a scribbling or doodling mechanism (on a blank canvas)
  • colouring in via a background image with clip art linework, perhaps โ€ฆ
  • create a postcard (type of creation) via a background image, perhaps browsed for (or using the Take Photo or Video option for mobile) on your device, and overlay some scribbled (or doodled) wording

Codewise โ€ฆ

โ€ฆ helped with these mobile platform tweaks. We thank https://i.pinimg.com/736x/86/98/2d/86982d9ee1582bb7a4e730f11ebed3f4.jpg for the background image used (and fed into that image URL textbox to make happen) in todayโ€™s tutorial animated GIF presentation.



Previous relevant Colouring In Drag and Drop Mobile Tutorial is shown below.

Colouring In Drag and Drop Mobile Tutorial

Colouring In Drag and Drop Mobile Tutorial

Yesterdayโ€™s Colouring In Drag and Drop Sharing Tutorial sharing and collaboration code for our latest Colouring In web application was tested on our MacBook Air laptop only. As you can imagine, that can mean that code working there is not always going to work the same way on mobile touch devices, but it was not, as it panned out for us, regarding the reason we thought it would be about. We thought โ€ฆ

  • itโ€™s bound to be an issue with dragging event workings regarding mobile โ€ฆ but it took us quite some time to stop burying our head in the sand and, instead, โ€œkeeping it simple, Seรฑorโ€ (ie. the KISS principle, and yes, Seรฑor is not a spelling mistake, thank you very much for your concern) โ€ฆ and testing another โ€œdumber soundingโ€ but panning out to be true, in this case โ€ฆ
  • issue was to do with table cell widths and heights for table cells with no content acts differently for mobile than non-mobile (effectively scrunching cells up)

โ€ฆ the trigger for us being that the โ€œdropโ€ event.target.id kept on showing up as โ€œmytableโ€. That happened hours ago! We beavered away with x,y proportional co-ordinate calculations and eventually after all that not helping (for 2 maybe 3 hours), started applying a table cell border, which gave crazy results, and then it tweaked?! Sheeeeesssshhhhh!

Can you teach yourself the KISS principle? Maybe you get better over time. Another opinion can be great, though, with that alternative view, you hadnโ€™t even thought of, often the result of such conversations.

Back to today, we โ€ฆ

Made sure table โ€œtrโ€ row elements were for a better defined (proportionate to table) width โ€ฆ
<?php


for ($thisrow=1; $thisrow<=$across; $thisrow++) {

$cthisrow='0000000000' . $thisrow;

$rowsofar='<tr style="width:100%;" id=tr' . substr($cthisrow, -$iacross, $iacross) . '></tr>';

$thistdid='td' . substr($cthisrow, -$iacross, $iacross) . '_';

for ($thiscol=1; $thiscol<=$across; $thiscol++) {

$cthiscol='0000000000' . $thiscol;

$thistdidsuffix='' . substr($cthiscol, -$iacross, $iacross) . '';

$rowsofar=str_replace('></tr>', '><td class="tdone" id=' . $thistdid . $thistdidsuffix . ' style=text-align:center; data-answer=' . $ttcnt . '></td></tr>', $rowsofar);

}

$newih=str_replace('</tbody>', $rowsofar . '</tbody>', $newih);

}


?>
Made sure table โ€œtdโ€ cell elements were proportional โ€ฆ initially, expressed in โ€œviewportโ€ (percentage style) dimension terms โ€ฆ
<style>


td.tdone {

width: 1vw;

height: 1vh;

}


</style>
โ€ฆ and if not the default number of cells across and down โ€ฆ


function overdover() {

if (document.getElementById('dragoverdelay') && document.getElementById('dragovercountdown')) {

if (document.getElementById('numacross')) {

if (('' + document.getElementById('numacross').value) != '99') {

document.getElementById('dstyle').innerHTML+='<st' + 'yle> td { width: ' + eval(eval('' + document.getElementById('numacross').value) /100) + 'vw; height: ' + eval(eval('' + document.getElementById('numacross').value) /100) + 'vh; } </st' + 'yle>';

}

}


if (Math.abs(doverd) != eval('' + document.getElementById('dragoverdelay').value)) { doverd=eval('' + document.getElementById('dragoverdelay').value); }

if (doverc == 0 && eval('' + document.getElementById('dragovercountdown').value) == 0) { doverc=doverd; document.getElementById('dragovercountdown').value='' + doverc; document.getElementById('dragovercountdown').style.display='inline-block'; }

}

}

Codewise โ€ฆ

โ€ฆ helped with these mobile platform tweaks.


Previous relevant Colouring In Drag and Drop Sharing Tutorial is shown below.

Colouring In Drag and Drop Sharing Tutorial

Colouring In Drag and Drop Sharing Tutorial

Weโ€™re hoping yesterdayโ€™s Colouring In Drag and Drop Settings Tutorial new Colouring In web application is seen as a creativeโ€™s tool. As such, youโ€™re going to want to share and collaborate โ€ฆ some of you, that is?!

Youโ€™re going to want to hashtag โ€ฆ oops โ€ฆ weโ€™re going to want to hashtag. Yes, there is lots of data to share, but it worries us even involving hashtagging, how much there is, underlying, regarding that table element acting a bit like a televisionโ€™s pixels. How do you effectively share even a snapshot of that?

But the difference between us and the television is, at least for a lot of peopleโ€™s creations, the table is likely to be untouched, so canโ€™t we โ€œnicknameโ€ these repeated table cell scenarios? If you just said โ€œindeedโ€, weโ€™d concur! Take a look at some global Javascript variables we thought might help โ€ฆ



var defemail='';

var defsms='', snum=null, sparewes=null;

var prefixnickchar='.';

var prefixfor='<td class="tdone" id="';

var suffixnickchar='-';

var suffixfor='" class="tdone" style="text-align:center;" data-answer="1"></td>';


โ€ฆ and for those untouched cells youโ€™re saving more than (because of encryption) the length difference between the โ€œnickcharsโ€ above and their โ€œfixforโ€ counterparts for each โ€œboringโ€ table cell encountered. And all this eases our mind somewhat, as a design, realized, on the way to the emailee or smsee this way โ€ฆ



function doemail(inidea) {

var bihbig='';

var azx=top.document.getElementById('xae' + 'mail');

//alert(33);

if (!azx) { azx=top.document.createElement("a"); }

//alert(3333);

//if (1 == 1) {

//document.getElementById('divas').appendChild(azx);

//} else {

top.document.body.appendChild(azx);

//}

//(334);

azx.style = "display: none";

//alert(2334);

azx.target = "_top";

//alert(6334);

azx.id = 'xae' + 'mail';

if (inidea.indexOf('@') == -1) {

inidea=('' + prompt('Please enter Email address to send to.', defemail));

if (inidea == null) { inidea=''; }

}

if (inidea.indexOf('@') == -1) { return ''; }



bihbig=document.body.innerHTML;

while (bihbig.indexOf(suffixfor) != -1) {

bihbig=bihbig.replace(suffixfor, suffixnickchar);

}

while (bihbig.indexOf(prefixfor + 'td') != -1) {

bihbig=bihbig.replace(prefixfor + 'td', prefixnickchar + 'td');

}



//if (1 == 6 && bihbig.indexOf('</he' + 'ad>') != -1 || bihbig.indexOf('<b' + 'o' + 'dy') != -1 || bihbig.indexOf('<h' + '1') == 0) {

//azx.href = 'mailto:' + inidea + '?subject=' + encodeURIComponent(document.getElementsByTagName('h1')[0].innerText.split('&')[0].split('<')[0].replace(/\`/g,'').replace(/^Events\ in\ /g, 'Events in Month ').substring(0)) + '&body=' + encodeURIComponent(document.URL.replace('php#', 'php?').replace('#', '&') + '#cibih=' + encodeURIComponent(encodeURIComponent(bihbig))); //encodeURIComponent(document.URL.split('#')[0] + '<h2' + document.body.innerHTML.split('<h2')[1]));

//} else {

if (sparewes) {

azx.href = 'mailto:' + inidea + '?subject=' + encodeURIComponent(sparewes.document.getElementsByTagName('h1')[0].innerText.split('&')[0].split('<')[0].replace(/\`/g,'').replace(/^Events\ in\ /g, 'Events in Month ').substring(0)) + '&body=' + encodeURIComponent(document.URL.replace('php#', 'php?').replace('#', '&') + '#cibih=' + encodeURIComponent(encodeURIComponent(bihbig))); //encodeURIComponent(document.URL.split('#')[0] + '<h2' + sparewes.document.body.innerHTML.split('<h2')[1]));

} else {

azx.href = 'mailto:' + inidea + '?subject=' + encodeURIComponent(document.getElementsByTagName('h1')[0].innerText.split('&')[0].split('<')[0].replace(/\`/g,'').replace(/^Events\ in\ /g, 'Events in Month ').substring(0)) + '&body=' + encodeURIComponent(document.URL.replace('php#', 'php?').replace('#', '&') + '#cibih=' + encodeURIComponent(encodeURIComponent(bihbig))); //encodeURIComponent(document.URL.split('#')[0] + '<h2' + document.body.innerHTML.split('<h2')[1]));

}

//}

azx.click();

return '';

}



function dosms() {

var bihbig='';

if (('' + window.localStorage.getItem('colouringincollaboratoremailee')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {

defemail=window.localStorage.getItem('colouringincollaboratoremailee');

}

if (('' + window.localStorage.getItem('colouringincollaboratorsmsno')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {

defsms=window.localStorage.removeItem('colouringincollaboratorsmsno');

}

if (eval('' + ('sms:' + snum + '&body=' + encodeURIComponent(document.URL.split('?')[0].split('#')[0] + '#cibih=' + encodeURIComponent(parent.hfanalyze()))).length) >= 18000) {

snum=('' + prompt('Please enter SMS number to send to. We suspect message is too long for an SMS and if you enter an email address here instead, we will try to send an email instead. Append space(s) to remember, whatever you enter, for next time.', snum)).replace(/^null/g, (defemail.indexOf('@') != -1 ? defemail : (defsms != '' ? defsms : '')) );

} else {

snum=('' + prompt('Please enter SMS number to send to. Append space(s) to remember for next time.', snum)).replace(/^null/g, (defsms != '' ? defsms : (defemail.indexOf('@') != -1 ? defemail : '')));

}

if (snum == null) { snum=''; }



if (snum.indexOf('@') != -1) {

if (snum.trim() != snum) {

snum=snum.trim();

if (('' + window.localStorage.getItem('colouringincollaboratoremailee')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {

window.localStorage.removeItem('colouringincollaboratoremailee');

}

window.localStorage.setItem('colouringincollaboratoremailee', snum);

defemail=snum;

}

return doemail(snum);

} else if (snum.trim() != '' && snum.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'').trim() == '') {

//alert('Snum=' + snum + '?');

if (snum.trim() != snum) {

snum=snum.trim();

if (('' + window.localStorage.getItem('colouringincollaboratorsmsno')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {

window.localStorage.removeItem('colouringincollaboratorsmsno');

}

window.localStorage.setItem('colouringincollaboratorsmsno', snum);

defsms=snum;

}



bihbig=document.body.innerHTML;

while (bihbig.indexOf(suffixfor) != -1) {

bihbig=bihbig.replace(suffixfor, suffixnickchar);

}

while (bihbig.indexOf(prefixfor + 'td') != -1) {

bihbig=bihbig.replace(prefixfor + 'td', prefixnickchar + 'td');

}



var azx=top.document.getElementById('xas' + 'ms');

if (azx == null) { azx=top.document.createElement("a"); }

//if (1 == 1) {

// document.getElementById('divas').appendChild(azx);

//} else {

top.document.body.appendChild(azx);

// }

azx.id = 'xas' + 'ms';

azx.target = "_top";

azx.style = "display: none";

azx.href = 'sms:' + snum + '&body=' + encodeURIComponent(document.URL.replace('php#', 'php?').replace('#', '&') + '#cibih=' + encodeURIComponent(encodeURIComponent(bihbig)));

azx.click();

}

return '';

}

โ€ฆ and when arriving back from an emaileeโ€™s or smseeโ€™s link click โ€ฆ



function cibihcheck() {

var partslh=('' + location.hash).split('#ci' + 'bih=');

if (eval('' + partslh.length) > 1) {

var bihbig=decodeURIComponent(decodeURIComponent(partslh[1]));



bihbig=bihbig.replace(/\.td/g, prefixfor + 'td');

bihbig=bihbig.replace(/0\-/g, '0' + suffixfor);

bihbig=bihbig.replace(/1\-/g, '1' + suffixfor);

bihbig=bihbig.replace(/2\-/g, '2' + suffixfor);

bihbig=bihbig.replace(/3\-/g, '3' + suffixfor);

bihbig=bihbig.replace(/4\-/g, '4' + suffixfor);

bihbig=bihbig.replace(/5\-/g, '5' + suffixfor);

bihbig=bihbig.replace(/6\-/g, '6' + suffixfor);

bihbig=bihbig.replace(/7\-/g, '7' + suffixfor);

bihbig=bihbig.replace(/8\-/g, '8' + suffixfor);

bihbig=bihbig.replace(/9\-/g, '9' + suffixfor);



document.body.innerHTML=bihbig;

}

}


Codewise โ€ฆ

โ€ฆ helped with this sense of collaboration.


Previous relevant Colouring In Drag and Drop Settings Tutorial is shown below.

Colouring In Drag and Drop Settings Tutorial

Colouring In Drag and Drop Settings Tutorial

Onto the start for our Colouring In web application via yesterdayโ€™s Colouring In Canvas Clone of Numbers Guessing Game Tutorial weโ€™re starting to enhance, on top of that โ€œclone levelโ€ functionality, via two new settings with two approaches to the management of data, regarding, those being โ€ฆ

  • number of table cells across (that programmatically is made to be the same number of cells, as down) โ€ฆ we deal with via a get ? (or &) address line URL arrangement โ€ฆ whereas โ€ฆ
  • pen โ€œwidthโ€ can be 1 or 2 (where 2 colours in the 1+8=9 surrounding cells of a dragged over cell) โ€ฆ we deal with via a hashtag arrangement

Why the difference in approach? Letโ€™s start with hashtag methodologies. This arrangement can leave everything about a webpage, in place, regarding the user actions on a webpage, while the Javascript can detect that change in โ€ฆ



location.hash

โ€ฆ dynamically. In other words some dragging canvas drawings with pen โ€œwidthโ€ 2 can be combined with some using pen โ€œwidthโ€ 1 in the same user creation.

But when the data management involves get ? (or &) address line URL arrangements, this involves navigation to a new incarnation of the webpage creation logic, effectively wiping the webpage slate clean. This is apt for the โ€œnumber of table cells acrossโ€ data item, because the HTML content of the table element is not just affected, but is totally structured, according to this user setting.

Lately, more and more, weโ€™ve been hashtagging data to dynamically created โ€œaโ€ link โ€œmailto:โ€ email or โ€œsms:โ€ SMS communication body webpage URL links. An email link or SMS link, from the recipientโ€™s point of view is a โ€œbrand new startโ€ that can address either or both of these data conduit arrangements, weโ€™re getting happier and happier to discover โ€ฆ



// ondragover event function code snippet below ...

ev.target.style.backgroundColor='' + document.getElementById('ddcolour').value;

if (decodeURIComponent(('' + location.hash)).indexOf('fontweight=') != -1) {

ifontweight=eval('' + ('' + decodeURIComponent(('' + location.hash))).split('fontweight=')[1].substring(0,1));

}
else if (document.getElementById('numfontweight')) {

ifontweight=eval('' + document.getElementById('numfontweight').value);

}

if (ifontweight == 2) { // colour in 8 surrounding cells, as applicable

var minusthree=-3;

if (document.getElementById('numacross')) {

minusthree=eval(-1 * eval('' + document.getElementById('numacross').value.length));

}

var tdx=eval(('' + ev.target.id).substring(2).split('_')[0].replace(/^0/g,'').replace(/^0/g,''));

var tdy=eval(('' + ev.target.id).split('_')[1].replace(/^0/g,'').replace(/^0/g,''));

if (document.getElementById('td' + ('000' + eval(-1 + tdx)).slice(minusthree) + '_' + ('000' + eval(-1 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(-1 + tdx)).slice(minusthree) + '_' + ('000' + eval(-1 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}

if (document.getElementById('td' + ('000' + eval(-1 + tdx)).slice(minusthree) + '_' + ('000' + eval(0 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(-1 + tdx)).slice(minusthree) + '_' + ('000' + eval(0 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}

if (document.getElementById('td' + ('000' + eval(-1 + tdx)).slice(minusthree) + '_' + ('000' + eval(1 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(-1 + tdx)).slice(minusthree) + '_' + ('000' + eval(1 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}



if (document.getElementById('td' + ('000' + eval(0 + tdx)).slice(minusthree) + '_' + ('000' + eval(-1 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(0 + tdx)).slice(minusthree) + '_' + ('000' + eval(-1 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}

if (document.getElementById('td' + ('000' + eval(0 + tdx)).slice(minusthree) + '_' + ('000' + eval(1 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(0 + tdx)).slice(minusthree) + '_' + ('000' + eval(1 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}



if (document.getElementById('td' + ('000' + eval(1 + tdx)).slice(minusthree) + '_' + ('000' + eval(-1 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(1 + tdx)).slice(minusthree) + '_' + ('000' + eval(-1 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}

if (document.getElementById('td' + ('000' + eval(1 + tdx)).slice(minusthree) + '_' + ('000' + eval(0 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(1 + tdx)).slice(minusthree) + '_' + ('000' + eval(0 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}

if (document.getElementById('td' + ('000' + eval(1 + tdx)).slice(minusthree) + '_' + ('000' + eval(1 + tdy)).slice(minusthree))) {

document.getElementById('td' + ('000' + eval(1 + tdx)).slice(minusthree) + '_' + ('000' + eval(1 + tdy)).slice(minusthree)).style.backgroundColor='' + document.getElementById('ddcolour').value;

}

}

Codewise โ€ฆ

Did you know?

Our recent Earth Scanner project was conducted during our โ€œHashtagging Enlightenment Periodโ€, whereby, around here, the โ€ฆ

What the Hep?

โ€ฆ greeting, is code for โ€œHave yourself a happy and fruitful hashtagging dayโ€ โ€ฆ but we digress. In amongst itโ€™s code there was an example codeline โ€ฆ



var nontz=('' + location.search + ('' + location.hash).replace(/^\#/g,'')).split('nontz=')[1] ? decodeURIComponent(('' + location.search + ('' + location.hash).replace(/^\#/g,'')).split('nontz=')[1].split('&')[0].split('#')[0]) : '';

โ€ฆ exemplifying, how more and more, weโ€™re happy with setting (or other types of incoming) data coming from get (? and & ( eg. ?nontz=Alice_Springs%7C133.8807%7C_23.6980%7C )) arguments via location.search and/or hashtagged data coming from location.hash ( eg. #nontz=Alice_Springs%7C133.8807%7C_23.6980%7C ) above, either or both, perhaps, used in an email or SMS body URL link.


Previous relevant Colouring In Canvas Clone of Numbers Guessing Game Tutorial is shown below.

Colouring In Canvas Clone of Numbers Guessing Game Tutorial

Colouring In Canvas Clone of Numbers Guessing Game Tutorial

As the blog posting title suggests, cloned from yesterdayโ€™s Numbers Guessing Game Dragover Tutorial โ€ฆ

  • Numbers Guessing Game dragover โ€œvalue addโ€ proof of concept work โ€ฆ comes โ€ฆ
  • Colouring In Canvas drag and (faux) drop web application

โ€ฆ where a โ€œcanvasโ€ palette (which is really an HTML table element made up of lots of table cells, rather than an HTML5 canvas element). Why this design? Well, each table cell element can be identified as an individual โ€œdragged overโ€ element. โ€œDragged overโ€ by what? Well, we turn some โ€œdraggableโ€ wording in the basis HTML into โ€ฆ

This entry was posted in eLearning, Event-Driven Programming, Games, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *