created reusable method to calculate RGB