POV-Ray : Newsgroups : povray.general : Tips for Short Code Contest Server Time
28 Nov 2024 17:35:40 EST (-0500)
  Tips for Short Code Contest (Message 1 to 5 of 5)  
From: Mike Kost
Subject: Tips for Short Code Contest
Date: 12 Oct 2006 14:22:41
Message: <452e87f1@news.povray.org>
After tyring to get a few scenes into 256 bytes for Paul Bourke's short code
contest, here's a few tips I've stumbled on to squeeze the last bits from
the sdl.

1. What Camera?

It helps to remove the camera declaration out of the scene. The default
camera is located at <0,0,0> and looking at <0,0,1>. If you must move the
camera, the camera will continue to look in the +z direction from it's new
location, the equivalent of 'camera{location loc look_at loc+z}'. This
prevents having to use 'look_at <a,b,c>' 

2. Colors

In SCC round 3, Tek noted
(http://local.wasp.uwa.edu.au/~pbourke/rendering/scc3/final/swokwz_l.pov -
at the bottom) that the direction vectors can be used for colors. 
 x = <1,0,0> (red)
 y = <0,1,0> (green)
 z = <0,0,1> (blue)

What's even better is that you can throw out the rgb reference if you use
vectors, i.e.:
 'pigment{color x}' = 'pigment{color rgb <1,0,0>}'

3. Vector Substitution

A constant 'C' will be interpreted as '<C,C,C>' if the parser needs a
vector. This can be quite useful since '1-z' is equivalent to '<1,1,0>',
but with less than half the bytes.

4. Spaces Are Optional

Brackets, braces, and parentheses are not the only characters that help
remove spaces. Povray does not require spaces before pound signs ('#'),
(sometimes) does not need spaces after numbers, and (sometimes) does not
need spaces before decimal points ('.'). The following will parse:
#macro a(b)#if(b<5)box{-1,1scale.5translate y-3pigment{color x}}#end#end

5. Reorder The Math

Watch for leading minus signs: they can sometimes be placed elsewhere in the
equation. For example '-x+1' can also be '1-x'. Also, place numbers last to
combine with #4 above and remove a space, i.e. 'translate 3+y pigment{color
x}' -> 'translate y+3pigment{color x}'

6. Isosurfaces

If you're using isosurfaces, don't forget that the default bounding box is
'contained_by{box{-1,1}}'. If your bounding box is the same size or smaller
(suck up that rendering time hit), remove the contained_by directive if you
don't need it. 

7. Scaling

When scaling in only one axis, it's customary to make all the other scaling
factors be one because scaling by zero is illegal, i.e. 'scale <1,1,10>'.
Povray converts all zero scaling factors to ones, so use 'scale 10*z'. 

Mike
--
http://povray.tashcorp.net


Post a reply to this message

From: Warp
Subject: Re: Tips for Short Code Contest
Date: 12 Oct 2006 21:07:21
Message: <452ee6c8@news.povray.org>
Mike Kost <con### [at] povraytashcorpnet> wrote:
> 1. What Camera?

> It helps to remove the camera declaration out of the scene. The default
> camera is located at <0,0,0> and looking at <0,0,1>. If you must move the
> camera, the camera will continue to look in the +z direction from it's new
> location, the equivalent of 'camera{location loc look_at loc+z}'. This
> prevents having to use 'look_at <a,b,c>' 

  Usually putting a camera statement at all is a waste of space. Translating
the scene usually takes less space. And yes, you can often use tricks to
avoid the 'translate' keyword too.

> What's even better is that you can throw out the rgb reference if you use
> vectors, i.e.:
>  'pigment{color x}' = 'pigment{color rgb <1,0,0>}'

  Why not 'pigment{rgb x}'?

  This is not just a "short code trick", it should be basic knowledge right
from the documentation.

> 3. Vector Substitution

> A constant 'C' will be interpreted as '<C,C,C>' if the parser needs a
> vector. This can be quite useful since '1-z' is equivalent to '<1,1,0>',
> but with less than half the bytes.

  Again not even a "trick", but basic info straight from the documentation.

> #macro a(b)#if(b<5)box{-1,1scale.5translate y-3pigment{color x}}#end#end

  That's not even the shortest way of doing that ;)

