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0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,1,1,0,0,0,1,1,0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,1,0,0,0,0,1,0,0,0,0,0,1,0,0},
}

function rnde()
   local x
   repeat
      x=rnd(1,16)
   until x%2==0
   return x
end

function rndo()
   local x
   repeat
      x=rnd(1,16)
   until x%2==1
   return x
end

function spal()
   local i,j
   j=1
   for i=1,15 do
      pal[j]=peek(0x03fc0+i*3)
      pal[j+1]=peek(0x03fc0+i*3+1)
      pal[j+2]=peek(0x03fc0+i*3+2)
      j=j+3
   end
end

function rpal()
   local i,j
   j=1
   for i=1,15 do
      poke(0x03fc0+i*3, pal[j])
      poke(0x03fc0+i*3+1, pal[j+1])
      poke(0x03fc0+i*3+2, pal[j+2])
      j=j+3
   end
end

function BOOT()
   t=0
   max=0
   res=0
   idx=1
   fl=1
   spal()
   cls()
end

function TIC()
   t=t+1
      for i=0,max do
         y=i//11
         x=i%11
         if px[idx][i+1]==1 then
            circ(60+x*12,8+y*12,5,rndo()) 
         else
            circ(60+x*12,8+y*12,5,rnde())
         end
      end
      if max==120 then
         if fl==1 then
            for i=1,15,2 do
               poke(0x03fc0+3*i,0)
               poke(0x03fc0+3*i+1,0)
               poke(0x03fc0+3*i+2,0)
            end
            fl=0
         end
         res=res+1
      else
         max=max+1
      end
      if res==100 then
         res=0
         max=0
         idx=idx+1
         if idx>#px then
            idx=1
         end
         fl=1
         rpal()
         cls()
      end
end
