Actually I used a rather different equation involving a pixel 'frequency' (I was initially trying to make a black-and-white pixel gradient) but its cool that there's a simpler way!