Пример #1
0
    def __init__(self, p0: Point3, p1: Point3, mat: Material) -> None:
        self.box_min = p0
        self.box_max = p1

        self.sides = HittableList()
        self.sides.add(XYRect(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), mat))
        self.sides.add(
            FlipFace(XYRect(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), mat)))
        self.sides.add(XZRect(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), mat))
        self.sides.add(
            FlipFace(XZRect(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), mat)))
        self.sides.add(YZRect(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), mat))
        self.sides.add(
            FlipFace(YZRect(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), mat)))
Пример #2
0
    def noise(self, p: Point3) -> float:
        u = p.x() - np.floor(p.x())
        v = p.y() - np.floor(p.y())
        w = p.z() - np.floor(p.z())

        i = int(np.floor(p.x()))
        j = int(np.floor(p.y()))
        k = int(np.floor(p.z()))
        c: List[List[List[Vec3]]] = np.empty((2, 2, 2), dtype=object)

        for di in range(2):
            for dj in range(2):
                for dk in range(2):
                    c[di][dj][dk] = self.ranvec[self.perm_x[(i + di) & 255]
                                                ^ self.perm_y[(j + dj) & 255]
                                                ^ self.perm_z[(k + dk) & 255]]

        return Perlin.trilinear_interp(c, u, v, w)
Пример #3
0
 def value(self, u: float, v: float, p: Point3) -> Color:
     sines = np.sin(10 * p.x()) * np.sin(10 * p.y()) * np.sin(10 * p.z())
     if sines < 0:
         return self.odd.value(u, v, p)
     else:
         return self.even.value(u, v, p)