-- 
                                                          - Warp


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Tips for Short Code Contest
Date: 12 Oct 2006 22:10:00
Message: <web.452ef46fb1f80888fb5a6f0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> > What's even better is that you can throw out the rgb reference if you use
> > vectors, i.e.:
> >  'pigment{color x}' = 'pigment{color rgb <1,0,0>}'
>
>   Why not 'pigment{rgb x}'?

Even though this is valid, it gives me the creeps for some reason, x is x,
red is red...

>
>   This is not just a "short code trick", it should be basic knowledge right
> from the documentation.
>
> > 3. Vector Substitution
>
> > A constant 'C' will be interpreted as '<C,C,C>' if the parser needs a
> > vector. This can be quite useful since '1-z' is equivalent to '<1,1,0>',
> > but with less than half the bytes.
>
>   Again not even a "trick", but basic info straight from the documentation.
>

Not necessarily all tricks, but often ignored, skipped over or forgotten...

> > #macro a(b)#if(b<5)box{-1,1scale.5translate y-3pigment{color x}}#end#end
>
>   That's not even the shortest way of doing that ;)
>
> --
>                                                           - Warp

Best I can do:
#macro a(b)#if(b<5)box{y-3.5y-2.5pigment{rgb x}}#end#end

-tgq


Post a reply to this message

From: Warp
Subject: Re: Tips for Short Code Contest
Date: 12 Oct 2006 23:08:30
Message: <452f032d@news.povray.org>
Trevor G Quayle <Tin### [at] hotmailcom> wrote:
> >   Why not 'pigment{rgb x}'?

> Even though this is valid, it gives me the creeps for some reason, x is x,
> red is red...

  You are not a programmer then? ;)

  I think of 'x' as '<1, 0, 0>', not as "the x axis". Since '<1, 0, 0>' is
a valid and normal color (in a similar way as eg "#FF0000" is a valid normal
color in html), then 'x' is one too.

  This actually makes understanding things like "x+y" easier. You have
to think about that as "<1, 0, 0> + <0, 1, 0>", not as "the x axis plus
the y axis", which would be quite confusing.

> > > #macro a(b)#if(b<5)box{-1,1scale.5translate y-3pigment{color x}}#end#end
> >
> >   That's not even the shortest way of doing that ;)

> Best I can do:
> #macro a(b)#if(b<5)box{y-3.5y-2.5pigment{rgb x}}#end#end

  Much better. :P

-- 
                                                          - Warp


Post a reply to this message

From: Mike Kost
Subject: Re: Tips for Short Code Contest
Date: 13 Oct 2006 19:14:52
Message: <45301dec@news.povray.org>
Warp wrote:
> Mike Kost <con### [at] povraytashcorpnet> wrote:
>> 1. What Camera?
> 
>> It helps to remove the camera declaration out of the scene. The default
>> camera is located at <0,0,0> and looking at <0,0,1>. If you must move the
>> camera, the camera will continue to look in the +z direction from it's
>> new location, the equivalent of 'camera{location loc look_at loc+z}'.
>> This prevents having to use 'look_at <a,b,c>'
> 
>   Usually putting a camera statement at all is a waste of space.
>   Translating
> the scene usually takes less space. And yes, you can often use tricks to
> avoid the 'translate' keyword too.
> 
>> What's even better is that you can throw out the rgb reference if you use
>> vectors, i.e.:
>>  'pigment{color x}' = 'pigment{color rgb <1,0,0>}'
> 
>   Why not 'pigment{rgb x}'?
> 
>   This is not just a "short code trick", it should be basic knowledge
>   right
> from the documentation.

Good suggestion for 'rgb x' instead of 'color x'.

Whether this is basic knowledge or not, I'm interested in encouraging 
entries in the short code contest. If someone hasn't read the documents
closely for syntax structure, it's helpful to know it. 

>> 3. Vector Substitution
> 
>> A constant 'C' will be interpreted as '<C,C,C>' if the parser needs a
>> vector. This can be quite useful since '1-z' is equivalent to '<1,1,0>',
>> but with less than half the bytes.
> 
>   Again not even a "trick", but basic info straight from the
>   documentation.
> 
>> #macro a(b)#if(b<5)box{-1,1scale.5translate y-3pigment{color x}}#end#end
> 
>   That's not even the shortest way of doing that ;)

No, but it got the point across. 

Mike
--
http://povray.tashcorp.net


Post a reply to this message

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