drawing canvas and rectangle with line - code reusing