Created
June 26, 2014 12:16
-
-
Save KOLANICH/34e4278e6a247029803b to your computer and use it in GitHub Desktop.
AI-Challenge.com debug tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@author KOLANICH <https://github.com/KOLANICH> | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> | |
*/ | |
if (typeof console != "undefined" && typeof ai.log.logOld == "undefined") { | |
var logOld = ai.log; | |
ai.log = function () { | |
console.log.apply(console, arguments); | |
//logOld(Array.prototype.map.call(arguments,JSON.stringify).join(" ")); | |
}; | |
ai.log.logOld=logOld; | |
} | |
if(typeof ai.point=="undefined"){ | |
if(typeof console != "undefined"){ | |
var origCanv=document.getElementById("canvasEdit"); | |
var canv=document.createElement("CANVAS"); | |
document.body.appendChild(canv); | |
canv.width=origCanv.width; | |
canv.height=origCanv.height; | |
var rect=origCanv.getBoundingClientRect(); | |
canv.style.position="absolute"; | |
canv.style.top=(rect.top+ window.pageYOffset)+"px"; | |
canv.style.left=(rect.left+ window.pageXOffset)+"px"; | |
canv.style.zIndex="999999"; | |
canv.style.width=origCanv.style.width; | |
canv.style.height=origCanv.style.height; | |
var U_SCALE = canv.width / 930; | |
ai.ctx=canv.getContext("2d"); | |
ai.ctx.strokeStyle="blue"; | |
ai.ctx.fillStyle = "red"; | |
//ai.ctx.transform(U_SCALE,0,0,-U_SCALE,0,-canv.style.height*U_SCALE); | |
ai.ctx.transform(U_SCALE,0,0,U_SCALE,0,0); | |
ai.clearMarks=function(){ | |
ai.ctx.clearRect(0,0,canv.width,canv.height); | |
}; | |
ai.point=function(rV,color){ | |
ai.ctx.save(); | |
ai.ctx.beginPath(); | |
ai.ctx.fillStyle=color||ai.ctx.fillStyle; | |
ai.ctx.arc.apply(ai.ctx,rV.elements.concat([5,0,Math.PI*2])); | |
ai.ctx.fill(); | |
ai.ctx.stroke(); | |
ai.ctx.restore(); | |
}; | |
ai.line=function(rV,v,color,width){ | |
ai.ctx.save(); | |
ai.ctx.beginPath(); | |
ai.ctx.strokeStyle=color||ai.ctx.strokeStyle; | |
ai.ctx.lineWidth=width||ai.ctx.lineWidth; | |
ai.ctx.moveTo.apply(ai.ctx,rV.elements); | |
ai.ctx.lineTo.apply(ai.ctx,rV.add(v).elements); | |
ai.ctx.stroke(); | |
ai.ctx.restore(); | |
}; | |
ai.angle=function(rVec,startAngle,angle){ | |
function prepAngle(a){ | |
//a%=360; | |
/*a=a<0?360-a:a; | |
a=a>360?a-360*Math.floor(a/360):a;*/ | |
return deg2rad(a); | |
}; | |
angle=prepAngle(angle); | |
startAngle=prepAngle(angle); | |
var len=40; | |
var orig=rVec; | |
var side=$V([0,-len]).rotate(startAngle,$V([0,0])); | |
var anotherSide=side.rotate(angle,$V([0,0])); | |
ai.ctx.save(); | |
ai.ctx.beginPath(); | |
ai.ctx.strokeStyle="purple"; | |
ai.ctx.moveTo.apply(ai.ctx,orig.elements); | |
ai.ctx.lineTo.apply(ai.ctx,orig.elements.concat(orig.add(side).elements)); | |
ai.ctx.stroke(); | |
ai.ctx.strokeStyle="pink"; | |
ai.ctx.arc.apply(ai.ctx,orig.elements.concat(len,startAngle,startAngle+angle)); | |
ai.ctx.stroke(); | |
ai.ctx.strokeStyle="green"; | |
ai.ctx.lineTo.apply(ai.ctx,orig.elements.concat(orig.add(anotherSide).elements)); | |
ai.ctx.stroke(); | |
ai.ctx.restore(); | |
}; | |
var debugOptionsDiv=document.getElementsByClassName("debugOption")[0]; | |
function addOption(name){ | |
var div=document.createElement("DIV"); | |
div.className="checkbox"; | |
var cbx=document.createElement("INPUT"); | |
cbx.type="checkbox"; | |
cbx.id="debugCbx-"+Math.floor(Math.random()*100); | |
var lbl=document.createElement("LABEL"); | |
lbl.for=cbx.id; | |
lbl.innerHTML=name; | |
div.appendChild(cbx); | |
div.appendChild(lbl); | |
debugOptionsDiv.appendChild(div); | |
return cbx; | |
} | |
ai.settings=new Proxy(new Map(), | |
{ | |
get:function(debugOptionsMap,name){ | |
if(!debugOptionsMap.has(name)){ | |
debugOptionsMap.set(name,addOption(name)); | |
} | |
return debugOptionsMap.get(name).checked; | |
} | |
}); | |
window.addEventListener("hashchange",function(evt){canv.style.display=location.hash==="#!/editor"?"":"none";},false); | |
}else{ | |
ai.point=ai.line=ai.clearMarks=ai.angle=function(){}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment