function fig = plotBulb(color)
%

% Copyright 2017 The MathWorks, Inc.

oldFigs = findall(0, 'Tag', 'zigbeeBulb');
delete(oldFigs);

% Upper part
theta = linspace(0, pi);
x1 = cos(theta);
y1 = 1.2*sin(theta);

% Left middle part
theta = linspace(2*pi, 5*pi/2);
x2 = 1.5*cos(theta/2) + 0.5;
y2 = 1.6*sin(theta/2);

% Left bottom part
theta = linspace(pi/6, 0);
newXc = x2(end) - 1.5*cos(pi/6);
newYc = y2(end) - 1.6*sin(pi/6);
x3 = 1.5*cos(theta) + newXc;
y3 = 1.6*sin(theta) + newYc;

% Right middle part
theta = linspace(7*pi/2, 4*pi);
x4 = 1.5*cos(theta/2) -0.5;
y4 = 1.6*sin(theta/2);

% Right bottom part
theta = linspace(pi, pi-pi/6);
newXc = x4(1) + 1.5*cos(pi/6);
newYc = y4(1) - 1.6*sin(pi/6);
x5 = 1.5*cos(theta) + newXc;
y5 = 1.6*sin(theta) + newYc;

% Plot colored bulb:
figure;
ax = axes;
patch(ax, [x5 x4 x1 x2 x3], [y5 y4 y1 y2 y3], color, 'Tag', 'bulbPatch');
fig = ax.Parent;
fig.Position = [100 100 300 400*4.5/4-50];
fig.Tag = 'zigbeeBulb';

% create base of bulb
h = 0.2;
margin = 0.025;
hold on;
rectangle('Position', [max(x3)+margin min(y5)-h   min(x5)-max(x3)-2*margin h],      'Curvature', 1, 'FaceColor', [0.84 0.84 0.84])
rectangle('Position', [max(x3)+margin min(y5)-h*2 min(x5)-max(x3)-2*margin h],      'Curvature', 1, 'FaceColor', [0.84 0.84 0.84])
rectangle('Position', [max(x3)+margin min(y5)-h*3 min(x5)-max(x3)-2*margin h],      'Curvature', 1, 'FaceColor', [0.84 0.84 0.84])
rectangle('Position', [max(x3)+margin*9 min(y5)-h*4 min(x5)-max(x3)-2*margin*9 h],  'Curvature', 1, 'FaceColor', [0.84 0.84 0.84])

axis(ax, [-1.5 1.5 -2.75 1.25])
xticks(ax, []);
yticks(ax, []);
fig.Color = [1 1 1];
ax.Visible = 'off';

end

