It sounds like you need to calculate a value for the analogWrites in this fashion:
unsigned int Red = R*D/255;
Edit: one int too many.
It sounds like you need to calculate a value for the analogWrites in this fashion:
unsigned int Red = R*D/255;
Edit: one int too many.