Some refinements to the POV-Ray generations.

Also add a simple program to print out gray codes of a specified width.
This commit is contained in:
Aldo Cortesi 2010-01-04 01:41:05 +13:00
parent a56d1cda43
commit 26d2d5ed46
2 changed files with 77 additions and 16 deletions

74
cube
View File

@ -2,18 +2,37 @@
from scurve import hilbert
import cubictemp
"""
This program outputs a POV-Ray definition file.
We render the curve into a 100x100 cube, with the mid-point of the cube at
the origin. You may have to fiddle with the resulting file to adjust the
camera location to suit the resulting image.
You can render it with a command like the following:
povray -W500 -H500 -Q10 +A0.8 +Q11 +P ./file.pov
"""
pov = """
global_settings { assumed_gamma 2.2 }
global_settings {
assumed_gamma 2.2
}
camera {
location <0, 50, 15>
right <1, 1, 1>
look_at <0, 0, 0>
up 1
right 1
location <50, 50, -200>
look_at <0, 0, 0>
rotate z*270
}
background { color red 1 green 1 blue 1 }
light_source { <50, 30, 20> color red 1 green 1 blue 1 }
light_source {
<50, 30, -200> color red 1 green 1 blue 1
}
blob {
threshold 0.5
@ -21,33 +40,32 @@ blob {
cylinder {
<@!i[0][0]!@, @!i[0][1]!@, @!i[0][2]!@>,
<@!i[1][0]!@, @!i[1][1]!@, @!i[1][2]!@>,
0.1, 1
4, 1
}
sphere {
<@!i[0][0]!@, @!i[0][1]!@, @!i[0][2]!@>,
0.1, 1
4, 1
}
<!--(end)-->
sphere {
<@!lines[0][0][0]!@, @!lines[0][0][1]!@, @!lines[0][0][2]!@>,
0.2, 1
6, 1
pigment { color red 0 green 1 blue 0 }
}
pigment { color red 0.5 green 0.5 blue 1 }
finish { ambient 0.2 diffuse 0.8 phong 1 }
rotate 70*z
rotate -180*x
rotate -80*y
scale 12.5
}
"""
f = cubictemp.Template(pov)
# Size of the PovRay cube
SIZE = float(100)
def maken(n):
def maken(n, scale):
lines = []
current = None
for v in hilbert.Hilbert(3, n):
for v in n:
v = [i*scale-SIZE/2 for i in v]
if not current:
current = v
continue
@ -56,5 +74,29 @@ def maken(n):
return lines
print f(lines=maken(2))
def main():
from optparse import OptionParser, OptionGroup
parser = OptionParser(
usage = "%prog [options] output",
version="%prog 0.1",
)
parser.add_option(
"-o", "--order", action="store",
type="int", dest="order", default=3
)
options, args = parser.parse_args()
if len(args) != 1:
parser.error("Please specify output file.")
c = hilbert.Hilbert(3, options.order)
scale = SIZE/c.dimensions()[0]
t = cubictemp.Template(
pov,
lines = maken(c, scale),
scale = scale
)
f = open(args[0], "w")
f.write(str(t))
main()

19
gray Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env python
from scurve import utils
def main():
from optparse import OptionParser, OptionGroup
parser = OptionParser(
usage = "%prog [options] output",
version="%prog 0.1",
)
options, args = parser.parse_args()
if len(args) != 1:
parser.error("Please specify the bit width of the desired gray code.")
width = int(args[0])
for i in range(2**width):
print str(utils.bits(utils.graycode(i), width))[1:-1]
main()