POV-Ray : Newsgroups : povray.general : Problem making macro work right : Re: Problem making macro work right Server Time
8 Aug 2024 06:17:08 EDT (-0400)
  Re: Problem making macro work right  
From: Dan Johnson
Date: 19 Feb 2001 18:41:26
Message: <3A91B0A3.31098CAC@hotmail.com>
Warp wrote:

>   I had to reindent the code in order to understand. You should really
> work on this side :)

Well my only formal training in programming was a 9 week intro to computers class I
took in 7th
grade.  I learned logo (I have almost completely forgotten it now), and basic on an
apple clone.
The code looked something like.

10 var = 1
15 if var > 30 end
20 var = var +1
30 goto 10
40 end

So I was never taught to write pretty code.  For years since then I have wanted to
take some
classes, but there was always something in the way.  Usually it was related to my poor
performance
in school, and how time spent on an extra curricular class would take away from
classes I needed
to graduate.  My parents used the same logic for never getting me a nintendo.  Well a
friend of
mine, also a poor performer at school took the other route.  He now lives in a million
US dollar
home.  The moral of this story is buy your kid video games.

>
>   What you are creating in your macro is a bunch of unions. This means that
> when you make this:
>
> object {Grid(<2,2,2>,1,.1) pigment{Green}}
>
> it generates code that looks like this:
>
> object
> { union { ... }
>   union { ... }
>   union { ... }
>   ...
> }
>
>   You can't have several unions inside an object block.
>

Ahh, its all so obvious now.

>
>   By the way, I think that you are missing some #breaks in your #switch.

Well the POV-Ray docs said that the #breaks were optional, and I usually do things the
easy way.
Since you asked, I fixed that.

>   Here is the code after I indented it (well, actually I didn't indent it,
> I just let emacs to do it automatically):

    Well emacs seems to be a magical tool to people who understand it.  Working with
POV-Ray I
learned for the first time how slow my computer really is.  I know now that I can
never truly be
happy with windows, because most of the truly powerful computers in the world use
unix.  I
installed Red Hat on a pentium 100 machine, but I never use it, and I didn't learn
much installing
it or using the dorky control panels.  I think I need more motivation to get me
started, like when
I learned dos so that I could play games.  My friend told me "from the command prompt
type help
read everything", and I did so that I could play doom.  I usually only play games now
when I am at
friends, or when I am in a really bad mood, and want to kill something without
consequences.  To
prepare my transition to linux I have been learning Gimp, and Emacs on windows.  Many
features of
these programs don't seem to work at all on windows.  So now I have some motivation,
but I know I
will only successfully transition if the gain is more than the loss.  Right now I
can't make
emacs, or xemacs for windows work anywhere near as nicely as the editor built in to
the windows
version of POV-Ray.  I have been posting questions on gnu.emacs.help, and have managed
to get
emacs to function somewhat close to what I am used to.  So far though when it comes to
using
povray with emacs: it uses really ugly colors, and it doesn't do any kind of auto
indenting.  I
tried looking through the source to "pov-mode.el" but it only makes slightly more
sense to me than
warps signature (see below).  Maybe one of the code gurus can tell me how to make
emacs look a
little more like this

http://www.cs.tut.fi/~warp/snapshot.gif

Here is my .emacs file can anyone tell me what I am doing wrong.

;---begin .emacs
(setq font-lock-maximum-decoration t)   ; many colors
(global-font-lock-mode t)               ; enable syntax highlighting
(load "cua-mode")    ;  windows shortcut keys
(CUA-mode t)
(autoload 'pov-mode "pov-mode.el" "PoVray scene file mode" t)
(setq auto-mode-alist
 (append '(("\\.pov$" . pov-mode)
    ("\\.inc$" . pov-mode)
                 ) auto-mode-alist))
;; Use this to turn on font-lock:
(add-hook 'pov-mode-hook 'turn-on-font-lock)
(setq scroll-conservatively 1000)
;--end .emacs



>
> --
> char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
> main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
> c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/

Below is my fixed code.  Added "#local Dimentions_vector = Dimentions_vector0 *
<1,1,1>;" to both
functions, and now it successfully promotes integers to vectors.  I don't know why it
renders a
blank screen when I use a negative number, in the input vector instead of generating
an error like
I wanted it to.  Tried to indent by hand doesn't help in understanding the core of
Arrange_3d " (
(mod(N+A-1,A))*x + (B-mod(div(N+A-1,A)+B-1,B))*y + (mod(div(N+B*A-1,B*A)+C-1,C))*z
-<A-1,B+1,C-1>/2)".

//---begin pov
#include "colors.inc"

light_source {<20,100,-150> rgb 2}
camera {location <0,0,-6> look_at 0}

#macro Arrange_3d (Dimentions_vector0,N)
        #local Dimentions_vector = Dimentions_vector0 * <1,1,1>;
        #local A = Dimentions_vector.x;
        #local B = Dimentions_vector.y;
        #local C = Dimentions_vector.z;
        #local Error_loop = 1;
        #while (Error_loop <= 3)
                #switch (Error_loop)
                        #case (1)
                                #local Vect = A;
                        #break
                        #case (2)
                                #local Vect = B;
                        #break
                        #case (3)
                                #local Vect = C;
                        #break
                #end
                #if (abs(Vect)<1)
                        #local Input_error = yes;
                #end
                #if (Vect-int(Vect.x)>0)
                        #local Input_error = yes;
                #end
                #if ((Vect/abs(Vect))<0)
                        #local Input_error = yes;
                #end
                #local Error_loop = Error_loop + 1;
        #end
        #ifdef (Input_error)
                #if (Input_error = yes)
                        #error "Dimentions_vector has a number that is not a natural
number"
                #end
        #end

       ( (mod(N+A-1,A))*x + (B-mod(div(N+A-1,A)+B-1,B))*y +
(mod(div(N+B*A-1,B*A)+C-1,C))*z
-<A-1,B+1,C-1>/2)
#end  // use only natural numbers aka 1,2,3,4,5,6... no fractions 0 or negative
numbers


#macro Grid (Dimentions_vector0,Marker_interval,Marker_scale)
        #local Dimentions_vector = Dimentions_vector0 * <1,1,1>;
        #local N = 1;
        union {
        #while (N <= (((Dimentions_vector.x * 2) + 1)*((Dimentions_vector.y * 2)
+1)*((Dimentions_vector.z * 2) + 1)))
                #local Grid_vector = Arrange_3d(<(Dimentions_vector.x * 2) +
1,(Dimentions_vector.y * 2) +1,(Dimentions_vector.z * 2) + 1>,N) * Marker_interval;
                union {
                sphere {0,.5}
                text { ttf "timrom.ttf"
concat("<",str(Grid_vector.x,1,0),",",str(Grid_vector.y,1,0),",",str(Grid_vector.z,1,0),">")
.5 0
translate 1}
                scale Marker_scale
                translate Grid_vector}
                #local N = N+1;
        #end
        }
#end

object {Grid(<3,2,1>,1,.1) pigment{Green}}
//--end pov


--
Dan Johnson

http://www.geocities.com/zapob


Post a reply to this message

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