Beispiel #1
0
def createScene(floorColors, sphereColors, lightColors, lightPositions):
    WIDTH = 960
    HEIGHT = 540
    RENDERED_IMG = "custom.ppm"
    CAMERA = Vector(0, -0.35, -1)
    OBJECTS = [
        # Ground Plane
        Sphere(
            Point(0, 10000.5, 1),
            10000.0,
            ChequeredMaterial(
                color1=Color.from_hex(floorColors[0]),
                color2=Color.from_hex(floorColors[1]),
                ambient=0.2,
                reflection=0.2,
            ),
        ),
    ]
    createSpheres(OBJECTS, sphereColors)
    LIGHTS = []
    createLights(LIGHTS, lightColors, lightPositions)
    scene = Scene(CAMERA, OBJECTS, LIGHTS, WIDTH, HEIGHT)
    engine = RenderEngine()  #Creates an instance of the render
    image = engine.prepareRender(scene)  #Creates a image rendering the data
    #os.chdir(os.path.dirname(os.path.abspath(mod.__file__))) #Creates a dir using the name in the mod
    with open(RENDERED_IMG,
              "w") as img_file:  #Open the ppm image and store the pixels
        image.write_ppm(img_file)
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("scene", help="Path to scene file (without .py extension)")
    parser.add_argument(
        "-p",
        "--processes",
        action="store",
        type=int,
        dest="processes",
        default=0,
        help="Number of processes (0=auto)",
    )
    args = parser.parse_args()
    if args.processes == 0:
        process_count = cpu_count()
    else:
        process_count = args.processes

    mod = importlib.import_module(args.scene)
    scene = Scene(mod.CAMERA, mod.OBJECTS, mod.LIGHTS, mod.WIDTH, mod.HEIGHT)
    engine = RenderEngine()

    os.chdir(os.path.dirname(os.path.abspath(mod.__file__)))
    with open(mod.RENDERED_IMG, "w") as img_fileobj:
        engine.render_multiprocess(scene, process_count, img_fileobj)
Beispiel #3
0
def main():
    process_count = cpu_count()

    scene = Scene(CAMERA, OBJECTS, LIGHTS, WIDTH, HEIGHT)
    engine = RenderEngine()
    with open("scene1.ppm", "w") as img_fileobj:
        engine.render_multiprocess(scene, process_count, img_fileobj)
Beispiel #4
0
def main():
    #CHANGE SCENE HERE
    sc = twoSpheres

    scene = Scene(sc.CAMERA, sc.OBJECTS, sc.LIGHTS, sc.WIDTH, sc.HEIGHT)
    engine = RenderEngine()
    img = engine.render(scene)
    with open("test.ppm", "w") as imgFile:
        img.writePPM(imgFile)
Beispiel #5
0
def main():
    camera = Vec3(0, 0, -1)
    objects = [Sphere(Point(0, 0, 0), 0.5, Color.from_hex("#FF0000"))]
    scene = Scene(camera, objects, WIDTH, HEIGHT)
    engine = RenderEngine()
    img = engine.render(scene)

    with open("sphere_test.ppm", 'w') as img_file:
        img.write_ppm(img_file)
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('scene', help="Scene path, without .py extension")
    args = parser.parse_args()
    mod = importlib.import_module(args.scene)

    scene = Scene(mod.CAMERA, mod.OBJECTS, mod.LIGHTS, mod.WIDTH, mod.HEIGHT)
    engine = RenderEngine()
    image = engine.render(scene)

    os.chdir(os.path.dirname(os.path.abspath(mod.__file__)))
    with open(mod.RENDERED_IMG, "w") as img_file:
        image.write_ppm(img_file)
def main():
    WIDTH = 320
    HEIGHT = 200
    camera = Vector(0, 0, -1)
    mat = Material(Color(1,0,0))
    objects = [Sphere(Point(0,0,0), 0.5, mat)]
    lights = [Light(Point(1.5,-0.5,-10), Color(1,1,1))]
    scene = Scene(camera, objects, lights, WIDTH, HEIGHT)
    engine = RenderEngine()
    img = engine.render(scene)    
    
    f = open("test.ppm","w")
    img.writeImage(f)
    f.close()
Beispiel #8
0
def main():
    WIDTH = 800
    HEIGHT = 400
    camera = Vector(0, 0, -1)
    objects = [
        Sphere(Point(0, 0, 0), 0.5, Material(Color.fromHEX("#FF0000"))),
        Sphere(Point(1, 0, 0), 0.5, Material(Color(0, 1, 0))),
        Sphere(Point(-1, 0, 0), 0.5, Material(Color(0, 0, 1)))
    ]
    lights = [Light(Point(10, 5, -10.0), Color.fromHEX("#FFFFFF"))]
    scene = Scene(camera, objects, lights, WIDTH, HEIGHT)
    engine = RenderEngine()
    image = engine.render(scene)

    with open("test.ppm", "w") as img_file:
        image.writePPM(img_file)
def main():
    console.clear()
    canvas.clear()
    multiplier = 0.6
    WIDTH = 1920
    HEIGHT = 1080
    camera = Vector(0, 0, -1)
    objects = [
        Sphere(Point(0, 0, 1.0), 0.3, Color.from_hex("#F24F00")),
        Sphere(Point(0.2, 0, 0.4), 0.1, Color.from_hex("#224F00")),
        Sphere(Point(-0.25, 0.0, 0.4), 0.1, Color.from_hex("#1f8fd8")),
        Sphere(Point(0.4, -0.9, 1.7), 0.6, Color.from_hex("#d80cac")),
        Sphere(Point(-0.4, -0.9, 1.7), 0.6, Color.from_hex("#d8b63e"))
    ]
    scene = Scene(camera, objects, WIDTH, HEIGHT)
    engine = RenderEngine()
    image = engine.render(scene, 10)
Beispiel #10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("scene", help="Path to rendered image")
    args = parser.parse_args()
    mod = importlib.import_module(args.scene)
    myScene = GenerateScene()
    comm = MPI.COMM_WORLD
    size = comm.Get_size()
    rank = comm.Get_rank()
    node_name = MPI.Get_processor_name()
    numFramesCam = 1
    numFramesMove = 15
    image = []
    preview_objects_hit_pixel = []
    preview_obj = []
    objects_hit_pixel = []
    print(size)
    for i in range(numFramesCam):
        for j in range(numFramesMove):
            # CAMERA = Vector(0, i, -1)
            myScene = GenerateScene(480, 270, Vector(0, 0, -1),
                                    "2balls1tri.ppm", Point(-1, 0, 0),
                                    Point(j / 10, 0, 0))
            if ((i % size) == rank):
                print(i)
                print(rank)
                # print("cant objetos" + str(range(myScene.objects)))

                scene = Scene(myScene.camera, myScene.objects, myScene.lights,
                              myScene.width, myScene.height)

                engine = RenderEngine(myScene.width, myScene.height,
                                      len(myScene.objects), preview_obj,
                                      objects_hit_pixel, image, 0)
                image = engine.render(scene)

                os.chdir(os.path.dirname(os.path.abspath(mod.__file__)))
                with open(
                        "FRAME_i " + str(i) + "j_" + str(j) + mod.RENDERED_IMG,
                        "w") as img_file:
                    image.write_ppm(img_file)
                preview_obj = myScene.objects
                cant_ray = engine.cant_ray
                print("FRAME_i " + str(i) + "j_" + str(j) + mod.RENDERED_IMG +
                      "use " + str(cant_ray))
                objects_hit_pixel = engine.preview_objects_hit_pixel
