new file: Files/flashplayer_32_sa.exe new file: favicon.ico new file: globe.gif new file: imgs/download.png new file: imgs/zuck.jpg new file: index.html new file: other.ico new file: script.js new file: site.webmanifest new file: sitemap.html new file: styles/backround.css new file: styles/border.css new file: styles/fonts/Titillium_Web/OFL.txt new file: styles/fonts/Titillium_Web/TitilliumWeb-Black.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-Bold.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-BoldItalic.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-ExtraLight.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-ExtraLightItalic.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-Italic.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-Light.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-LightItalic.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-Regular.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-SemiBold.ttf new file: styles/fonts/Titillium_Web/TitilliumWeb-SemiBoldItalic.ttf new file: styles/fonts/webfontkit-20221027-163353/generator_config.txt new file: styles/fonts/webfontkit-20221027-163353/specimen_files/grid_12-825-55-15.css new file: styles/fonts/webfontkit-20221027-163353/specimen_files/specimen_stylesheet.css new file: styles/fonts/webfontkit-20221027-163353/stylesheet.css new file: styles/fonts/webfontkit-20221027-163353/titilliumweb-extralight-demo.html new file: styles/fonts/webfontkit-20221027-163353/titilliumweb-extralight-webfont.woff new file: styles/fonts/webfontkit-20221027-163353/titilliumweb-extralight-webfont.woff2 new file: styles/fonts/webfontkit-20221027-165950/generator_config.txt new file: styles/fonts/webfontkit-20221027-165950/specimen_files/grid_12-825-55-15.css new file: styles/fonts/webfontkit-20221027-165950/specimen_files/specimen_stylesheet.css new file: styles/fonts/webfontkit-20221027-165950/stylesheet.css new file: styles/fonts/webfontkit-20221027-165950/titilliumweb-bold-demo.html new file: styles/fonts/webfontkit-20221027-165950/titilliumweb-bold-webfont.woff new file: styles/fonts/webfontkit-20221027-165950/titilliumweb-bold-webfont.woff2 new file: styles/style.css new file: tools/2048/.gitignore new file: tools/2048/.jshintrc new file: tools/2048/CONTRIBUTING.md new file: tools/2048/LICENSE.txt new file: tools/2048/README.md new file: tools/2048/Rakefile new file: tools/2048/favicon.ico new file: tools/2048/index.html new file: tools/2048/js/animframe_polyfill.js new file: tools/2048/js/application.js new file: tools/2048/js/bind_polyfill.js new file: tools/2048/js/classlist_polyfill.js new file: tools/2048/js/game_manager.js new file: tools/2048/js/grid.js new file: tools/2048/js/html_actuator.js new file: tools/2048/js/keyboard_input_manager.js new file: tools/2048/js/local_storage_manager.js new file: tools/2048/js/tile.js new file: tools/2048/meta/apple-touch-icon.png new file: tools/webretro/cores/neocd_libretro.js new file: tools/webretro/cores/neocd_libretro.wasm new file: tools/webretro/cores/nestopia_libretro.js new file: tools/webretro/cores/nestopia_libretro.wasm new file: tools/webretro/cores/o2em_libretro.js new file: tools/webretro/cores/o2em_libretro.wasm new file: tools/webretro/cores/opera_libretro.js new file: tools/webretro/cores/opera_libretro.wasm
84 lines
25 KiB
JavaScript
84 lines
25 KiB
JavaScript
function polymodelsMain(){this.version='0.92';var m=getQueryVariable('m');if(m){m=m.replace(/%20/g,' ');m=m.toLowerCase();this.shapeName=m;}else{this.shapeName='icosidodecahedron';this.shapeName='rhombicosidodecahedron';this.shapeName='cube';this.shapeName='truncated icosahedron';}
|
|
this.curvyQ=['cone','cylinder','sphere','hemisphere'].indexOf(this.shapeName)>=0;this.flatyQ=['plane'].indexOf(this.shapeName)>=0;console.log("polymodelsMain",this.shapeName);w=550;h=550;topMargin=65;var s="";s+='<div style="position:relative; width:'+w+'px; height:'+h+'px; border-radius: 10px; margin:auto; display:block; ">';s+='<canvas id="canvas2" style="position: absolute; width:'+w+'px; height:'+h+'px; z-index: 1; border: none;"></canvas>';s+='<canvas id="canvas1" style="position: absolute; width:'+w+'px; height:'+h+'px; z-index: 1; border: none;"></canvas>';s+='<div style="position: relative; height:33px; z-index:2; background-color: #48f;border-radius: 10px;">';s+='<button id="prevBtn" style="position: absolute; left:1px; z-index:3;font-size: 16px; color: #000aae; " class="togglebtn" onclick="prevPoly()" >◀</button>';s+='<button id="nextBtn" style="position: absolute;right:1px; z-index:3;font-size: 16px; color: #000aae; " class="togglebtn" onclick="nextPoly()" >▶</button>';s+='<div id="title" style="z-index:2; color: white;text-align: center; position: relative; font: bold 20px Arial; padding-top: 2px; ">';s+='</div>';s+='</div>';s+='<div style="position: relative; height:20px; z-index:2; font: 18px Arial; ">';s+='<button id="dragBtn" onclick="toggleDrag()" style="z-index:2; position: absolute; top: 3px; left: 3px;" class="togglebtn lo" >Spin</button>';if(this.curvyQ||this.flatyQ){}else{s+='<button id="explodeBtn" onclick="toggleExplode()" style="z-index:2; position: absolute; top: 3px; left: 60px;" class="togglebtn lo" >Explode</button>';s+='<button id="netBtn" onclick="toggleNet()" style="z-index:2; position: absolute; top: 3px; left: 140px;" class="togglebtn lo" >Net</button>';s+='<button id="solidBtn" onclick="toggleSolid()" style="z-index:2; position: absolute; top: 3px; left: 190px;" class="togglebtn hi" >Solid</button>';s+='<div style="z-index:2;position: absolute; top: 7px; right: 5px; font: 18px Arial;">';s+="Coloring: ";s+=getDropdownHTML(['Multi','Shaded','Two','Glass','PureGlass','Beams'],'clrChg','clrType');s+='</div>';}
|
|
s+='</div>';s+='<button style="z-index:2;font: 16px Arial; position:absolute; right:64px; bottom:3px;" class="togglebtn" onclick="canvasPrint()" >Print</button>';s+='<button style="z-index:2;font: 16px Arial; position:absolute; right:3px; bottom:3px;" class="togglebtn" onclick="canvasSave()" >Save</button>';s+='<div id="copyrt" style="font: 7pt arial; font-weight: bold; color: #6600cc; position:absolute; left:5px; bottom:3px;">© 2016 MathsIsFun.com v'+this.version+'</div>';s+='</div>';document.write(s);el=document.getElementById('canvas1');ratio=2;el.width=w*ratio;el.height=h*ratio;el.style.width=w+"px";el.style.height=h+"px";g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);el2=document.getElementById('canvas2');el2.width=w*ratio;el2.height=h*ratio;el2.style.width=w+"px";el2.style.height=h+"px";g2=el2.getContext("2d");g2.setTransform(ratio,0,0,ratio,0,0);transMat=[[1,0,0],[0,1,0],[0,0,1],[0,0,0]];this.f=500;this.shapes=[];this.clrs=["#ff0000","#0000ff","#ff9900","#00ff00","#ffff00","#660066","#99ff00","#0099ff","#00ff99","#9900ff","#ff0099","#006666","#666600","#990000","#009999","#999900","#003399","#ff00ff","#993333","#330099"];this.explodeQ=false;this.netQ=false;this.solidQ=true;dragQ=false;draggingQ=false;prevmouseX=0;prevmouseY=0;this.poly=new Poly();xAngle=2;yAngle=4;zAngle=0;el.addEventListener('touchstart',ontouchstart,false);el.addEventListener('touchmove',ontouchmove,false);el.addEventListener('mousedown',onmouseDown,false);el.addEventListener('mousemove',onmouseMove,false);el.addEventListener("mouseup",onmouseUp,false);polys=getPolyData();polyNo=0;for(var i=0;i<polys.length;i++){if(polys[i][0].toLowerCase()==this.shapeName){polyNo=i;break;}}
|
|
console.log("stt",this.shapeName,polyNo);settransMat(200,50,0,transMat);restart();animate();}
|
|
function ontouchstart(evt){draggingQ=true;var touch=evt.targetTouches[0];var bRect=el.getBoundingClientRect();prevmouseX=(touch.clientX-bRect.left)*(el.width/ratio/bRect.width);prevmouseY=(touch.clientY-bRect.top)*(el.height/ratio/bRect.height);}
|
|
function ontouchmove(evt){var touch=evt.targetTouches[0];evt.clientX=touch.clientX;evt.clientY=touch.clientY;evt.touchQ=true;onmouseMove(evt);evt.preventDefault();}
|
|
function onmouseDown(){draggingQ=true;prevmouseX=mouseX;prevmouseY=mouseY;}
|
|
function onmouseUp(){draggingQ=false;}
|
|
function onmouseMove(evt){var bRect=el.getBoundingClientRect();mouseX=(evt.clientX-bRect.left)*(el.width/ratio/bRect.width);mouseY=(evt.clientY-bRect.top)*(el.height/ratio/bRect.height);if(dragQ){if(draggingQ){settransMat(-(prevmouseY-mouseY)*3,(prevmouseX-mouseX)*3,0,transMat);prevmouseX=mouseX;prevmouseY=mouseY;update();}}else{yAngle=-(mouseX-w/2)/50;xAngle=(mouseY-h/2)/50;}}
|
|
function toggleDrag(){dragQ=!dragQ;toggleBtn("dragBtn",dragQ);if(dragQ){document.getElementById("dragBtn").innerHTML='Drag';}else{document.getElementById("dragBtn").innerHTML='Spin';}}
|
|
function toggleExplode(){this.explodeQ=!this.explodeQ;toggleBtn("explodeBtn",this.explodeQ);restart();}
|
|
function toggleNet(){this.netQ=!this.netQ;toggleBtn("netBtn",this.netQ);restart();}
|
|
function toggleSolid(){this.solidQ=!this.solidQ;toggleBtn("solidBtn",this.solidQ);restart();}
|
|
function toggleBtn(btn,onq){if(onq){document.getElementById(btn).classList.add("hi");document.getElementById(btn).classList.remove("lo");}else{document.getElementById(btn).classList.add("lo");document.getElementById(btn).classList.remove("hi");}}
|
|
function prevPoly(){polyNo--;if(polyNo<0)polyNo=polys.length-1;console.log("prevPoly",polyNo,polys.length);restart();}
|
|
function nextPoly(){polyNo=(++polyNo)%polys.length;console.log("nextPoly",polyNo,polys.length);restart();}
|
|
function getDropdownHTML(opts,funcName,id){var s='';s+='<select id="'+id+'" style="font: 16px Arial; color: #6600cc; background: rgba(200,220,256,0.7); padding: 1px;" onchange="'+funcName+'()">';for(var i=0;i<opts.length;i++){var idStr=id+i;var chkStr=i==3?'selected':'';s+='<option id="'+idStr+'" value="'+opts[i]+'" style="height:18px;" '+chkStr+' >'+opts[i]+'</option>';}
|
|
s+='</select>';return s;}
|
|
function clrChg(){var el=document.getElementById('clrType');if(el.selectedIndex==-1)
|
|
return null;var t=el.options[el.selectedIndex].text;setClrs(t);update();}
|
|
function getClrType(){if(this.curvyQ||this.flatyQ){if(this.shapeName=='plane'){return "Glass";}else{return "Shaded";}}else{var div=document.getElementById('clrType');if(div.selectedIndex==-1)return 'Multi';return div.options[div.selectedIndex].text;}}
|
|
function init(){}
|
|
function restart(){console.log("restart",polyNo,polys[polyNo][0]);shapes=[];poly.shapeSource="data";poly.shapeType=polys[polyNo][0];setShapesFromPoly();document.getElementById('title').innerHTML=poly.shapeType.capitalize();g2.clearRect(0,0,el.width,el.height);if(this.netQ)drawNet();this.frameNo=0;g.clearRect(0,0,el.width,el.height);update();update();}
|
|
function animate(){this.frameNo++;if(dragQ){}else{settransMat(xAngle,yAngle,zAngle,transMat);update();}
|
|
if(this.frameNo<1e8){requestAnimationFrame(animate);}}
|
|
function update(){g.clearRect(0,0,el.width,el.height);if(this.solidQ)drawShapes();}
|
|
function drawShapes(){var prevDepth=0;var sortNeededQ=false;for(var i=0,len=shapes.length;i<len;i++){var shape=shapes[i];shape.drawsurface(false,"N");if(i>0){if(shape.depth<prevDepth){sortNeededQ=true;}}
|
|
prevDepth=shape.depth;}
|
|
if(sortNeededQ){shapes.sort(compareDepth);}}
|
|
function compareDepth(a,b){if(a.depth<b.depth)return-1;return 1;}
|
|
function setShapesFromPoly(){var C=poly.getSolid();var i=0;while(i<C.length){var surf=C[i];addShape3D("surface",coords2Lines(surf,poly.scale),1,'#ffffff','rgba(0,0,255,0.3)');i++;}
|
|
setClrs(getClrType());}
|
|
function coords2Lines(surf,Scale){var P=[];var midPt=[0,0,0];for(var i=0;i<surf.length;i++){if(i<surf.length-1){var tonum=i+1;}else{tonum=0;}
|
|
P[i]=[];if(surf[i]==undefined){console.log("Error surface ="+i,surf[i]);}else{for(var j=0;j<3;j++){P[i][j]=surf[i][j]*Scale;if(explodeQ)midPt[j]+=P[i][j];}}}
|
|
if(explodeQ){for(j=0;j<3;j++){midPt[j]/=surf.length;}
|
|
for(i=0;i<surf.length;i++){for(j=0;j<3;j++){P[i][j]+=midPt[j]/2;}}}
|
|
return P;}
|
|
function addShape3D(shapeType,pointarray,lineweight,lineClr,fillClr){var shape=new Shape3D;shape.transMat=transMat;shape.f=this.f;shape.setPts(pointarray);shape.shapeType=shapeType;shape.lineweight=lineweight;shape.lineClr=lineClr;shape.fillClr=fillClr;shapes.push(shape);}
|
|
function settransMat(x,y,z,M){var vectorLength=Math.sqrt(x*x+y*y+z*z);if(vectorLength>.0001){x/=vectorLength;y/=vectorLength;z/=vectorLength;var Theta=vectorLength/500;var cosT=Math.cos(Theta);var sinT=Math.sin(Theta);var tanT=1-cosT;var T=[[],[],[]];T[0][0]=tanT*x*x+cosT;T[0][1]=tanT*x*y-sinT*z;T[0][2]=tanT*x*z+sinT*y;T[1][0]=tanT*x*y+sinT*z;T[1][1]=tanT*y*y+cosT;T[1][2]=tanT*y*z-sinT*x;T[2][0]=tanT*x*z-sinT*y;T[2][1]=tanT*y*z+sinT*x;T[2][2]=tanT*z*z+cosT;transMat=matMatMult(T,M);}}
|
|
function matMatMult(A,B){var C=[[],[],[]];C[0][0]=A[0][0]*B[0][0]+A[0][1]*B[1][0]+A[0][2]*B[2][0];C[0][1]=A[0][0]*B[0][1]+A[0][1]*B[1][1]+A[0][2]*B[2][1];C[0][2]=A[0][0]*B[0][2]+A[0][1]*B[1][2]+A[0][2]*B[2][2];C[1][0]=A[1][0]*B[0][0]+A[1][1]*B[1][0]+A[1][2]*B[2][0];C[1][1]=A[1][0]*B[0][1]+A[1][1]*B[1][1]+A[1][2]*B[2][1];C[1][2]=A[1][0]*B[0][2]+A[1][1]*B[1][2]+A[1][2]*B[2][2];C[2][0]=A[2][0]*B[0][0]+A[2][1]*B[1][0]+A[2][2]*B[2][0];C[2][1]=A[2][0]*B[0][1]+A[2][1]*B[1][1]+A[2][2]*B[2][1];C[2][2]=A[2][0]*B[0][2]+A[2][1]*B[1][2]+A[2][2]*B[2][2];return C;}
|
|
function setClrs(clrMethod){for(var i=0;i<shapes.length;i++){var shape=shapes[i];shape.clrMethod=clrMethod;switch(clrMethod){case "Multi":shape.fillClr=convertHexClr(clrs[i%clrs.length],0.7);break;case "Two":shape.fillClr=convertHexClr(clrs[i%2],0.8);break;case "Smooth":var FromMiddle=parseInt(Math.abs(shapes.length/2-i));var blu=FromMiddle*8+1;var ccc=rgb2hex([blu,128,blu]);shape.fillClr=ccc;break;case "Glass":case "PureGlass":shape.doShading();break;case "Shaded":shape.doShading();break;default:}}}
|
|
function Poly(){this.shapeType='cube';this.shapeSource='calc';this.scale=90;}
|
|
Poly.prototype.getSolid=function(){var C=[];switch(this.shapeSource){case "file":case "data":var solid=polys[polyNo][1];var vertices=solid[3];var solidFaces=solid[5];C=[];for(var i=0;i<solidFaces.length;i++){var faceVerts=[];for(var j=0;j<solidFaces[i].length;j++){faceVerts.push(vertices[solidFaces[i][j]]);}
|
|
C.push(faceVerts);}
|
|
clrMethod="Glass";Scale=100;this.scale=120;break;case "calc":C=this.getCalcSolid();break;default:}
|
|
return C;};Poly.prototype.getNet=function(){var solid=polys[polyNo][1];var vertices=solid[3];var netFaces=solid[4];var C=[];for(var i=0;i<netFaces.length;i++){var faceVerts=[];for(var j=0;j<netFaces[i].length;j++){faceVerts.push(vertices[netFaces[i][j]]);}
|
|
C.push(faceVerts);}
|
|
return C;};Poly.prototype.getCalcSolid=function(){var C=[];this.scale=90;var i;var j;switch(this.shapeType.toLowerCase()){case "net":C=[[[0,0,0],[0,1,0],[1,1,0],[1,0,0]],[[1,0,0],[2,0,0],[2,1,0],[1,1,0]],[[2,0,0],[3,0,0],[3,1,0],[2,1,0]]];clrMethod="Glass";this.scale=100;break;case "sphere":C=this.createNSphere(3);clrMethod="Alternating";this.scale=110;break;case "hemisphere":C=CreateNSphere(3,true);clrMethod="Shaded";this.scale=110;break;case "cone":C=this.createNCone(60,1.3);this.scale=140;clrMethod="Smooth";break;case "cylinder":C=this.createNCylinder(60);clrMethod="Smooth";this.scale=110;break;case "square-pyramid":C=this.createNCone(4,0.5);this.scale=180;break;case "pent-pyramid":C=this.createNCone(5,0.7);this.scale=180;break;case "tetrahedron":C=[[[1,1,1],[-1,1,-1],[1,-1,-1]],[[-1,1,-1],[-1,-1,1],[1,-1,-1]],[[1,1,1],[1,-1,-1],[-1,-1,1]],[[1,1,1],[-1,-1,1],[-1,1,-1]]];break;case "irr-tetrahedron":C=[[[2,1,-0.2],[-1,1,-1],[1,-1,-1]],[[-1,1,-1],[-1,-1,1],[1,-1,-1]],[[2,1,-0.2],[1,-1,-1],[-1,-1,1]],[[2,1,-0.2],[-1,-1,1],[-1,1,-1]]];this.scale=80;break;case "cube":C=[[[-1,-1,-1],[1,-1,-1],[1,-1,1],[-1,-1,1]],[[-1,-1,-1],[-1,-1,1],[-1,1,1],[-1,1,-1]],[[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],[[-1,1,-1],[-1,1,1],[1,1,1],[1,1,-1]],[[1,-1,-1],[1,1,-1],[1,1,1],[1,-1,1]],[[-1,-1,-1],[-1,1,-1],[1,1,-1],[1,-1,-1]]];break;case "3 points":C=[[[-1,-1,-1],[1,-1,-1],[1,-1,1]]];this.scale=80;break;case "4 coplanar points":C=[[[-1.5,-1,-1],[1,-1,-1],[0.3,-1,1],[-1.5,-1,1]]];this.scale=80;break;case "4 points":C=[[[-1.1,-2,-2],[1,-1,-1],[0.8,2,1]],[[1,-1,-1],[0.8,2,1],[1.5,-1,1]]];Scale=70;break;case "plane":var a=0.5;var b=0.5;var c=0.5;var d=-3;C=[];for(i=0;i<6;i++){for(j=0;j<6;j++){C.push([[a,-b+d+i,-c+d+j],[a,b+d+i,-c+d+j],[a,b+d+i,c+d+j],[a,-b+d+i,c+d+j]]);}}
|
|
this.scale=80;break;case "cuboid":case "rect-prism":a=1.2;b=0.7;c=0.7;C=[[[-a,-b,-c],[a,-b,-c],[a,-b,c],[-a,-b,c]],[[-a,-b,-c],[-a,-b,c],[-a,b,c],[-a,b,-c]],[[-a,-b,c],[a,-b,c],[a,b,c],[-a,b,c]],[[-a,b,-c],[-a,b,c],[a,b,c],[a,b,-c]],[[a,-b,-c],[a,b,-c],[a,b,c],[a,-b,c]],[[-a,-b,-c],[-a,b,-c],[a,b,-c],[a,-b,-c]]];break;case "pent-prism":a=1.2;b=0.70;c=0.73;d=0.16;var e=0.44;C=[[[-a,0,b],[-a,c,d],[-a,e,-b],[-a,-e,-b],[-a,-c,d]],[[a,0,b],[a,c,d],[a,e,-b],[a,-e,-b],[a,-c,d]],[[-a,0,b],[-a,c,d],[a,c,d],[a,0,b]],[[-a,c,d],[-a,e,-b],[a,e,-b],[a,c,d]],[[-a,e,-b],[-a,-e,-b],[a,-e,-b],[a,e,-b]],[[-a,-e,-b],[-a,-c,d],[a,-c,d],[a,-e,-b]],[[-a,-c,d],[-a,0,b],[a,0,b],[a,-c,d]]];break;case "oct-prism":a=1.1;b=0.33;c=0.79;C=[[[-a,b,c],[-a,c,b],[-a,c,-b],[-a,b,-c],[-a,-b,-c],[-a,-c,-b],[-a,-c,b],[-a,-b,c]],[[a,b,c],[a,c,b],[a,c,-b],[a,b,-c],[a,-b,-c],[a,-c,-b],[a,-c,b],[a,-b,c]]];for(i=0;i<8;i++){j=Maths.loop(i,0,7,1);C.push([[C[0][i][0],C[0][i][1],C[0][i][2]],[C[0][j][0],C[0][j][1],C[0][j][2]],[C[1][j][0],C[1][j][1],C[1][j][2]],[C[1][i][0],C[1][i][1],C[1][i][2]]]);}
|
|
break;case "irr-pent-prism":a=1.2;b=0.70;c=0.73;d=0.16;e=0.9;C=[[[-a,0,b],[-a,c,d],[-a,e,-b],[-a,-e,-b],[-a,-c,d]],[[a,0,b],[a,c,d],[a,e,-b],[a,-e,-b],[a,-c,d]],[[-a,0,b],[-a,c,d],[a,c,d],[a,0,b]],[[-a,c,d],[-a,e,-b],[a,e,-b],[a,c,d]],[[-a,e,-b],[-a,-e,-b],[a,-e,-b],[a,e,-b]],[[-a,-e,-b],[-a,-c,d],[a,-c,d],[a,-e,-b]],[[-a,-c,d],[-a,0,b],[a,0,b],[a,-c,d]]];break;case "tri-prism-n":C=CreateNCylinder(3);this.scale=100;break;case "tri-prism":a=1.2;b=0.7;c=0.7;d=0.6;C=[[[-a,-b,-c],[-a,-b,c],[-a,d,0]],[[a,-b,-c],[a,-b,c],[a,d,0]],[[-a,-b,-c],[a,-b,-c],[a,-b,c],[-a,-b,c]],[[-a,-b,c],[a,-b,c],[a,d,0],[-a,d,0]],[[-a,-b,-c],[-a,d,0],[a,d,0],[a,-b,-c]]];break;case "strange-prism":a=1.2;b=0.7;c=0.7;C=[[[-a,-b,-c],[a,-b,-c],[a,-b,c]],[[-a,-b,-c],[-a,-b,c],[-a,b,c]],[[-a,-b,c],[a,-b,c],[a,b,c]],[[-a,b,-c],[-a,b,c],[a,b,c]],[[a,-b,-c],[a,b,-c],[a,b,c]],[[-a,-b,-c],[-a,b,-c],[a,b,-c]]];break;case "octahedron":a=3/(2*Math.sqrt(2));b=3/2;C=[[[-a,0,a],[-a,0,-a],[0,b,0]],[[-a,0,-a],[a,0,-a],[0,b,0]],[[a,0,-a],[a,0,a],[0,b,0]],[[a,0,a],[-a,0,a],[0,b,0]],[[a,0,-a],[-a,0,-a],[0,-b,0]],[[-a,0,-a],[-a,0,a],[0,-b,0]],[[a,0,a],[a,0,-a],[0,-b,0]],[[-a,0,a],[a,0,a],[0,-b,0]]];Scale=100;break;case "dodecahedron":var phi=(1+Math.sqrt(5))/2;a=1;b=1/phi;c=2-phi;a*=1.5;b*=1.5;c*=1.5;C=[[[c,0,a],[-c,0,a],[-b,b,b],[0,a,c],[b,b,b]],[[-c,0,a],[c,0,a],[b,-b,b],[0,-a,c],[-b,-b,b]],[[c,0,-a],[-c,0,-a],[-b,-b,-b],[0,-a,-c],[b,-b,-b]],[[-c,0,-a],[c,0,-a],[b,b,-b],[0,a,-c],[-b,b,-b]],[[0,a,-c],[0,a,c],[b,b,b],[a,c,0],[b,b,-b]],[[0,a,c],[0,a,-c],[-b,b,-b],[-a,c,0],[-b,b,b]],[[0,-a,-c],[0,-a,c],[-b,-b,b],[-a,-c,0],[-b,-b,-b]],[[0,-a,c],[0,-a,-c],[b,-b,-b],[a,-c,0],[b,-b,b]],[[a,c,0],[a,-c,0],[b,-b,b],[c,0,a],[b,b,b]],[[a,-c,0],[a,c,0],[b,b,-b],[c,0,-a],[b,-b,-b]],[[-a,c,0],[-a,-c,0],[-b,-b,-b],[-c,0,-a],[-b,b,-b]],[[-a,-c,0],[-a,c,0],[-b,b,b],[-c,0,a],[-b,-b,b]]];break;case "icosahedron-intersected":phi=(1+Math.sqrt(5))/2;a=1;b=1/phi;c=2-phi;a*=1.5;b*=1.5;c*=1.5;C=[[[0,b,-a],[b,a,0],[-b,a,0]],[[0,0,0],[-b,a,0],[b,a,0]],[[0,0,0],[0,-b,a],[-a,0,b]],[[0,0,0],[a,0,b],[0,-b,a]],[[0,b,-a],[0,0,0],[a,0,-b]],[[0,b,-a],[-a,0,-b],[0,0,0]],[[0,-b,a],[b,-a,0],[-b,-a,0]],[[0,0,0],[-b,-a,0],[b,-a,0]],[[-b,a,0],[-a,0,b],[-a,0,-b]],[[-b,-a,0],[-a,0,-b],[-a,0,b]],[[b,a,0],[a,0,-b],[a,0,b]],[[b,-a,0],[a,0,b],[a,0,-b]],[[0,0,0],[-a,0,b],[-b,a,0]],[[0,0,0],[b,a,0],[a,0,b]],[[0,b,-a],[-b,a,0],[-a,0,-b]],[[0,b,-a],[a,0,-b],[b,a,0]],[[0,0,0],[-a,0,-b],[-b,-a,0]],[[0,0,0],[b,-a,0],[a,0,-b]],[[0,-b,a],[-b,-a,0],[-a,0,b]],[[0,-b,a],[a,0,b],[b,-a,0]]];break;case "icosahedron":phi=(1+Math.sqrt(5))/2;a=1/2;b=1/(2*phi);a*=3;b*=3;C=[[[0,b,-a],[b,a,0],[-b,a,0]],[[0,b,a],[-b,a,0],[b,a,0]],[[0,b,a],[0,-b,a],[-a,0,b]],[[0,b,a],[a,0,b],[0,-b,a]],[[0,b,-a],[0,-b,-a],[a,0,-b]],[[0,b,-a],[-a,0,-b],[0,-b,-a]],[[0,-b,a],[b,-a,0],[-b,-a,0]],[[0,-b,-a],[-b,-a,0],[b,-a,0]],[[-b,a,0],[-a,0,b],[-a,0,-b]],[[-b,-a,0],[-a,0,-b],[-a,0,b]],[[b,a,0],[a,0,-b],[a,0,b]],[[b,-a,0],[a,0,b],[a,0,-b]],[[0,b,a],[-a,0,b],[-b,a,0]],[[0,b,a],[b,a,0],[a,0,b]],[[0,b,-a],[-b,a,0],[-a,0,-b]],[[0,b,-a],[a,0,-b],[b,a,0]],[[0,-b,-a],[-a,0,-b],[-b,-a,0]],[[0,-b,-a],[b,-a,0],[a,0,-b]],[[0,-b,a],[-b,-a,0],[-a,0,b]],[[0,-b,a],[a,0,b],[b,-a,0]]];this.scale=80;break;default:}
|
|
return C;};Poly.prototype.createNCone=function(ngon,ht){var D=[];D[0]=[];var sumx=0;var sumy=0;for(var i=0;i<ngon;i++){var Angle=(Math.PI*2*i)/ngon;D[0][i]=[];D[0][i][0]=Math.sin(Angle)*0.8;D[0][i][1]=Math.cos(Angle)*0.8;D[0][i][2]=-ht/2;sumx=sumx+D[0][i][0];sumy=sumy+D[0][i][1];}
|
|
var apexx=sumx/ngon;var apexy=sumy/ngon;for(i=0;i<ngon;i++){var n=i+1;D[n]=[];D[n][0]=[];D[n][0][0]=apexx;D[n][0][1]=apexy;D[n][0][2]=ht;D[n][1]=[];D[n][1][0]=D[0][i][0];D[n][1][1]=D[0][i][1];D[n][1][2]=D[0][i][2];var i1=i+1;if(i1==ngon)
|
|
i1=0;D[n][2]=[];D[n][2][0]=D[0][i1][0];D[n][2][1]=D[0][i1][1];D[n][2][2]=D[0][i1][2];}
|
|
return D;};Poly.prototype.createNCylinder=function(ngon){var D=[];D[0]=[];for(var i=0;i<ngon;i++){var Angle=(Math.PI*2*i)/ngon;D[0][i]=[];D[0][i][0]=Math.sin(Angle)*0.8;D[0][i][1]=Math.cos(Angle)*0.8;D[0][i][2]=1.4;}
|
|
D[1]=[];for(i=0;i<ngon;i++){Angle=(Math.PI*2*i)/ngon;D[1][i]=[];D[1][i][0]=Math.sin(Angle)*0.8;D[1][i][1]=Math.cos(Angle)*0.8;D[1][i][2]=-1.1;}
|
|
for(i=0;i<ngon;i++){var n=i+2;D[n]=[];var i1=i+1;if(i1==ngon)
|
|
i1=0;D[n][0]=[];D[n][0][0]=D[0][i][0];D[n][0][1]=D[0][i][1];D[n][0][2]=D[0][i][2];D[n][1]=[];D[n][1][0]=D[0][i1][0];D[n][1][1]=D[0][i1][1];D[n][1][2]=D[0][i1][2];D[n][2]=[];D[n][2][0]=D[1][i1][0];D[n][2][1]=D[1][i1][1];D[n][2][2]=D[1][i1][2];D[n][3]=[];D[n][3][0]=D[1][i][0];D[n][3][1]=D[1][i][1];D[n][3][2]=D[1][i][2];}
|
|
return D;};Poly.prototype.sphereNormalise=function(p){var vectorLength=Math.sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);if(vectorLength!=0){p[0]/=vectorLength;p[1]/=vectorLength;p[2]/=vectorLength;}else{p[0]=0;p[1]=0;p[2]=0;}};function Shape3D(){var rotSelfMatrix=[[1,0,0],[0,1,0],[0,0,1],[0,0,0]];var rotSelfQ=false;this.velQ=false;this.lt=w/2;this.tp=(h-topMargin)/2+topMargin;this.eye=new Pt3d;this.eye.setMe(0,0,400);this.pts=[];this.lineweight;this.lineClr='white';this.fillClr='rgba(255,0,0,0.9)';this.shapeType="surf";this.clrMethod="None";this.depth=0;this.showPtsQ=false;this.centroid=new Pt3d();this.vel3d=new Pt3d;this.hideCount=0;}
|
|
Shape3D.prototype.setPts=function(apts){this.pts=[];for(var i=0;i<apts.length;i++){var p3d=new Pt3d;p3d.setMe(apts[i][0],apts[i][1],apts[i][2]);this.pts.push(p3d);}
|
|
this.calcCentroid();};Shape3D.prototype.doShading=function(){var alpha=0.8;switch(this.clrMethod){case 'Glass':alpha=0.5;break;case 'PureGlass':alpha=0.5;break;default:}
|
|
var angle=this.getNormalAngle(this.pts,0);var dark=(1-angle/Math.PI);var red=(dark*255>>0)+1;var grn=(dark*255>>0)+1;angle=this.getNormalAngle(this.pts,1);dark=(1-angle/Math.PI);var blu=(dark*255>>0)+1;this.fillClr='rgba('+red+','+grn+','+blu+','+alpha+')';};Shape3D.prototype.getNormalAngle=function(pts,dimN){var a=[pts[1].x-pts[0].x,pts[1].y-pts[0].y,pts[1].z-pts[0].z];var b=[pts[2].x-pts[1].x,pts[2].y-pts[1].y,pts[2].z-pts[1].z];var cross=[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]];var mag=Math.sqrt(cross[0]*cross[0]+cross[1]*cross[1]+cross[2]*cross[2]);var theta=Math.acos(cross[dimN]/mag);return theta;}
|
|
Shape3D.prototype.calcCentroid=function(){centroid=new Pt3d;for(var i=0;i<this.pts.length;i++){centroid.addPtMe(this.pts[i]);}
|
|
if(this.pts.length>0){centroid.x/=this.pts.length;centroid.y/=this.pts.length;centroid.z/=this.pts.length;}};Shape3D.prototype.drawsurface=function(aboutEyeQ,viewType){var xsum=0;var ysum=0;var zsum=0;var clips=[];var zMin=Number.MAX_VALUE;var zMax=-Number.MAX_VALUE;var i=0;var ptRot;while(i<this.pts.length){var pt3d=this.pts[i];if(this.aboutEyeQ){}else{ptRot=this.matPtMult(transMat,pt3d);clips.push(ptRot);}
|
|
zMin=Math.min(zMin,ptRot.z);zMax=Math.max(zMax,ptRot.z);xsum+=ptRot.x;ysum+=ptRot.y;zsum+=ptRot.z;i++;}
|
|
var pt2s=[];i=0;while(i<clips.length){var p3d=clips[i];var pt=new Pt();pt.x=this.lt+(this.eye.z*(p3d.x))/(this.eye.z+p3d.z);pt.y=this.tp+(this.eye.z*(p3d.y))/(this.eye.z+p3d.z);pt2s.push(pt);i++;}
|
|
var fillQ=true;var strokeQ=true;switch(this.clrMethod){case "Glass":g.lineWidth=1;g.strokeStyle='#000000';g.fillStyle=this.fillClr;break;case "PureGlass":g.lineWidth=3;g.strokeStyle='rgba(205,205,205,0.9)';g.fillStyle=this.fillClr;g.lineJoin="round";break;case "Beams":g.lineWidth=18;g.strokeStyle='#444444';g.fillStyle='rgba(250,250,250,0.2)';g.lineJoin="round";break;case "Shaded":g.fillStyle=this.fillClr;strokeQ=false;break;default:g.lineWidth=1;g.strokeStyle=this.lineClr;g.fillStyle=this.fillClr;}
|
|
if(pt2s.length>2){g.beginPath();for(i=0,len=pt2s.length;i<len;i++){pt=pt2s[i];if(i==0){g.moveTo(pt.x,pt.y);}else{g.lineTo(pt.x,pt.y);}}
|
|
g.closePath();if(strokeQ)g.stroke();if(fillQ)g.fill();}
|
|
var iRecip=1/(pt2s.length+1);xsum*=iRecip;ysum*=iRecip;zsum=f-zsum*iRecip;this.depth=(xsum*xsum+ysum*ysum+zsum*zsum)/10000;};Shape3D.prototype.matPtMult=function(A,B){var C=new Pt3d;C.x=A[0][0]*B.x+A[0][1]*B.y+A[0][2]*B.z;C.y=A[1][0]*B.x+A[1][1]*B.y+A[1][2]*B.z;C.z=A[2][0]*B.x+A[2][1]*B.y+A[2][2]*B.z;return C;};function Pt(){this.x=0;this.y=0;}
|
|
Pt.prototype.toString=function(){return this.x+','+this.y;};function Pt3d(){this.x=0;this.y=0;this.z=0;}
|
|
Pt3d.prototype.setMe=function(x,y,z){this.x=x;this.y=y;this.z=z;};Pt3d.prototype.addPtMe=function(pt3d,factor){factor=typeof factor!=='undefined'?factor:1;if(factor==1){this.x+=pt3d.x;this.y+=pt3d.y;this.z+=pt3d.z;}else{this.x+=pt3d.x*factor;this.y+=pt3d.y*factor;this.z+=pt3d.z*factor;}};function drawNet(){var bareQ=false;var shapes=poly.getNet();var minPt=new Pt();var maxPt=new Pt();for(var i=0;i<shapes.length;i++){for(var j=0;j<shapes[i].length;j++){var pt=new Pt();pt.x=shapes[i][j][0];pt.y=shapes[i][j][1];if(pt.x<minPt.x)minPt.x=pt.x;if(pt.y<minPt.y)minPt.y=pt.y;if(pt.x>maxPt.x)maxPt.x=pt.x;if(pt.y>maxPt.y)maxPt.y=pt.y;}}
|
|
var xSpan=maxPt.x-minPt.x;var ySpan=maxPt.y-minPt.y;var scale=Math.min(w/xSpan,(h-topMargin)/ySpan);var xLeft=(w-xSpan*scale)/2;var yTop=(h-topMargin-ySpan*scale)/2+topMargin;g2.clearRect(0,0,el.width,el.height);if(bareQ){g2.strokeStyle='#000000';g2.fillStyle='white';}else{g2.strokeStyle='#ff4400';g2.fillStyle='rgba(250,230,200,0.3)';}
|
|
for(i=0;i<shapes.length;i++){g2.beginPath();var xStt=0;var yStt=0;for(j=0;j<shapes[i].length;j++){var xPos=(shapes[i][j][0]-minPt.x)*scale+xLeft;var yPos=(shapes[i][j][1]-minPt.y)*scale+yTop;if(j==0){g2.moveTo(xPos,yPos);xStt=xPos;yStt=yPos;}else{g2.lineTo(xPos,yPos);}}
|
|
g2.lineTo(xStt,yStt);g2.fill();g2.stroke();}}
|
|
function convertHexClr(hex,opacity){hex=hex.replace('#','');var r=parseInt(hex.substring(0,2),16);var g=parseInt(hex.substring(2,4),16);var b=parseInt(hex.substring(4,6),16);return 'rgba('+r+','+g+','+b+','+opacity+')';}
|
|
function rgb2hex(color){var hex=[];for(var i=0;i<3;i++){hex.push(color[i].toString(16));if(hex[i].length<2){hex[i]="0"+hex[i];}}
|
|
return "#"+hex[0]+hex[1]+hex[2];}
|
|
String.prototype.capitalize=function(){return this.replace(/(?:^|\s)\S/g,function(a){return a.toUpperCase();});};function canvasGetExtents(can){var g=can.getContext('2d');var wd=can.width*ratio;var ht=can.height*ratio;var idata=g.getImageData(0,0,wd,ht);var buffer=idata.data;var buffer32=new Uint32Array(buffer.buffer);var x,y;var x1=wd,y1=ht,x2=0,y2=0;for(y=0;y<ht;y++){for(x=0;x<wd;x++){if(buffer32[x+y*wd]>0){if(x<x1)x1=x;if(x>x2)x2=x;if(y<y1)y1=y;if(y>y2)y2=y;}}}
|
|
console.log("canvasGetExtents",can,x1,y1,x2,y2);return{left:x1,top:y1,wd:x2-x1,ht:y2-y1}}
|
|
function canvasCrop(c1,rect){var c2=document.createElement('canvas');c2.width=rect.wd;c2.height=rect.ht;var g2=c2.getContext("2d");g2.drawImage(c1,rect.left,rect.top,rect.wd,rect.ht,0,0,rect.wd,rect.ht);return c2;}
|
|
function canvasSave(typ){typ=(typ==undefined)?'png':typ;if(typ=='jpg')typ='jpeg';canID="canvas1";if(netQ)canID="canvas2";var can=document.getElementById(canID);var rect=canvasGetExtents(can);can=canvasCrop(can,rect);var dataUrl=can.toDataURL('image/'+typ);var win=window.open();win.document.write("<img src='"+dataUrl+"'/>");win.document.location="#";}
|
|
function canvasPrint(){canID="canvas1";if(netQ)canID="canvas2";var can=document.getElementById(canID);var rect=canvasGetExtents(can);can=canvasCrop(can,rect);var dataUrl=can.toDataURL('image/png');var win=window.open();win.document.write("<img src='"+dataUrl+"'/>");win.document.location="#";win.setTimeout(function(){win.focus();win.print();},500);}
|
|
function getQueryVariable(variable){var query=window.location.search.substring(1);var vars=query.split("&");for(var i=0;i<vars.length;i++){var pair=vars[i].split("=");if(pair[0]==variable){return pair[1];}}
|
|
return false;} |