varbrd2=JXG.JSXGraph.initBoard('box2',{boundingbox:[-0.02631578947368421,1.0263157894736843,1.2894736842105263,-0.02631578947368421]});varlevel=0;functionrun(){JXG.JSXGraph.freeBoard(brd2);brd2=JXG.JSXGraph.initBoard('box2',{boundingbox:[-0.02631578947368421,1.0263157894736843,1.2894736842105263,-0.02631578947368421]});level++;brd2.suspendUpdate();paint();brd2.unsuspendUpdate();}functionpaint(){// Initial trianglevarxCoords=[0,1,0.5];varyCoords=[0,0,1];drawPolygon(xCoords,yCoords,level);drawTriangle({x:0,y:0},{x:1,y:0},{x:0.5,y:1},level);}functiondrawPolygon(xCoords,yCoords,level){p1=brd2.create('point',[xCoords[0],yCoords[0]],{visible:false,name:'',withLabel:false});p2=brd2.create('point',[xCoords[1],yCoords[1]],{visible:false,name:'',withLabel:false});p3=brd2.create('point',[xCoords[2],yCoords[2]],{visible:false,name:'',withLabel:false});varcolors=['#000000','#665566','#994499','#BB33BB','#EE99FF','#FFCCFF'];l1=brd2.create('line',[p1,p2],{straightFirst:false,straightLast:false,strokeColor:colors[level%6],name:'',withLabel:false});l2=brd2.create('line',[p2,p3],{straightFirst:false,straightLast:false,strokeColor:colors[level%6],name:'',withLabel:false});l3=brd2.create('line',[p3,p1],{straightFirst:false,straightLast:false,strokeColor:colors[level%6],name:'',withLabel:false});}functiondrawTriangle(a,b,c,level){if(level==0)return;level-=1;// In das übergebene Dreieck, wird ein auf dem Kopf stehendes Dreieck eingefügtvarxCoords=[c.x,(c.x+b.x)/2,(a.x+c.x)/2];varyCoords=[b.y,(c.y+a.y)/2,(c.y+a.y)/2];drawPolygon(xCoords,yCoords,level);// 3 neue Dreiecke bestimmena1=a;b1={x:c.x,y:b.y};c1={x:(a.x+c.x)/2,y:(c.y+a.y)/2};drawTriangle(a1,b1,c1,level);a2={x:c.x,y:b.y};b2=b;c2={x:(c.x+b.x)/2,y:(c.y+a.y)/2};drawTriangle(a2,b2,c2,level);a3={x:(a.x+c.x)/2,y:(c.y+a.y)/2};b3={x:(c.x+b.x)/2,y:(c.y+a.y)/2};c3=c;drawTriangle(a3,b3,c3,level);}paint();