Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/interfaces/povray.py
4056 views
1
r"""
2
POV-Ray, The Persistence of Vision Ray Tracer
3
"""
4
5
6
from sage.misc.pager import pager
7
import os
8
9
class POVRay:
10
"""
11
POV-Ray The Persistence of Vision Ray Tracer
12
13
INPUT:
14
pov_file -- complete path to the .pov file you want to be rendered
15
outfile -- the filename you want to save your result to
16
**kwargs -- additionally keyword arguments you want to pass to POVRay
17
18
OUTPUT:
19
Image is written to the file you specified in outfile
20
21
EXAMPLES:
22
23
AUTHOR:
24
Sage interface written by Yi Qiang (yqiang _atNOSPAM_ gmail.com)
25
POVRay: http://www.povray.org
26
"""
27
def __repr__(self):
28
return 'POV-Ray The Persistence of Vision Ray Tracer'
29
30
def __call__(self, pov_file, outfile='sage.ppm', block=True, **kwargs):
31
if not os.path.isfile(pov_file):
32
return "%s not found" % (pov_file)
33
34
outfile = os.path.abspath(os.path.expanduser(outfile))
35
ext = outfile[-4:].lower()
36
try:
37
width = kwargs['W']
38
height = kwargs['H']
39
except:
40
return "You must specify a width and height."
41
42
cmd = "povray -D +FP +I%s +O%s " % (pov_file, outfile)
43
for k, v in kwargs.iteritems():
44
cmd += "+%s%s " % (k, v)
45
46
if not block:
47
cmd += ' &'
48
os.system(cmd)
49
50
def usage(self):
51
r = os.popen('povray').read()
52
pager()(r)
53
54
povray = POVRay()
55
56