encapsulated drawing in function