|
|
"clipka" <nomail@nomail> wrote:
> Peter Hokanson <pch### [at] mindspringcom> wrote:
> > from povray import *
> > MyTex = texture(pigment=(1,1,1))
> > sphere((0,0,0),5,texture=MyTex)
>
> Fine. Can we also write this as
>
> sphere((0,0,0),5,texture(pigment=(1,1,1)))
>
> ?
>
> How about more complex scenarios, like multi-layered textures for instance?
I think this can be done with positional arguments. The constructor for a type
would have to accept variable arguments and then determine if there is more
than one texture by if more than one argument is a texture object:
class baseobject:
def __init__(self, *args):
for i in *args:
if isinstance(i, texture):
self.textures.append(i)
self.texture_transforms.append(transform())
if isinstance(i, (transform, rotate, scale, translate)):
self.transform_matrix.update(i)
for j in self.texture_transforms:
j.update(i)
class sphere(baseobject):
def __init__(self, *args):
# Extract sphere-specific arguments first and pass the rest to the base
baseobject.__init__(self, ...)
mysphere = sphere(
(0, 0, 0), 5,
scale(4), # Doesn't affect any texture
texture(
pigment(
checker(0.5, color(0.0, 0.0, 0.0, 0.5), color(0.5, 0.5, 0.5, 0.5))
),
finish(...),
)
scale(x=4, y=1), # Affects the first texture only
texture(...),
...
)
My question would be, how to differentiate between creating an object or just
declaring it. Maybe a special function to add the object to the scene:
add(sphere(
....
))
or perhaps a special global object that if in the attributes would cause it not
to be added to the scene list
class Dummy:
pass
nocreate = Dummy()
class baseobject:
def __init__(self, *args):
create = True
for i in args:
...
if i is nocreate:
create = False
if create:
scene_objects.append(self)
mysphere = sphere(..., nocreate)
Post a reply to this message
|
|