//var n=1;
//initial settings
var min1=1;
var max1=1;
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;
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";
}
function setHTML(id,text){
var e=document.getElementById(id);
if (e==null) return;
e.innerHTML=text;
}
function gravity (x){
x=Math.floor(x/50)*50;
return x+25;
}
class Movable {
static DOWN=1;
static UP=2;
static mouse=2;
static x1=0;
static y1=0;
static ctx;
static list=new Array();
static list1=new Array();
static list2=new Array();
static selected=null;
constructor(x,y){
this.x0=x;
this.y0=y;
this.fixed=false;
}
inside(x,y){
return true;
}
draw (ctx1){
;
}
move (e){
if (this.fixed==true) return;
var dx=e.offsetX-Movable.x1;
var dy=e.offsetY-Movable.y1;
this.x0+=dx;
this.y0+=dy;
Movable.x1=e.offsetX;
Movable.y1=e.offsetY;
this.draw(Movable.ctx);
}
fixPosition(x,y){
this.x0=x;
this.y0=y;
this.fixed=true;
}
static mouseUp() {
Movable.mouse=Movable.UP;
/*if (Movable.selected!=null){
Movable.selected.x0=gravity(Movable.selected.x0)+25;
Movable.selected.y0=gravity(Movable.selected.y0)+25;
}*/
}
static mouseDown(e) {
Movable.mouse=Movable.DOWN;
Movable.x1=e.offsetX;
Movable.y1=e.offsetY;
}
static isMouseDown() {
if (Movable.mouse==Movable.DOWN)
return true;
return false;
}
static isInside (e){
for (var i=0;i
=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();
}
}
var c_i=0;
class MyCircle extends Movable {
constructor (xx,y,r,id){
super (xx,y);
this.r=r;
//this.h=h;
this.id=id;
//this.id=c_i++; _error_
}
setlocation (x,y){
this.x0=x;
this.y0=y;
}
inside(x,y){
if(this.fixed==true)
return false;
x-=this.x0;
y-=this.y0;
var r=this.r;
if((x*x+y*y)<(r*r))
return true;
return false;
}
/*move (e){
var x=Math.floor(e.offsetX/50)*50;
var y=Math.floor(e.offsetY/50)*50;
//var dx=e.offsetX-Movable.x1;
//var dy=e.offsetY-Movable.y1;
super.move(e);
var dx=x-Movable.x1;
var dy=y-Movable.y1;
this.x0+=dx;
this.y0+=dy;
Movable.x1=e.offsetX;
Movable.y1=e.offsetY;
this.draw(Movable.ctx);
var newx0=this.x0-300;
var newy0=this.y0-200;
var angleP=Math.atan2(newy0,newx0);
this.x0=300+75*Math.cos(angleP);
this.y0=200+75*Math.sin(angleP);
}*/
draw (ctx){
ctx.strokeStyle="red";
//ctx.fillStyle="white";
ctx.beginPath();
//ctx.fillStyle="white";
if (this.fixed==true) ctx.fillStyle="black";
ctx.font="20px Arial";
ctx.textAlign = "center";
//ctx.arc(this.x0, this.y0, this.r,0,2*Math.PI);
//ctx.fillStyle="white";
ctx.fillStyle="white";
//ctx.fill();
//ctx.fillText(""+this.x0+" "+this.y0,this.x0, this.y0+0);
//if (Math.abs(this.x0-200)<=50 &&Math.abs(this.y0-300)<=50) ctx.fillText(""+this.id,this.x0+300, this.y0+17);
//if (Math.abs(this.x0-300)<=50 &&Math.abs(this.y0-300)<=50) ctx.fillText(""+this.id,this.x0+300, this.y0+17);
//if (Math.abs(this.x0-400)<=50 &&Math.abs(this.y0-300)<=50) ctx.fillText(""+this.id,this.x0+300, this.y0+17);
ctx.stroke();
ctx.fillStyle="black";
ctx.fillText(""+this.id,this.x0, this.y0);
// _error_ ctx.fillText(""+(this.id+1),this.x0, this.y0);
}
}
class MyContainer {
constructor (x,y,r,type, color){
//constructor (x,y,w, h,color){
this.x0=x;
this.y0=y;
this.r=r;
this.type=type;
this.id=0;
this.color=color;
}
inside(x,y){
x-=this.x0;
y-=this.y0;
var r=this.r;
if((x*x+y*y)<(r*r))
return true;
return false;
}
draw (ctx){
ctx.strokeStyle=this.color;
ctx.fillStyle="white";
ctx.beginPath();
ctx.arc(this.x0, this.y0, this.r,0,2*Math.PI);
ctx.fillText(""+this.type,this.x0,this.y0);
ctx.fill();
ctx.stroke();
}
isOK(n){
if (this.inside(n.x0,n.y0)==false)
return 0;
var re=0;
switch (this.type) {
case 1:
if (n.id%2==1)
re= 1;
break;
case 2:
if (n.id%2==0)
re= 1;
break;
case 3:
if (n.id%3==0)
re= 1;
break;
}
}
}
function doMouseDown(event) {
//alert("mouse is down");
//var m=document.getElementById("mouseInfo");
//m.innerHTML="mouse is down";
Movable.mouseDown(event);
Movable.isInside(event);
}
function grab() {
var OK1=0;
for (var i=0;iPlace number 1-12 into the circiles so that the sum of the six numbers on the sides of each triangle are the same.";
setHTML("c2",str);
setHTML("c7","The sum of the two numbers of each side must be the same.");
}else{
setHTML("c1","三角形和圆圈");
str="请将数字 1-12 放在圆圈中(先找到这四个三角形),";
str+=" 并使每个三角形边上的六个数字的和相同.";
setHTML("c2",str);
/*setHTML("c4","Also each of three men hired the son of one of the other men as an assistant;");
setHTML("c5", "Again, though, none of three sons works in a profession that matches his name.");
setHTML("c6", "If Mr.Carpenter is not a potter, can you tell each one's occupation.?");*/
setHTML("c7","三角形每条边上的两个数字的和应该相同.");
}
}else if (n==2){
setHTML("c1","Small difference");
setHTML("c2","To place the digits 2,4,6,7 into the circles, ");
setHTML("c3","so that the difference between two two-digit numbers is as small as possible.");
}
ctx.font="20px Arial";
ctx.textAlign = "center";
ctx.beginPath();
ctx.fillStyle="red";
//===========================
ctx.strokeStyle="light yellow";
var xx1=500;
var yy1=100;
var ww=150;
var hh=250;
ctx.beginPath();
//first line;
ctx.moveTo(xx1, yy1);
ctx.lineTo(xx1+ww, yy1+hh);
//second line;
ctx.moveTo(xx1, yy1);
ctx.lineTo(xx1-ww, yy1+hh);
//third line;
ctx.moveTo(xx1-ww, yy1+hh);
ctx.lineTo(xx1+ww, yy1+hh);
//line 4
ctx.moveTo(xx1, yy1);
ctx.lineTo(xx1, yy1+hh/1.5);
//line 5
ctx.moveTo(xx1, yy1+hh/1.5);
ctx.lineTo(xx1-ww, yy1+hh);
//line 6
ctx.moveTo(xx1, yy1+hh/1.5);
ctx.lineTo(xx1+ww, yy1+hh);
ctx.stroke();
Container1.draw(ctx);
Container2.draw(ctx);
Container3.draw(ctx);
Container4.draw(ctx);
Container5.draw(ctx);
Container6.draw(ctx);
Container7.draw(ctx);
Container8.draw(ctx);
Container9.draw(ctx);
Container10.draw(ctx);
Container11.draw(ctx);
Container12.draw(ctx);
Movable.redraw();
}
function LineEquation(x1,y1,x2,y2,k1,k2){
if ((x1-x2)!=0){
var a=(y1-y2)/(x1-x2);
var b= (-x2*(y1-y2)+y2*(x1-x2))/(x1-x2);
var diffx=x1-x2;
var diffy=y1-y2;
//var length=sqrt(diffx**diffx+diffy**diffy);
var xx1=x1-k1*diffx;
//var yy1=y1+k1*diffy;
var yy1=a*xx1+b;
var xx2=x1-k2*diffx;
//var yy2=y1+k2*diffy;
var yy2=a*xx2+b;
}else{
xx1=x1;
yy1=y1+k1*(-y1+y2);
xx2=x1;
yy2=y1+k2*(-y1+y2);
}
return [xx1,yy1,xx2,yy2];
}
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
function getRandomPara(){
n=getRndInteger(min1,max1);
/*randomNum=getRndInteger(min2,max2);
var id=new Array();
var x=0;
var err;
for (i=0;i<13;i++){
id[i]=x;
}
for (i=0;i<12;i++){
for (k=1;k<100;k++){
err=0;
var ik=Math.floor(Math.random() * randomNum)+2;
for (j=0;j<12;j++){
if(id[j]==ik) err=1;
}
if (err==0) break;
}
id[i]=ik;
}*/
//============================
// Movable.list=new Array();
/*
for (i=1;i<13;i++){
Movable.add(new MyCircle((i)*50,50,20,i))
//Movable.add(new MyCircle((i)*105,60,20,i))
//Movable.add(new MyCircle((i)*35,100,15,id1));
}
*/
/*Movable.list[7].fixPosition(200,305);
Movable.list[2].fixPosition(300,305);
Movable.list[6].fixPosition(450,305);
Movable.list[8].fixPosition(650,305);*/
/* Movable.add(new MyCircle(i*35,30,15,i));
Movable.add(new MyCircle(1*35,30,15,1));
for (i=8;i<10;i++)
Movable.add(new MyCircle(i*35,30,15,i));
for (i=11;i<17;i++)
Movable.add(new MyCircle(i*35,30,15,i));
for (i=18;i<21;i++)
Movable.add(new MyCircle(i*35,30,15,i));*/
//====
}
//======= initializing ========
var radius=100;
var canvas=initCanvas("myCanvas");
var ctx = canvas.getContext("2d");
var paraStr=window.location.search;
Movable.ctx=ctx;
var min1 = 1;
var max1 = 1;
var min2 = 12;
var max2 = 24;
var n=0;
var nPosition;
var randomNum = 0;
grid=new MyRect(350,150,250,200);
if (paraStr.length>3) {
// ?p=min1,max1,min2,max2
var ss=paraStr.substring(3).split(/[=,]+/);
// alert(paraStr+" s[0]="+s[0]+" s["+(s.length-1)+"]="+s[s.length-1]);
if (ss.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);
/*var Container1=new MyContainer(400,200,30,1,"blue");
var Container2=new MyContainer(470,200,30,2,"red");
var Container3=new MyContainer(400,300,30,3,"green");
var Container4=new MyContainer(470,300,30,4,"purple");*/
//var containerlist=new Array();
//var Container1=new MyRect (200,300,40,"Mr.C","blue");
//ctx.fillText("+",250, 300);
var k1=0.4;k2=0.7;
var r =20;
var xy1=LineEquation(500,100,650,350,k1,k2);
var x1=xy1[0];y1=xy1[1]; x2=xy1[2];y2=xy1[3];
var xy2=LineEquation(500,100,350,350,k1,k2);
var x3=xy2[0];y3=xy2[1];x4=xy2[2];y4=xy2[3];
var xy3=LineEquation(350,350,650,350,k1,k2);
var x5=xy3[0];y5=xy3[1];x6=xy3[2];y6=xy3[3];
var xy4=LineEquation(500,100,500,267,k1,k2);
var x7=xy4[0];y7=xy4[1];x8=xy4[2];y8=xy4[3];
var xy5=LineEquation(500,267,350,350,k1,k2);
var x9=xy5[0];y9=xy5[1];x10=xy5[2];y10=xy5[3];
var xy6=LineEquation(500,267,650,350,k1,k2);
var x11=xy6[0];y11=xy6[1];x12=xy6[2];y12=xy6[3];
var ContainerList=[];
var Container1=new MyContainer(x1,y1,r,1);
var Container2=new MyContainer (x2,y2,r,2);
var Container3=new MyContainer (x3,y3,r,3);
var Container4=new MyContainer (x4,y4,r,4);
var Container5=new MyContainer (x5,y5,r,5);
var Container6=new MyContainer(x6,y6,r,6);
var Container7=new MyContainer (x7,y7,r,7);
var Container8=new MyContainer (x8,y8,r,8);
var Container9=new MyContainer (x9,y9,r,9);
var Container10=new MyContainer (x10,y10,r,10);
var Container11=new MyContainer (x11,y11,r,11);
var Container12=new MyContainer (x12,y12,r,12);
//var Container7=new MyContainer (600,300,20,7,"green");
//var Container8=new MyContainer (650,300,20,8,"green");
//var Container9=new MyContainer (750,300,20,9,"green");
ContainerList.push(Container1);
ContainerList.push(Container2);
ContainerList.push(Container3);
ContainerList.push(Container4);
ContainerList.push(Container5);
ContainerList.push(Container6);
ContainerList.push(Container7);
ContainerList.push(Container8);
ContainerList.push(Container9);
ContainerList.push(Container10);
ContainerList.push(Container11);
ContainerList.push(Container12);
Movable.list=new Array();
for (i=1;i<13;i++){
Movable.add(new MyCircle((i)*50,50,20,i))
}
function showHint() {
if (hButton.sel===0)
return;
var str;
if (lang==0){
str="The sum of the two numbers on every side must be the same.";
}else{
str="三角形每条边上的两个数字的和应该相同.";
}
hButton.hText.text=str;
hButton.hText.draw(ctx);
}
var hButton = new ToggleButton((canvas.width>>1)-100,canvas.height-30,200,30,"Show Hint", "Hide Hint",ctx,"green");
hButton.visible=true;
hButton.hText=new MyTextArea(800,200,300,"this is the hint","20px Arial","blue");
getRandomPara();
redraw(ctx);
showOrHide('foot',lang);
showOrHide('title1',lang);
showOrHide('title2',lang);
showOrHide('title3',lang);
setHTML('myBtn',word('Hint'));
setHTML('myreset',word('Reset'));
) processed by MyLexV4 -->