function paint()
% constants
screenSize = get(groot, 'ScreenSize');
figSize = [500, 500];
XData = [];
YData = [];
hLines = gobjects(0, 1);
lineColor = [0 0 0];
% GUI buiding
hFig = uifigure(...
   'Position', [(screenSize(3:4) - figSize)/2, figSize], ...
   'Name', 'Paint', 'Resize', 'off');
hAx = uiaxes(hFig, 'Position', [1, 1, figSize], ...
   'XLim', [1, figSize(1)], ...
   'YLim', [1, figSize(2)]);
hMenuColor = uimenu(hFig, 'Text', 'Color');
hMenuClear = uimenu(hFig, 'Text', 'Clear');
% compute mapping of coord. figure-axes
drawnow(); % to get proper size of axes redraw gui
borderSize = hAx.TightInset;
axesLLC = borderSize(1:2);
axesSize = round(figSize - axesLLC - borderSize(3:4));
axesSizeRatio = figSize./axesSize;
% callback settings
hFig.WindowButtonDownFcn = @(a, b)turnOnDrawing();
hFig.WindowButtonUpFcn = @(a, b)turnOffDrawing();
hMenuColor.MenuSelectedFcn = @(a, b)changeColor();
hMenuClear.MenuSelectedFcn = @(a, b)clearCanvas();

   function mouseMove()
      currentPoint = (hFig.CurrentPoint - axesLLC).*axesSizeRatio;
      XData(end+1, :) = currentPoint(1);
      YData(end+1, :) = currentPoint(2);
      set(hLines(end, :), 'XData', XData, 'YData', YData);
   end

   function turnOnDrawing()
      XData = [];
      YData = [];
      hLines(end+1, :) = line(hAx, ...
         'XData', XData, 'YData', YData, ...
         'LineWidth', 2, 'Color', lineColor);
      hFig.WindowButtonMotionFcn = @(a, b)mouseMove();
   end

   function turnOffDrawing()
      hFig.WindowButtonMotionFcn = '';
   end

   function changeColor()
      newColor = uisetcolor();
      if ~isequal(newColor, 0)
         lineColor = newColor;
      end
   end

   function clearCanvas()
      hLines.delete();
      hLines = gobjects(0, 1);
   end
end