POV-Ray : Newsgroups : povray.general : Attempt to POV4 Syntax basics : Re: Attempt to POV4 Syntax basics Server Time
31 Jul 2024 10:27:01 EDT (-0400)
  Re: Attempt to POV4 Syntax basics  
From: nemesis
Date: 6 Oct 2007 11:05:00
Message: <web.4707a30f153c00f6bb2c29160@news.povray.org>
"Wolf" <nomail@nomail> wrote:
> IMHO the most people using POV-ray by writing the SDL by hand (as opposite
> to using a graphical modeler) have at least some programming experience,
> either Java or .NET.

or Lisp and Python.

BTW, Python accepts named parameters to functions and default values to
parameters.  Let's not forget python is an option -- although slow, but not
nearly as much as the current SDL -- as embbedable scripting engine hooking
directly to C/C++ code underneath...

like:

class GlassSphere( Sphere ):
  def __init__( self, pos = 0, radius = 1, ior = 1.4 ):
    Sphere.__init__( self, pos, radius )
    self.material = materials.Glass( ior )

you then may call it:
sph = GlassSphere( 0, 1, 1.4 )

or:
sph = GlassSphere( ior = 1.2 )

or:
sph = GlassSphere( ior = 1.2, radius = 3 )

or even:
sph = GlassSphere()
sph.ior = 1.2

etc.

A Basic povray scene with just a glass sphere over checkered board and light
could be expressed just as:

GlassSphere()
Plane( y, -1, Pigment( Checker( 0, 1 ) ) )
LightSource( (-5,5,-5) )

which is currently less than with current SDL syntax, which requires
position and radius of sphere.  The python version doesn't, because it gets
default parameters.

What people should understand is that classes allow for far more modular,
reusable and easier way to define objects rather than the macros and local
variables approach.  In my simple example, I've defined a new object type
which inherits behaviour from a predefined povray object (Sphere) and can
easily extend the base class by adding or overriding behaviour via method
definitions.  It's much more than macros which really just define the
constructor and have to take explicit parameters because the SDL lacks
lexical scoping to share modules variables of sort.

yes, Python also supports multiple inheritance as well as a simple interface
system by the name "duck typing"...

I don't have a problem with structured programming by indentation...

BTW, just about as nice as Python or moreso is Ruby, which has not been
mentioned so far...


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.