// JavaScript Document program game of life
var z;
var c;
var okraj;
var pomca=0;
var suvo=document.getElementById("sun");
var kreslo=document.getElementById("kres");
var obrazce=document.getElementById("obrazce");
var obrazy=document.getElementById("obrazy");
var text=document.getElementById("txt");
var speci=document.getElementById("speci");
var delay=document.getElementById("track1").value;
text.value=delay+" ms";
var moznost;
var vybrate;
var zvecy;
var zvecx;
var n=-1;
var stvorecky = new Array (2000);
var zalozne = new Array (2000);
var utvary= new Array (2000);
var nn;
var p;
var o;
var pam=false;
var f=0;
var geny;
var ending;
var begining;
var x=1;
var y=0;
var xp;
var yp;
var vy= window.innerHeight-33;
var ky= parseInt(vy);
ky=Math.floor(ky/3);
var pom=new Array(10000);
var pf=0;
var timer;
var timer_is_on=0;
var pax=0;
var pey=0;
var vlau=3;
var hex;
var hey;
var ex;
var ey;
var utvr=false;
var zx;
var zy;
function moznosti(){
if (kreslo.checked==true){
tvorba();
}else if (suvo.checked==true){
document.body.style.cursor='pointer';
z.onmousedown=function(event){
document.body.style.cursor='move';
xp=event.pageX;
yp=event.pageY;
z.onmousemove=function(event){
document.body.style.cursor='move';
xp=xp-event.pageX;
yp=yp-event.pageY;
x+=xp;
y+=yp;
xp=event.pageX;
yp=event.pageY;
c.clearRect(0,0,z.width,z.height);
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if(zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
z.onmouseup = function() {
z.onmousemove = null;
}
}
}else if (obrazy.checked==true){
pdo();
}else if (speci.checked==true){
plne();
}
}
function tvorba(){
document.body.style.cursor='crosshair';
z.onmousedown = function(event){
if (timer_is_on==1){
clearTimeout(timer);
timer_is_on=0;
}
document.body.style.cursor='crosshair';
p = Math.floor((event.clientX+x-okraj)/vlau);
o = Math.floor((event.clientY+y)/vlau);
if (zalozne[p][o]==true){
zalozne[p][o]=false;
c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
pom[pf]=true;
++pf;
}else{
pom[pf]=false;
++pf;
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
z.onmousemove = function(event){
document.body.style.cursor='crosshair';
p = Math.floor((event.clientX+x-okraj)/vlau);
o = Math.floor((event.clientY+y)/vlau);
if (pom[pf-1]==true){
zalozne[p][o]=false;
c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
pom[pf]=true;
++pf;
}else{
pom[pf]=false;
++pf;
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
z.onmouseup = function() {
z.onmousemove = null;
if (pam==true){
play();
}
}
}
}
function poprve(){
z = document.getElementById("can");
z.height=vy;
okraj = (parseInt(window.innerWidth)-z.width)/2;
z.style.left=okraj+'px';
zvecy=z.height;
zvecx=z.width;
c = z.getContext("2d");
c.fillStyle="black";
begining = confirm("chcete si vytvorit sami pole?");
for (i=0; i <=2000; i++){
stvorecky[i]=new Array(2000);
zalozne[i]=new Array(2000);
utvary[i]=new Array(2000);
}
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
stvorecky[p][o]=false;
zalozne[p][o]=false;
utvary[p][o]=false;
}
}
if (begining==true){
moznosti();
}else{
pociatek();
}
}
function pociatek(){
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
nn=Math.floor(Math.random()*5);
if (nn==4){
stvorecky[p][o]=true;
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}else{
stvorecky[p][o]=false;
zalozne[p][o]=false;
}
}
}
doTimer();
}
function krezba(){
if(timer_is_on==1){
pam=true;
}
moznosti();
c.clearRect(0,0,z.width,z.height);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
stvorecky[p][o]=zalozne[p][o];
}
}
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
f=0;
--p;--o;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
++o;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
p-=2;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
++o;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
++p;if((o<0 || p<0) ||(o>ky+1 || p>250+1)){f=0;}else if(stvorecky[p][o]==true){++f;}
--p;--o;
if (stvorecky[p][o]==true){
if (f<=1 || f>3){
c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
zalozne[p][o]=false;
f=0;
}else{
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}else{
if(f==3){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
zalozne[p][o]=true;
}
}
}
}
if (speci.checked==true && utvr==true){
c.strokeStyle="green";
c.lineWidth="2";
c.strokeRect(hex*vlau-x,hey*vlau-y,(ex*vlau-x)-(hex*vlau-x),(ey*vlau-y)-(hey*vlau-y));
}
if(utvr==true){
c.strokeStyle="red";
c.strokeRect(zx,zy,zvecx,zvecy);
}
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
delay=document.getElementById("track1").value;
text.value=delay+" ms";
if (timer_is_on==1){
timer=setTimeout("krezba()",delay);
}
}
function doTimer(){
if (!timer_is_on){
timer_is_on=1;
krezba();
}
}
function play(){
doTimer();
}
function pause(){
pam=false;
clearTimeout(timer);
timer_is_on=0;
}
function zmaz(){
pam=false;
clearTimeout(timer);
timer_is_on=0;
c.clearRect(0,0,z.width,z.height);
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
zalozne[p][o]=false;
stvorecky[p][o]=false;
}
}
}
function hraj(){
pam=false;
clearTimeout(timer);
timer_is_on=0;
krezba();
}
function plne(){
z.onmousedown=function(event){
utvr=true;
hex=Math.floor((event.clientX+x-okraj)/vlau);
hey=Math.floor((event.clientY+y)/vlau);
z.onmousemove = function(event){
ex=Math.floor((event.clientX+x-okraj)/vlau);
ey=Math.floor((event.clientY+y)/vlau);
if (timer_is_on==0){
c.clearRect(0,0,z.width,z.height);
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if(zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
if(timer_is_on==0){
c.strokeStyle="green";
c.lineWidth="2";
c.strokeRect(hex*vlau-x,hey*vlau-y,(ex*vlau-x)-(hex*vlau-x),(ey*vlau-y)-(hey*vlau-y));
}
}
z.onmouseup = function() {
utvr=false;
z.onmousemove = null;
if(ex<hex){
console.log(hex+" "+ex);
hex=ex+hex;
ex=ex-hex;
hex=hex-ex;
console.log(hex+" "+ex);
}
if(ey<hey){
ey=hey+ey;
hey=hey-ey;
ey=ey-hey;
}
for(p=hex;p<=ex;p++){
for(o=hey;o<=ey;o++){
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
}
function glidergun(){
z.onmousemove = function(event){
for (p=pax;p<=pax+100;p++){
for(o=pey;o<=pey+100;o++){
if (utvary[p][o]==true){
utvary[p][o]=false;
c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
if (zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
p = Math.floor((event.clientX+x-okraj)/vlau);
o = Math.floor((event.clientY+y)/vlau);
if (o>0 && p>5){
pax=p-5;
utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p+=9;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p-=2;o-=5;pey=o-5;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;o+=3;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;o-=2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p--;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p--;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p+=5;o-=3;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o-=2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o--;p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p+=2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o+=5;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p-=2;o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o-=3;p+=12;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o--;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
z.onmousedown=function(){
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if (utvary[p][o]==true){
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
z.onmouseup=moznosti();
}
}
function plusak(){
z.onmousemove=function(event){
for (p=pax;p<=pax+100;p++){
for(o=pey;o<=pey+100;o++){
if (o>0 & p>0){
if (utvary[p][o]==true){
utvary[p][o]=false;
c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
if (zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
p = Math.floor((event.clientX+x-okraj)/vlau);
o = Math.floor((event.clientY+y)/vlau);
if (o>16 & p>2){
pax=p-2;
utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p+=12;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p-=15;o-=15;pey=o-2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o+=12;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
z.onmousedown=function(){
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if (utvary[p][o]==true){
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
z.onmouseup=moznosti();
}
}
function rovnik(){
z.onmousemove = function(event){
for (p=pax;p<=pax+100;p++){
for(o=pey;o<=pey+100;o++){
if (o>0 & p>0){
if (utvary[p][o]==true){
utvary[p][o]=false;
c.clearRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
if (zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
p = Math.floor((event.clientX+x-okraj)/vlau);
o = Math.floor((event.clientY+y)/vlau);
if (o>11 & p>2){
pax=p-2;
utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p+=14;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
p-=9;o-=9;pey=o-2;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
o++;utvary[p][o]=true;c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
z.onmousedown=function(){
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if (utvary[p][o]==true){
zalozne[p][o]=true;
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
z.onmouseup=moznosti();
}
}
function pdo(){
moznost=obrazce.options[obrazce.selectedIndex];
vybrate=moznost.value;
if(vybrate==1){
glidergun();
}else if (vybrate==2){
plusak();
}else if (vybrate==3){
rovnik();
}
}
function handle(delta, event) {
if (delta < 0 && vlau>1){
x-=Math.floor((z.width/vlau)/2);
y-=Math.floor((z.height/vlau)/2);
vlau--;
--n;
}else if (delta > 0 && vlau<20){
zvecx=z.width/(vlau);
zvecy=z.height/(vlau);
++n;
zvecsuj();
}
if (timer_is_on==0){
c.clearRect(0,0,z.width,z.height);
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if(zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
}
function zvecsuj(){
z.onmousemove=function(event){
utvr=true;
zvecx=z.width/(vlau);
zvecy=z.height/(vlau);
zvecx=z.width-zvecx;
zvecy=z.height-zvecy;
if (timer_is_on==0){
c.clearRect(0,0,z.width,z.height);
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if(zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
}
zx=(event.clientX-okraj)-(zvecx/2);
zy=(event.clientY)-(zvecy/2);
c.strokeStyle="red";
c.strokeRect(zx,zy,zvecx,zvecy);
z.onmousedown=function(){
utvr=false;
vlau++;
x+=Math.floor((event.clientX-okraj)-(zvecx/2));
y+=Math.floor((event.clientY)-(zvecy/2));
c.clearRect(0,0,z.width,z.height);
c.strokeStyle="orange";
c.lineWidth="4";
c.strokeRect(1-x,0-y,(250*vlau)+1,ky*vlau+2);
for (p=0;p<=250;p++){
for(o=0;o<=ky;o++){
if(zalozne[p][o]==true){
c.fillRect(p*vlau-x,o*vlau-y,vlau,vlau);
}
}
}
moznosti();
}
}
}
function wheel(event){
var delta = 0;
if (!event){
event = window.event;
}
if (event.wheelDelta) {
delta = event.wheelDelta/120;
}else if (event.detail) {
delta = -event.detail/3;
}
if (delta){
handle(delta, event);
}
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
if (window.addEventListener){
window.addEventListener('DOMMouseScroll', wheel, false);
}
window.onmousewheel = document.onmousewheel = wheel;
window.addEventListener("load",poprve,false);