Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 19th, 2012  |  syntax: JavaScript  |  size: 20.34 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // JavaScript Document program game of life
  2. var z;
  3. var c;
  4. var okraj;
  5. var pomca=0;
  6. var suvo=document.getElementById("sun");
  7. var kreslo=document.getElementById("kres");
  8. var obrazce=document.getElementById("obrazce");
  9. var obrazy=document.getElementById("obrazy");
  10. var text=document.getElementById("txt");
  11. var speci=document.getElementById("speci");
  12. var delay=document.getElementById("track1").value;
  13. text.value=delay+" ms";
  14. var moznost;
  15. var vybrate;
  16. var zvecy;
  17. var zvecx;
  18. var n=-1;
  19. var stvorecky = new Array (2000);
  20. var zalozne = new Array (2000);
  21. var utvary= new Array (2000);
  22. var nn;
  23. var p;
  24. var o;
  25. var pam=false;
  26. var f=0;
  27. var geny;
  28. var ending;
  29. var begining;
  30. var x=1;
  31. var y=0;
  32. var xp;
  33. var yp;
  34. var vy= window.innerHeight-33;
  35. var ky= parseInt(vy);
  36. ky=Math.floor(ky/3);
  37. var pom=new Array(10000);
  38. var pf=0;
  39. var timer;
  40. var timer_is_on=0;
  41. var pax=0;
  42. var pey=0;
  43. var vlau=3;
  44. var hex;
  45. var hey;
  46. var ex;
  47. var ey;
  48. var utvr=false;
  49. var zx;
  50. var zy;
  51. function moznosti(){
  52.         if (kreslo.checked==true){
  53.                 tvorba();
  54.         }else if (suvo.checked==true){
  55.                 document.body.style.cursor='pointer';
  56.                         z.onmousedown=function(event){
  57.                                 document.body.style.cursor='move';
  58.                                 xp=event.pageX;
  59.                                 yp=event.pageY;
  60.                                 z.onmousemove=function(event){
  61.                                         document.body.style.cursor='move';
  62.                                         xp=xp-event.pageX;
  63.                                         yp=yp-event.pageY;
  64.                                         x+=xp;
  65.                                         y+=yp;
  66.                                         xp=event.pageX;
  67.                                         yp=event.pageY;
  68.                                         c.clearRect(0,0,z.width,z.height);
  69.                                         c.strokeStyle="orange";
  70.                                         c.lineWidth="4";
  71.                                         c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  72.                                         for (p=0;p<=250;p++){
  73.                                                 for(o=0;o<=ky;o++){
  74.                                                         if(zalozne[p][o]==true){
  75.                                                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  76.                                                         }
  77.                                                 }
  78.                                         }
  79.                                                                
  80.                                 }
  81.                                 z.onmouseup = function() {
  82.                                         z.onmousemove = null;
  83.                                 }
  84.                         }
  85.         }else if (obrazy.checked==true){
  86.                 pdo();
  87.         }else if (speci.checked==true){
  88.                 plne();
  89.         }
  90. }
  91. function tvorba(){
  92.         document.body.style.cursor='crosshair';
  93.         z.onmousedown = function(event){
  94.                 if (timer_is_on==1){
  95.                         clearTimeout(timer);
  96.                         timer_is_on=0;
  97.                 }
  98.                 document.body.style.cursor='crosshair';
  99.                 p = Math.floor((event.clientX+x-okraj)/vlau);
  100.                 o = Math.floor((event.clientY+y)/vlau);
  101.                 if (zalozne[p][o]==true){
  102.                         zalozne[p][o]=false;
  103.                         c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
  104.                         pom[pf]=true;
  105.                         ++pf;
  106.                 }else{
  107.             pom[pf]=false;
  108.             ++pf;
  109.             zalozne[p][o]=true;
  110.             c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  111.                 }
  112.                 z.onmousemove = function(event){
  113.                         document.body.style.cursor='crosshair';
  114.                         p = Math.floor((event.clientX+x-okraj)/vlau);
  115.                         o = Math.floor((event.clientY+y)/vlau);
  116.                         if (pom[pf-1]==true){
  117.                                 zalozne[p][o]=false;
  118.                     c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
  119.                     pom[pf]=true;
  120.                     ++pf;
  121.                 }else{
  122.                     pom[pf]=false;
  123.                     ++pf;
  124.                     zalozne[p][o]=true;
  125.                     c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  126.                 }
  127.                 }
  128.         z.onmouseup = function() {
  129.                 z.onmousemove = null;
  130.                 if (pam==true){
  131.                         play();
  132.                 }
  133.         }
  134.         }
  135. }
  136. function poprve(){
  137.         z = document.getElementById("can");
  138.     z.height=vy;
  139.     okraj = (parseInt(window.innerWidth)-z.width)/2;
  140.     z.style.left=okraj+'px';
  141.     zvecy=z.height;
  142.     zvecx=z.width;
  143.     c = z.getContext("2d");    
  144.         c.fillStyle="black";
  145.     begining = confirm("chcete si vytvorit sami pole?");
  146.     for (i=0; i <=2000; i++){
  147.                 stvorecky[i]=new Array(2000);
  148.         zalozne[i]=new Array(2000);
  149.         utvary[i]=new Array(2000);
  150.     }
  151.         for (p=0;p<=250;p++){
  152.         for(o=0;o<=ky;o++){
  153.                         stvorecky[p][o]=false;
  154.                         zalozne[p][o]=false;
  155.                 utvary[p][o]=false;
  156.                 }
  157.         }              
  158.     if (begining==true){
  159.         moznosti();
  160.     }else{
  161.         pociatek();
  162.     }
  163. }
  164. function pociatek(){
  165.     for (p=0;p<=250;p++){
  166.         for(o=0;o<=ky;o++){
  167.             nn=Math.floor(Math.random()*5);
  168.             if (nn==4){
  169.                 stvorecky[p][o]=true;
  170.                 zalozne[p][o]=true;
  171.                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  172.             }else{
  173.                 stvorecky[p][o]=false;
  174.                 zalozne[p][o]=false;
  175.             }
  176.         }
  177.     }
  178.     doTimer();
  179. }
  180. function krezba(){
  181.         if(timer_is_on==1){
  182.                 pam=true;
  183.         }
  184.         moznosti();
  185.         c.clearRect(0,0,z.width,z.height);
  186.         for (p=0;p<=250;p++){
  187.                 for(o=0;o<=ky;o++){
  188.                         stvorecky[p][o]=zalozne[p][o];
  189.                 }
  190.         }
  191.         for (p=0;p<=250;p++){
  192.         for(o=0;o<=ky;o++){
  193.             f=0;
  194.             --p;--o;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  195.             ++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  196.             ++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  197.             ++o;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  198.             p-=2;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  199.             ++o;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  200.             ++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  201.             ++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
  202.             --p;--o;
  203.             if (stvorecky[p][o]==true){
  204.                 if (f<=1 || f>3){
  205.                     c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
  206.                     zalozne[p][o]=false;
  207.                     f=0;
  208.                 }else{
  209.                                         c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  210.                                 }
  211.             }else{
  212.                 if(f==3){
  213.                                         c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  214.                         zalozne[p][o]=true;
  215.                                 }
  216.                         }
  217.                 }
  218.         }
  219.         if (speci.checked==true && utvr==true){
  220.                 c.strokeStyle="green";
  221.                 c.lineWidth="2";
  222.                 c.strokeRect(hex*vlau-x,hey*vlau-y,(ex*vlau-x)-(hex*vlau-x),(ey*vlau-y)-(hey*vlau-y));
  223.         }
  224.         if(utvr==true){
  225.                 c.strokeStyle="red";
  226.         c.strokeRect(zx,zy,zvecx,zvecy);
  227.         }
  228.         c.strokeStyle="orange";
  229.         c.lineWidth="4";
  230.         c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  231.     delay=document.getElementById("track1").value;
  232.     text.value=delay+" ms";
  233.         if (timer_is_on==1){
  234.                 timer=setTimeout("krezba()",delay);
  235.         }
  236. }
  237. function doTimer(){
  238.         if (!timer_is_on){
  239.                 timer_is_on=1;
  240.                 krezba();
  241.         }
  242. }
  243. function play(){
  244.         doTimer();
  245. }
  246. function pause(){
  247.         pam=false;     
  248.         clearTimeout(timer);
  249.         timer_is_on=0;
  250. }
  251. function zmaz(){
  252.         pam=false;
  253.         clearTimeout(timer);
  254.         timer_is_on=0;
  255.         c.clearRect(0,0,z.width,z.height);
  256.         c.strokeStyle="orange";
  257.         c.lineWidth="4";
  258.         c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  259.         for (p=0;p<=250;p++){
  260.         for(o=0;o<=ky;o++){
  261.                 zalozne[p][o]=false;
  262.                         stvorecky[p][o]=false;
  263.                 }
  264.         }
  265. }
  266. function hraj(){
  267.         pam=false;     
  268.         clearTimeout(timer);
  269.         timer_is_on=0;
  270.         krezba();
  271. }
  272. function plne(){
  273.         z.onmousedown=function(event){
  274.                 utvr=true;
  275.                 hex=Math.floor((event.clientX+x-okraj)/vlau);
  276.                 hey=Math.floor((event.clientY+y)/vlau);
  277.                 z.onmousemove = function(event){
  278.                         ex=Math.floor((event.clientX+x-okraj)/vlau);
  279.                         ey=Math.floor((event.clientY+y)/vlau);
  280.                         if (timer_is_on==0){
  281.                                 c.clearRect(0,0,z.width,z.height);
  282.                                 c.strokeStyle="orange";
  283.                                 c.lineWidth="4";
  284.                                 c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  285.                 for (p=0;p<=250;p++){
  286.                         for(o=0;o<=ky;o++){
  287.                                 if(zalozne[p][o]==true){
  288.                                         c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  289.                             }
  290.                         }
  291.                 }
  292.                         }
  293.                         if(timer_is_on==0){
  294.                                 c.strokeStyle="green";
  295.                                 c.lineWidth="2";
  296.                                 c.strokeRect(hex*vlau-x,hey*vlau-y,(ex*vlau-x)-(hex*vlau-x),(ey*vlau-y)-(hey*vlau-y));
  297.                         }
  298.                 }
  299.                 z.onmouseup = function() {
  300.                         utvr=false;
  301.                         z.onmousemove = null;
  302.                         if(ex<hex){
  303.                                 console.log(hex+" "+ex);
  304.                                 hex=ex+hex;
  305.                                 ex=ex-hex;
  306.                                 hex=hex-ex;
  307.                                 console.log(hex+" "+ex);
  308.                         }
  309.                         if(ey<hey){
  310.                                 ey=hey+ey;
  311.                                 hey=hey-ey;
  312.                                 ey=ey-hey;
  313.                         }
  314.                 for(p=hex;p<=ex;p++){
  315.                         for(o=hey;o<=ey;o++){
  316.                                 zalozne[p][o]=true;
  317.                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  318.                         }
  319.                 }
  320.         }
  321.         }
  322. }
  323. function glidergun(){
  324.         z.onmousemove = function(event){
  325.                 for (p=pax;p<=pax+100;p++){
  326.                         for(o=pey;o<=pey+100;o++){
  327.                                 if (utvary[p][o]==true){
  328.                                         utvary[p][o]=false;
  329.                                 c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
  330.                                 }
  331.                         if (zalozne[p][o]==true){
  332.                                         c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  333.                 }
  334.                         }
  335.                 }
  336.                 p = Math.floor((event.clientX+x-okraj)/vlau);
  337.                 o = Math.floor((event.clientY+y)/vlau);
  338.                 if (o>0 && p>5){
  339.                 pax=p-5;
  340.                 utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  341.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  342.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  343.                 o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  344.                 p+=9;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  345.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  346.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  347.                 o++;p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  348.                 o++;p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  349.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  350.                 p-=2;o-=5;pey=o-5;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  351.                 p++;o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  352.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  353.                 p++;o+=3;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  354.                 p++;o-=2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  355.                 p++;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  356.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  357.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  358.                 p--;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  359.                 p--;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  360.                 p+=5;o-=3;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  361.                 o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  362.                 o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  363.                 p++;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  364.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  365.                 o-=2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  366.                 o--;p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  367.                 p+=2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  368.                 o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  369.                 o+=5;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  370.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  371.                 p-=2;o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  372.                 o-=3;p+=12;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  373.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  374.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  375.                 o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  376.                 }      
  377.                 z.onmousedown=function(){
  378.                 for (p=0;p<=250;p++){
  379.                     for(o=0;o<=ky;o++){
  380.                         if (utvary[p][o]==true){
  381.                             zalozne[p][o]=true;
  382.                             c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  383.                         }
  384.                                 }
  385.                 }
  386.         }
  387.         z.onmouseup=moznosti();
  388.     }
  389. }
  390. function plusak(){
  391.         z.onmousemove=function(event){
  392.                 for (p=pax;p<=pax+100;p++){
  393.                         for(o=pey;o<=pey+100;o++){
  394.                         if (o>0 & p>0){
  395.                                         if (utvary[p][o]==true){
  396.                                 utvary[p][o]=false;
  397.                                 c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
  398.                                         }
  399.                                         if (zalozne[p][o]==true){
  400.                                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  401.                         }
  402.                         }
  403.                         }
  404.                 }
  405.                 p = Math.floor((event.clientX+x-okraj)/vlau);
  406.         o = Math.floor((event.clientY+y)/vlau);
  407.         if (o>16 & p>2){
  408.                 pax=p-2;
  409.                 utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  410.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  411.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  412.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  413.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  414.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  415.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  416.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  417.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  418.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  419.                 p+=12;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  420.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  421.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  422.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  423.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  424.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  425.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  426.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  427.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  428.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  429.                 p-=15;o-=15;pey=o-2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  430.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  431.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  432.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  433.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  434.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  435.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  436.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  437.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  438.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  439.                 o+=12;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  440.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  441.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  442.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  443.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  444.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  445.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  446.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  447.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  448.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  449.                 }
  450.                 z.onmousedown=function(){
  451.                 for (p=0;p<=250;p++){
  452.                     for(o=0;o<=ky;o++){
  453.                         if (utvary[p][o]==true){
  454.                             zalozne[p][o]=true;
  455.                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  456.                         }
  457.                                 }
  458.                         }
  459.                 }
  460.                 z.onmouseup=moznosti();
  461.         }
  462. }
  463. function rovnik(){
  464.         z.onmousemove = function(event){
  465.                 for (p=pax;p<=pax+100;p++){
  466.                         for(o=pey;o<=pey+100;o++){
  467.                         if (o>0 & p>0){
  468.                                         if (utvary[p][o]==true){
  469.                                 utvary[p][o]=false;
  470.                                 c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
  471.                                         }
  472.                                         if (zalozne[p][o]==true){
  473.                                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  474.                         }
  475.                         }
  476.                         }
  477.                 }
  478.                 p = Math.floor((event.clientX+x-okraj)/vlau);
  479.         o = Math.floor((event.clientY+y)/vlau);
  480.         if (o>11 & p>2){
  481.                 pax=p-2;
  482.                 utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  483.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  484.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  485.                 p+=14;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  486.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  487.                 p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  488.                 p-=9;o-=9;pey=o-2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  489.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  490.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  491.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  492.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  493.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  494.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  495.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  496.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  497.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  498.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  499.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  500.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  501.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  502.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  503.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  504.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  505.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  506.                 o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  507.         }
  508.                 z.onmousedown=function(){
  509.                 for (p=0;p<=250;p++){
  510.                     for(o=0;o<=ky;o++){
  511.                         if (utvary[p][o]==true){
  512.                             zalozne[p][o]=true;
  513.                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  514.                         }
  515.                                 }
  516.                         }
  517.                 }
  518.                 z.onmouseup=moznosti();
  519.         }
  520. }
  521. function pdo(){
  522.         moznost=obrazce.options[obrazce.selectedIndex];
  523.         vybrate=moznost.value;
  524.         if(vybrate==1){
  525.                 glidergun();
  526.         }else if (vybrate==2){
  527.                 plusak();      
  528.         }else if (vybrate==3){
  529.                 rovnik();
  530.         }
  531. }
  532. function handle(delta, event) {
  533.         if (delta < 0 && vlau>1){
  534.         x-=Math.floor((z.width/vlau)/2);
  535.         y-=Math.floor((z.height/vlau)/2);
  536.         vlau--;
  537.                 --n;
  538.         }else if (delta > 0 && vlau<20){
  539.             zvecx=z.width/(vlau);
  540.             zvecy=z.height/(vlau);
  541.             ++n;
  542.             zvecsuj();
  543.         }
  544.         if (timer_is_on==0){
  545.                 c.clearRect(0,0,z.width,z.height);
  546.                 c.strokeStyle="orange";
  547.                 c.lineWidth="4";
  548.                 c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  549.         for (p=0;p<=250;p++){
  550.                         for(o=0;o<=ky;o++){
  551.                 if(zalozne[p][o]==true){
  552.                         c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  553.                 }
  554.             }
  555.         }
  556.         }
  557. }
  558. function zvecsuj(){
  559.         z.onmousemove=function(event){
  560.                 utvr=true;
  561.         zvecx=z.width/(vlau);
  562.         zvecy=z.height/(vlau);
  563.         zvecx=z.width-zvecx;
  564.         zvecy=z.height-zvecy;
  565.         if (timer_is_on==0){
  566.                         c.clearRect(0,0,z.width,z.height);
  567.                         c.strokeStyle="orange";
  568.                         c.lineWidth="4";
  569.                         c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  570.             for (p=0;p<=250;p++){
  571.                 for(o=0;o<=ky;o++){
  572.                         if(zalozne[p][o]==true){
  573.                         c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  574.                     }
  575.                 }
  576.             }
  577.                 }
  578.         zx=(event.clientX-okraj)-(zvecx/2);
  579.         zy=(event.clientY)-(zvecy/2);
  580.         c.strokeStyle="red";
  581.         c.strokeRect(zx,zy,zvecx,zvecy);
  582.         z.onmousedown=function(){
  583.                 utvr=false;
  584.                 vlau++;
  585.                 x+=Math.floor((event.clientX-okraj)-(zvecx/2));
  586.                 y+=Math.floor((event.clientY)-(zvecy/2));
  587.                 c.clearRect(0,0,z.width,z.height);
  588.                         c.strokeStyle="orange";
  589.                         c.lineWidth="4";
  590.                         c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
  591.                 for (p=0;p<=250;p++){
  592.                 for(o=0;o<=ky;o++){
  593.                         if(zalozne[p][o]==true){
  594.                                 c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
  595.                         }
  596.                         }
  597.                 }
  598.             moznosti();
  599.         }
  600.     }    
  601. }
  602. function wheel(event){
  603.         var delta = 0;
  604.     if (!event){
  605.         event = window.event;
  606.         }
  607.         if (event.wheelDelta) {
  608.         delta = event.wheelDelta/120;
  609.         }else if (event.detail) {
  610.         delta = -event.detail/3;
  611.     }
  612.     if (delta){
  613.         handle(delta, event);
  614.         }
  615.                 if (event.preventDefault)
  616.                 event.preventDefault();
  617.                         event.returnValue = false;
  618. }
  619. if (window.addEventListener){
  620.         window.addEventListener('DOMMouseScroll', wheel, false);
  621. }
  622. window.onmousewheel = document.onmousewheel = wheel;
  623. window.addEventListener("load",poprve,false);