More general colour-gradient code.