- /
-
traffic signals
on 13 Nov 2023
- 15
- 46
- 2
- 2
- 1414
drawframe(1);
Write your drawframe function below
function drawframe(f)
cla;
rectangle('Position',[2 9.9 1.2 3.2],'FaceColor','k')
if f<4
cg='r';
cy='k';
cr='k';
elseif f<8
cg='k';
cy='y';
cr='k';
elseif f<32
cg='k';
cy='k';
cr='g';
else
cg='r';
cy='k';
cr='k';
end
rectangle('Position',[2.1 10 1 1],'Curvature',[1 1],'FaceColor',cr)
rectangle('Position',[2.1 11 1 1],'Curvature',[1 1],'FaceColor',cy)
rectangle('Position',[2.1 12 1 1],'Curvature',[1 1],'FaceColor',cg)
rectangle('Position',[2.5 5 0.2 4.9],'FaceColor','k')
rectangle('Position',[-10 0 20 5],'FaceColor',[0.5 0.5 0.5])
for i=1:9
rectangle('Position',[1 0.5*i-0.1 3 0.25],'FaceColor','w')
end
if f<8
t=f-1;
x=0;
elseif f>=8 && f<32
t=7.8;
x=(f-7)*4/20;
else
t=f-32+7.8;
x=5.8;
end
patch('Faces',1:7,'Vertices',[-10+t 2;-6.8+t 2;-7.2+t 3; -7.6+t 3; -8+t 4; -10+t 4;-10+t 2],'FaceColor','k');
patch('Faces',1:4,'Vertices',[-8.5+t 3.2;-8+t 3.2;-8.2+t 3.7;-8.5+t 3.7],'FaceColor','b');
rectangle('Position',[-8.3+t 1.6 1 1],'Curvature',[1 1],'FaceColor','b')
rectangle('Position',[-9.8+t 1.6 1 1],'Curvature',[1 1],'FaceColor','b')
rectangle('Position',[-8.05+t 1.85 0.5 0.5],'Curvature',[1 1],'FaceColor','k')
rectangle('Position',[-9.55+t 1.85 0.5 0.5],'Curvature',[1 1],'FaceColor','k')
rectangle('Position',[2 0+x 0.5 0.5],'Curvature',[1 1],'FaceColor','k')
hold on
plot([1.5 2.25 3],[-0.75+x 0+x -0.75+x],'-','linewidth',2);
plot([2 2 2.5 2.5],[-1.2+x -0.4+x -0.4+x -1.2+x],'-','linewidth',4);
xticklabels([])
yticklabels([])
axis equal
axis([-10 10 -1 14])
set(gca,'Color',[.73 .91 .99])
box on
end