The reason for your problem is a wrong type of your pixel parameter. You used int but the function expects var. Converting var to int loses the fractional part of the number, which in turn leads to wrong colors.

You can find a description of the difference of int and var in the manual under "Variables".