tangram
function toggleHelp() {
var help="help"+langStr(lang);
var ele=document.getElementById(help);
ele.hidden=!ele.hidden;
if (ele.hidden==true) {
ele=document.getElementById("helpBtn");
ele.innerHTML="Help";
} else {
ele=document.getElementById("helpBtn");
ele.innerHTML="Hide Help";
}
}
//var n=1;
//initial settings
var min1=1;
var max1=5;
var min2=12;
var max2=50;
var GONews;
var grid;
//counter
var h=0;
var m=0;
var s=0;
var c = 0;
var t;
var timer_is_on = 0;
var listFigure=[];
function timedCount() {
s=s+1;
if (s==60){
m=m+1;
s=0;
}
if(m==60){
h=h+1;
m=0;
}
document.getElementById("txt").innerHTML = h + ":" + m + ":" + s;
if (h<10){
document.getElementById("txt").innerHTML = "0"+h + ":" + m + ":" + s;
if (s<10&&m<10)document.getElementById("txt").innerHTML = "0"+h + ":0" + m + ":0" + s;
if (s>10&&m<10)document.getElementById("txt").innerHTML = "0"+h + ":0" + m + ":" + s;
if (s<10&&m>10)document.getElementById("txt").innerHTML = "0"+h + ":" + m + ":0" + s;
}else if(m<10){
document.getElementById("txt").innerHTML = h + ":0" + m + ":" + s;
if (s<10)document.getElementById("txt").innerHTML = h + ":0" + m + ":0" + s;
}
//c = c + 1;
t = setTimeout(timedCount, 1000);
}
function startCount() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
clearTimeout(t);
timer_is_on = 0;
}
function resetCount() {
clearTimeout(t);
timer_is_on = 0;
s=0;
m=0;
h=0;
document.getElementById("txt").innerHTML = "00:00:00";
}
// Hint tag
//document.getElementById("myBtn").onclick = function() {myFunction()};
/* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
function setHTML(id,text){
var e=document.getElementById(id);
if (e==null) return;
e.innerHTML=text;
}
) processed by MyLexV4 -->
class MyRect extends Movable {
constructor (x,y,w,h){
super (x,y);
this.w=w;
this.h=h;
//this.id=id;
}
inside(x,y){
x-=this.x0;
y-=this.y0;
if(x>=0 && x<=this.w && y>=0 &&y<=this.h)
return true;
return false;
}
draw (ctx){
/*ctx.fillStyle="blue";
ctx.fillRect(this.x0, this.y0, this.w, this.h);
;*/
ctx.strokeStyle=this.color;
ctx.beginPath();
ctx.rect(this.x0, this.y0, this.w,this.h);
ctx.stroke();
}
}
function doMouseDown(event) {
//alert("mouse is down");
//var m=document.getElementById("mouseInfo");
//m.innerHTML="mouse is down";
Movable.mouseDown(event);
Movable.isInside(event);
TGP.isInside(event);
}
function doMouseUp(event) {
//alert("mouse is up");
//var m=document.getElementById("mouseInfo");
//m.innerHTML="mouse is up";
Movable.mouseUp();
//Movable.positionOK();
var inGrid=0;
for (var i=0;i':
case '.':
case 'ArrowRight':
da=-45;
break;
default:
return;
}
if (Movable.rotSelected(da,mirror)) {
redraw(Movable.ctx);
}
//var m=document.getElementById("mouseInfo");
//m.innerHTML="mouse is wheeling: ("+event.offsetX+", "+event.offsetY+")";
}
/*
function doClick(event) {
var str="";
if (isFullScreen(ctx)) {
str="fullscreen";
redraw(ctx);
}else
str="not fullscreen";
}
var fullScreen=false;
*/
function initCanvas(canvasName) {
var canvas = document.getElementById(canvasName);
initMyCanvasAndScreen(canvas,redraw, resizeTGP);
canvas.addEventListener('mousedown',doMouseDown,false);
canvas.addEventListener('mouseup',doMouseUp,false);
canvas.addEventListener('mousemove',doMouseMove,false);
canvas.addEventListener('mousewheel',doMouseWheel,false);
document.addEventListener('keydown',doKeyDown);
//document.addEventListener('keyup', doKeyUp);
//document.addEventListener('click',doClick);
return canvas;
}
function redraw(ctx,caller="") {
var n=getRndInteger(min1,max1);
ctx.fillStyle="white";
ctx.fillRect(0,0,canvas.width,canvas.height);
//ctx.arc(0,0,50,0,2*Math.PI);
for (var i=0;i3) {
// ?p=min1,max1,min2,max2
var s=paraStr.substring(3).split(/[=,]+/);
// alert(paraStr+" s[0]="+s[0]+" s["+(s.length-1)+"]="+s[s.length-1]);
if (s.length==2) {
//N=parseInt(s[0]);
min1=parseInt(s[0]);
max1=parseInt(s[1]);
//min2=parseInt(s[2]);
//max2=parseInt(s[3]);
}
// alert("min1="+min1+" "+max1+" "+min2+" "+max2);
}
//var n=getRndInteger(min1,max1);
//var randomNum=getRndInteger(min2,max2);
getRandomPara();
//==========================
//Tangram Square for initiation
//==========================
var fig, ix=10, iy=200, w=10*TGP.scale, dw=w;
fig = new TGP("person 1",w,ix,iy); listFigure.push(fig); iy+=dw*7;
fig = new TGP("person 2", w,ix,iy); listFigure.push(fig); iy+=dw*7;
fig = new TGP("person 3", w,ix-10,iy); listFigure.push(fig); iy+=dw*7;
fig = new TGP("person 4", w,ix,iy); listFigure.push(fig); iy+=dw*7;
fig = new TGP("person 5", w,ix,iy); listFigure.push(fig); iy+=dw*7;
fig = new TGP("person 6", w,ix-10,iy); listFigure.push(fig); iy+=dw*6;
fig = new TGP("person 7", w,ix,iy); listFigure.push(fig); iy+=dw*3;
fig = new TGP("person 8", w,ix+40,iy-10); listFigure.push(fig); ix+=dw*8;
fig = new TGP("person 9", w,ix,iy); listFigure.push(fig); ix+=dw*7;
fig = new TGP("person 10", w,ix,iy-25); listFigure.push(fig); ix+=dw*3;
fig = new TGP("person 11", w,ix,iy-25); listFigure.push(fig); ix+=dw*3;
fig = new TGP("person 12", w,ix,iy-20); listFigure.push(fig); ix+=dw*6;
fig = new TGP("person 13", w,ix,iy-20); listFigure.push(fig); ix+=dw*6;
fig = new TGP("person 14", w,ix,iy-20); listFigure.push(fig); ix+=dw*6;
fig = new TGP("person 15", w,ix,iy-20); listFigure.push(fig); ix+=dw*3;
fig = new TGP("person 16", w,ix,iy-20); listFigure.push(fig); ix+=dw*4;
fig = new TGP("person 17", w,ix,iy-20); listFigure.push(fig); ix+=dw*5;
fig = new TGP("person 18", w,ix,iy-20); listFigure.push(fig); ix+=dw*6;
fig = new TGP("person 19", w,ix,iy-20); listFigure.push(fig); ix+=dw*5;
fig = new TGP("person 20", w,ix,iy-20); listFigure.push(fig); ix+=dw*4;
fig = new TGP("person 21", w,ix,iy-20); listFigure.push(fig); ix+=dw*5;
fig = new TGP("person 22", w,ix,iy-30); listFigure.push(fig); ix+=dw*3;
fig = new TGP("person 23", w,ix,iy-20); listFigure.push(fig); ix+=dw*5;
fig = new TGP("person 24", w,ix,iy-40); listFigure.push(fig); ix+=dw*4;
fig = new TGP("person 25", w,ix,iy-30); listFigure.push(fig); ix+=dw*6;
fig = new TGP("person 26", w,ix,iy-10); listFigure.push(fig); ix+=dw*6;
fig = new TGP("person 27", w,ix-20,iy-70); listFigure.push(fig); iy+=dw*(-6);
fig = new TGP("person 28", w,ix-20,iy-70); listFigure.push(fig); iy+=dw*(-6);
fig = new TGP("person 29", w,ix-25,iy-70); listFigure.push(fig); iy+=dw*(-6);
fig = new TGP("person 30", w,ix-40,iy-70); listFigure.push(fig); iy+=dw*(-6);
fig = new TGP("person 31", w,ix-20,iy-70); listFigure.push(fig); iy+=dw*(-6);
fig = new TGP("person 32", w,ix-20,iy-70); listFigure.push(fig); iy+=dw*(-4);
fig = new TGP("person 33", w,ix-50,iy-70); listFigure.push(fig); iy+=dw*(-6);
rearrangeTPG(listFigure, canvas); // auto arrangements
resizeTGP();
//fig = new TGP("Duck",w, ix,iy); listFigure.push(fig); iy+=dw*5;
var pieces = new TGP("Square",50, 8*50,3*50, 0, false); // Movable.list.push(pieces); iy+=dw*6;
pieces.type="";
fig = new TGP("Person 3",50, (20-12)*W,W*2, 7);// listFigure.push(fig); iy+=dw*6;
fig.visible=false;
TGP.offsetY=20;
redraw(ctx);
function toggleScale(toDraw=true) {
if (TGP.scale==1) {
ctx.save();
/*
canvas.width*=2;
canvas.height*=2;
ctx.scale(2,2);
TGP.scale=2;
*/
} else {
ctx.restore();
TGP.scale=1;
}
if (toDraw==true)
redraw(ctx);
}
function save() {
pieces.save("textArea");
redraw(ctx);
}
showOrHide("title", lang);
showOrHide('foot',lang);
window;
//openFullscreen();
) processed by MyLexV4 -->