image thumbnail

Object oriented program demo: animated traffic lights on road intersection

by

 

24 Sep 2012 (Updated )

simple classes and superclass are used to arrange flexible object oriented programming environment

map
classdef map
    %static view of at road intersection
    % no  traffic lights, no animation
    properties
        g9=[0.9 0.9 0.8] %gray color / szary
    end
    
    methods
        function obj=map()
            %% East (from West to East)
            rectangle('Position',[4,4,7,6.7],'FaceColor',obj.g9,'Curvature',0.1);
            line([4,11],[12,12],'LineStyle','--');
            line([4,11],[13,13],'LineStyle','-');
            line([4,11],[14,14],'LineStyle','--');
            line([9,10.75],[12.5,12.5]);
            line([10.75,10.75],[12.5,12.5],'Marker','>');
            line([9,10.75],[11.5,11.5]);
            line([10.75,10.75],[11.5,11.5],'Marker','>');
            line([10.25,10.25],[11.5,11.25]);
            line([10.25,10.25],[11.25,11.25],'Marker','v');
            line([10.25,10.25],[12.5,12.75]);
            line([10.25,10.25],[12.75,12.75],'Marker','^');
            
            %% North (from South to North)
            rectangle('Position',[15,4,7,6.7],'FaceColor',obj.g9,'Curvature',0.1);
            line([12,12],[4,11],'LineStyle','--');
            line([13,13],[4,11],'LineStyle','-');
            line([14,14],[4,11],'LineStyle','--');
            line([13.5,13.5],[9,11]);
            line([13.5,13.5],[11,11],'Marker','^');
            line([14.5,14.5],[9,11.5]);
            line([14.5,14.75],[11.5,11.5]);
            line([14.75,14.75],[11.5,11.5],'Marker','>');
            
            %% West (from East to West)
            rectangle('Position',[15,15.3,7,6.7],'FaceColor',obj.g9,'Curvature',0.1);
            line([15,22],[12,12],'LineStyle','--');
            line([15,22],[13,13],'LineStyle','-');
            line([15,22],[14,14],'LineStyle','--');
            line([17,15],[13.5,13.5]);
            line([15,15],[13.5,13.5],'Marker','<');
            line([17,15],[14.5,14.5]);
            line([16,16],[14.5,14.75]);
            line([16,16],[14.75,14.75],'Marker','^');
            line([15,15],[14.5,14.5],'Marker','<');
            line([16.,16.],[13.5,13.25]);
            line([16.,16.],[13.25,13.25],'Marker','v');
            
            %% South (from North to South)
            rectangle('Position',[4,15.3,7,6.7],'FaceColor',obj.g9,'Curvature',0.1);
            line([14,14],[15,22],'LineStyle','--');
            line([13,13],[15,22],'LineStyle','-');
            line([12,12],[15,22],'LineStyle','--');
            line([12.5,12.5],[17,15]);
            line([12.5,12.5],[15,15],'Marker','v');
            line([11.5,11.5],[17,14.5]);
            line([11.5,11.25],[14.5,14.5]);
            line([11.25,11.25],[14.5,14.5],'Marker','<');
            
        end
    end
    
end

Contact us