示例#1
0
 def __init__(self, color1=Pixel.fromHex("#FFFFFF"), color2=Pixel.fromHex("#000000"), ambient=0.05, diffuse=1.0, specular=1.0, reflection=0.5):
     self.color1 = color1
     self.color2 = color2
     self.ambient = ambient
     self.diffuse = diffuse
     self.specular = specular
     self.reflection = reflection
示例#2
0
 def colorAt(self, objHit, hitPos, normal, scene):
     material = objHit.material
     objColor = material.colorAt(hitPos)
     toCam = scene.camera.centerPoint - hitPos
     specularK = 50
     color = material.ambient * Pixel.fromHex("#000000")
     #light calculations
     for light in scene.lights:
         toLight = Ray(hitPos, light.position - hitPos)
         #diffuse shading
         color += (objColor * material.diffuse *
                   max(normal.dot(toLight.direction), 0))
         #Specular shading
         halfVector = (toLight.direction + toCam).normalize()
         color += light.color * material.specular * max(
             normal.dot(halfVector), 0)**specularK
     return color
示例#3
0
from pixel import Pixel
from scene import Scene
from sphere import Sphere
from vector import Vector
from camera import Camera
from point import Point
from material import Material, ChequeredMaterial
from light import Light

COLS = 1920
ROWS = 1080
RENDEREDIMG = "twospheres.ppm"
CAMERA = Camera(Vector(0, -0.35, -1))
OBJECTS = [
    #Ground
    Sphere(
        Point(0, 10000.5, 1), 10000.0,
        ChequeredMaterial(color1=Pixel.fromHex("#420500"),
                          color2=Pixel.fromHex("#E6B87D"),
                          ambient=0.2,
                          reflection=0.2)),
    #Blue ball
    Sphere(Point(0.75, -.1, 1), 0.6, Material(Pixel.fromHex("#0000FF"))),
    #Pink ball
    Sphere(Point(-0.75, -0.1, 2.25), 0.6, Material(Pixel.fromHex("#803980")))
]
LIGHTS = [
    Light(Point(1.5, -.5, -10), Pixel.fromHex("#FFFFFF")),
    Light(Point(-.5, -10, -10), Pixel.fromHex("#E6E6E6"))
]