def get_shaded_rgb(rgb, point, unit_normal_vect, light_source): to_sun = normalize(light_source - point) factor = 0.5 * np.dot(unit_normal_vect, to_sun)**3 if factor < 0: factor *= 0.5 result = rgb + factor clip_in_place(rgb + factor, 0, 1) return result
def generate_rgbas_array(self, color, opacity): """ First arg can be either a color, or a tuple/list of colors. Likewise, opacity can either be a float, or a tuple of floats. If self.sheen is not zero, and only one color was passed in, a second slightly light color will automatically be added for the gradient """ colors = list(tuplify(color)) opacities = list(tuplify(opacity)) rgbas = np.array([ color_to_rgba(c, o) for c, o in zip(*make_even(colors, opacities)) ]) sheen = self.get_sheen() if sheen != 0 and len(rgbas) == 1: light_rgbas = np.array(rgbas) light_rgbas[:, :3] += sheen clip_in_place(light_rgbas, 0, 1) rgbas = np.append(rgbas, light_rgbas, axis=0) return rgbas
def project_points(self, points): frame_center = self.get_frame_center() distance = self.get_distance() rot_matrix = self.get_rotation_matrix() points -= frame_center points = np.dot(points, rot_matrix.T) zs = points[:, 2] for i in 0, 1: if self.exponential_projection: # Proper projedtion would involve multiplying # x and y by d / (d-z). But for points with high # z value that causes weird artifacts, and applying # the exponential helps smooth it out. factor = np.exp(zs / distance) lt0 = zs < 0 factor[lt0] = (distance / (distance - zs[lt0])) else: factor = (distance / (distance - zs)) clip_in_place(factor, 0, 10**6) points[:, i] *= factor points += frame_center return points