MediaWiki:Common.js: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 5: Line 5:


   var cconvdiv = document.getElementById('color-converter');
   var cconvdiv = document.getElementById('color-converter');
   cconvdiv.innerHTML = '<form name="cconvform" action=""><input type="text" maxlength="3" size="4" id="color-red">' +
   if (cconvdiv != null) {
                      '<input type="text" maxlength="3" size="4" id="color-green">' +
    cconvdiv.innerHTML = '<form name="cconvform" action="">' +
                      '<input type="text" maxlength="3" size="4" id="color-blue">' +
                        'Red:<input type="text" maxlength="3" size="4" id="color-red"><br>' +
                      '<input type="button" value="Convert" onClick="cconv();"></form>';
                        'Green:<input type="text" maxlength="3" size="4" id="color-green"><br>' +
                        'Blue:<input type="text" maxlength="3" size="4" id="color-blue"><br>' +
                        '<input type="button" value="Convert" onClick="cconv();"></form>';
  }


  var mguessdiv = document.getElementById('mirror-guesser');
  if (mguessdiv != null) {
    mguessdiv.innerHTML = '<form name="mguessform" action="">' +
                        'Address (hex):<input type="text" maxlength="6" size="6" id="address">' +
                        '<input type="button" value="Guess" onClick="mguess();"></form>';
  }
}());
}());
function mguess(frm) {
  var address = document.forms["mguessform"]["address"].value;
  var text = 'Bad';
  if ((address & 0xFE0001) == 0x300000) text = 'Ok';
  document.getElementById('mguessresult').innerHTML = text;
}


function cconv(frm) {
function cconv(frm) {

Revision as of 23:07, 17 April 2016

/* Any JavaScript here will be loaded for all users on every page load. */

// NeoGeo Color converter
(function () {

  var cconvdiv = document.getElementById('color-converter');
  if (cconvdiv != null) {
    cconvdiv.innerHTML = '<form name="cconvform" action="">' +
                         'Red:<input type="text" maxlength="3" size="4" id="color-red"><br>' +
                         'Green:<input type="text" maxlength="3" size="4" id="color-green"><br>' +
                         'Blue:<input type="text" maxlength="3" size="4" id="color-blue"><br>' +
                         '<input type="button" value="Convert" onClick="cconv();"></form>';
  }

  var mguessdiv = document.getElementById('mirror-guesser');
  if (mguessdiv != null) {
    mguessdiv.innerHTML = '<form name="mguessform" action="">' +
                         'Address (hex):<input type="text" maxlength="6" size="6" id="address">' +
                         '<input type="button" value="Guess" onClick="mguess();"></form>';
  }
}());

function mguess(frm) {

  var address = document.forms["mguessform"]["address"].value;

  var text = 'Bad';

  if ((address & 0xFE0001) == 0x300000) text = 'Ok';

  document.getElementById('mguessresult').innerHTML = text;

}

function cconv(frm) {

  var red = Math.min(255, document.forms["cconvform"]["color-red"].value);
  var green = Math.min(255, document.forms["cconvform"]["color-green"].value);
  var blue = Math.min(255, document.forms["cconvform"]["color-blue"].value);

  var icolor = red + "," + green + "," + blue;

  var luma = Math.floor((54.213*red) + (182.376*green) + (18.411*blue)) & 1;

  red = Math.floor(red / 8);
  green = Math.floor(green / 8);
  blue = Math.floor(blue / 8);

  var ocolor = (((red<<1)+luma)<<2) + "," + (((green<<1)+luma)<<2) + "," + (((blue<<1)+luma)<<2);

  var hex = (((luma^1)<<15)|((red&1)<<14)|((green&1)<<13)|((blue&1)<<12)|((red&0x1E)<<7)|((green&0x1E)<<3)|(blue>>1)).toString(16).toUpperCase();
  while (hex.length < 4) {
    hex = "0" + hex;
  }

  document.getElementById('cconvresult').innerHTML = '$' + hex + ' In: <div style="width:64px; height:32px; background:rgb(' + icolor + ');"></div>  Out:<div style="width:64px; height:32px; background:rgb(' + ocolor + ');"></div> ';

}