Beispiel #11
0
def main():
    WIDTH = 1000
    HEIGHT = 1000
    camera = point(0, 0, -1)
    objects = [
        sphere(point(0, 0, 0), 0.5,
               Material(color.from_hex("#FFFFFF"), 0.05, 0.1))
    ]
    lights = [
        Light(point(10.0 * -1.14, 10 * 1.14, 0), color.from_hex("#FF0000")),
        Light(point(0, -10, 0), color.from_hex("#00FF00")),
        Light(point(10.0 * 1.14, 10.0 * 1.14, 0), color.from_hex("#0000FF")),
    ]
    scene_1 = scene(camera, objects, lights, WIDTH, HEIGHT)
    engine = RenderEngine()
    im = engine.render(scene_1)
    with open("render.ppm", "w") as img_file:
        im.write_ppm(img_file)
Beispiel #12
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("imageout", help="Path to the rendered image")
    args = parser.parse_args()
    WIDTH = 320
    HEIGHT = 200
    camera = Vector(0, 0, -1)

    objects = [
        Sphere(Point(0, 0, 0), 0.5, Material(Color.from_hex("#FF0000"))),
    ]
    lights = [Light(Point(1.5, -0.5, -10.0), Color.from_hex("#FFFFFF"))]
    scene = Scene(camera, objects, lights, WIDTH, HEIGHT)
    engine = RenderEngine()

    image = engine.render(scene)

    with open(args.imageout, "w+") as f:
        image.write_ppm(f)
Beispiel #13
0
def main():
    width = 3200
    height = 2000
    camera = Vector(0, 0, -0.5)
    lights = [
        Light(Point(0, -0.6, -6), Colour.from_hex("#FFFFFF")),
        Light(Point(5, -0.9, 10), Colour.from_hex("#FFFFFF")),
        Light(Point(-1, -0.9, 10), Colour.from_hex("#FFFFFF"))
    ]
    objects = [
        Sphere(Point(-0.53, 0, 1), 0.5, Material(Colour.from_hex("#FF0000"))),
        Sphere(Point(0.53, 0, 1), 0.5, Material(Colour.from_hex("#F80000"))),
        Sphere(Point(0, 1000000.5, 1), 1000000,
               Material(Colour.from_hex("#FFFFFF")))
    ]
    scene = Scene(camera, objects, lights, width, height)
    engine = RenderEngine()
    image = engine.render(scene)

    with open("render.ppm", "w") as img_file:
        image.write_ppm(img_file)
Beispiel #14
0
def main():
    print("\n ... Generando imagen ... \n")
    start = time.time()
    parser = argparse.ArgumentParser()
    parser.add_argument("scene",
                        help="Path to scene file(without .py extension)")
    args = parser.parse_args()
    mod = importlib.import_module(args.scene)

    # Importing goes the same, mod imports directly from Scene
    scene = Scene(mod.CAMERA, mod.OBJECTS, mod.LIGHTS, mod.WIDTH, mod.HEIGHT)
    engine = RenderEngine()
    image = engine.render(scene)

    # writes the image
    os.chdir(os.path.dirname(os.path.abspath(mod.__file__)))
    with open(mod.RENDERED_IMG, "w") as img_file:
        image.write_ppm(img_file)
    end = time.time()
    print("Imagen guardada en " +
          os.path.dirname(os.path.abspath(mod.__file__)))
    print("\nTiempo de duración del algoritmo: " + str(end - start))
Beispiel #15
0
def main(location):
    # read the words from a file
    word_object = Words()
    word_object.set_case("UPPER")
    word_object.read_words_file(location)
    # word_object.read_words_url("https://gist.githubusercontent.com/atduskgreg/3cf8ef48cb0d29cf151bedad81553a54/raw/82f142562cf50b0f6fb8010f890b2f934093553e/animals.txt")

    # render a grid with the words
    engine = RenderEngine(word_object)
    engine.generate_grid(16)

    engine.print_letter_matrix()
    print("-" * word_object.get_max_word_len())

    #print (len(engine.missed_words))
    #engine.print_words_not_in_grid()

    engine.print_words_in_grid()