Skip to content

Commit a46ff5a

Browse files
author
monkstone
committed
Suggested render width/height to set at initialization
1 parent 6ad9e76 commit a46ff5a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

raytracing/cornell_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CornellBox(object):
3434
Cornell box mainly as an object, except for the lights which are bit complicated
3535
"""
3636
def __init__(self):
37-
self.scene = POVFile("cornell_box.pov", "colors.inc", "skies.inc")
37+
self.scene = POVFile("cornell_box.pov", (300, 300), "colors.inc", "skies.inc")
3838

3939
self.cam = Camera(
4040
location = (27.8, 27.3, -80),

raytracing/povwriter/povwriter.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
__all__ = ['POVFile', 'Vector', 'Sphere', 'Box', 'Triangle', 'Pigment',
66
'Blob', 'Texture', 'Finish', 'Normal', 'Camera', 'LightSource', 'Torus',
77
'Union', 'Intersection', 'Difference', 'SkySphere', 'Mesh', 'Plane']
8-
HEADER = """
8+
HEADER1 = """
99
// Persistence Of Vision Ray Tracer Scene Description pov_fib
1010
// pov_fib: Generated by tracer.py
1111
// tracer.py is based on http://code.activestate.com/recipes/205451/ (r1)
1212
// For PovRAY Version: 3.7 (includes radiosity)
1313
// Date: September 2011
1414
// Auth: Martin Prout
15-
// +width 800 +height 600 for basic_scene example
15+
"""
16+
HEADER2= """
1617
#version 3.7;
1718
global_settings{
1819
assumed_gamma 1.0
@@ -34,16 +35,22 @@ class POVFile(object):
3435

3536
"""
3637
In the original recipe this was simply called file class, it seems sensible
37-
to use a more descriptive name
38+
to use a more descriptive name, also included size, this can be useful.
39+
PovRAY sketches should have a suggested size if only to set the aspect
40+
ratio.
3841
"""
39-
def __init__(self, fnam = "out.pov", *items):
42+
def __init__(self, fnam = "out.pov", size = (300, 300), *items):
4043
"""
4144
Initialize the POVFile object with hard coded HEADER, this
4245
could easily be read from file for greater flexiblity
4346
"""
4447
self.file = open(fnam, "w")
4548
self.__indent = 0
46-
self.writeln(HEADER)
49+
self.writeln(HEADER1)
50+
self.size = size # could use this data to set aspect ratio
51+
# Split header to add suggested render size in comments
52+
self.writeln( '// width %s height %s' % size)
53+
self.writeln(HEADER2)
4754
self.write(*items)
4855
def include(self, name):
4956
"""
@@ -355,7 +362,7 @@ def basic_scene():
355362
Basic external scene
356363
Note the use of tuples to group scalar values for vector type
357364
"""
358-
scene = POVFile("basic_scene.pov", "colors.inc", "skies.inc")
365+
scene = POVFile("basic_scene.pov", (800, 600), "colors.inc", "skies.inc")
359366
cam = Camera(location = (0, 2, -3), look_at = (0, 1, 2))
360367
sky = SkySphere("S_Cloud3")
361368
ground = Plane((0.0, 1.0, 0.0), 0.0,
@@ -382,7 +389,7 @@ def spiral():
382389
"""
383390
from math import sqrt, pi, cos, sin
384391
gamma = (sqrt(5) - 1) / 2
385-
fib = POVFile()
392+
fib = POVFile("spiral.pov")
386393
Camera(location=(0, 0, -128), look_at = (0, 0, 0)).write(fib)
387394
LightSource((100, 100, -100), color = (1, 1, 1)).write(fib)
388395
LightSource((150, 150, -100), color = (0, 0, 0.3)).write(fib)
@@ -409,7 +416,7 @@ def test():
409416
"""
410417
The current test function is ...
411418
"""
412-
basic_scene()
419+
spiral()
413420

414421
if (__name__ == "__main__"):
415422
test()

0 commit comments

Comments
 (0)