The original code and your code is still very simplistic.
Try converting the RGB to HSV, adjust the value, then converting back.
This will produce a better lighten/darken model.