%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /data/down/eBOOKS/ebooks/Matlab a Simulink/Matlab Pro Lamy/Game Of Life/
Upload File :
Create Path :
Current File : //data/down/eBOOKS/ebooks/Matlab a Simulink/Matlab Pro Lamy/Game Of Life/life.m

clear;
clc;

x_max = 200; % sirka plochy
y_max = 200; % vyska plochy

color_on  = 1000;   % barva zive bunky
color_off = 0;      % barva nezive bunky

deska = round(rand(y_max,x_max)).*color_on;   % nahodne vytvori desku

pom_deska = deska.*0;   % vytvori a vynuluje pomocnou desku


image(deska);

for iterace=1:10
    
    for y = 1:y_max      
        for x = 1:x_max
            
            pocet_sousedu = 0;
            
            if ( x > 1 )
                if ( deska(y,x-1) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
            
            if ( x < x_max )
                if ( deska(y,x+1) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
            
            if ( y > 1 )
                if ( deska(y-1,x) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
            
            if ( y < y_max )
                if ( deska(y+1,x) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
            
            if ( x > 1 ) && ( y > 1 )
                if ( deska(y-1,x-1) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end

            if ( x < x_max ) && ( y > 1 )
                if ( deska(y-1,x+1) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
            
            if ( x < x_max ) && ( y < y_max )
                if ( deska(y+1,x+1) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
            
            if ( x > 1 ) && ( y < y_max )
                if ( deska(y+1,x-1) == color_on )
                    pocet_sousedu = pocet_sousedu +1;
                end
            end
                        
            
            if ( pocet_sousedu == 3 )
                pom_deska(y,x) = color_on;
            else
                pom_deska(y,x) = color_off;
            end
       
        end
    end
    
    deska = pom_deska;
    image(deska);
    pause (0.5)
end

Zerion Mini Shell 1.0