samedi 9 juillet 2016

How to change this function from creating a circular gradient to an elliptical gradient?


I am trying to create a function that doesn't rely on a perfect circle for a transparency gradient, but rather an elliptical that can be a perfect circle or can be an ellipse. Currently my function creates a square that contains a 1/4th of a circular gradient that is later mirrored in 3 directions to make a circle. My function is defined as: def _calc_mask(rx, ry): #rx and ry represent the pixels dx = rx - (width/2) # horizontal center of Grating dy = ry - (width/2) # vertical center of Grating t = math.atan2(dy, dx) r = math.sqrt(dx ** 2 + dy ** 2) ux = r * math.cos(t) uy = r * math.sin(t) f = math.exp(-0.5 * (ux / (self.std_dev*3)) ** 2 - 0.5 * (uy / (self.std_dev*3)) ** 2) f = 1.0-f return 0, 0, 0, f

Aucun commentaire:

Enregistrer un commentaire