POV-Ray : Newsgroups : povray.general : remove array element after N uses? : Re: remove array element after N uses? Server Time
16 May 2024 01:09:21 EDT (-0400)
  Re: remove array element after N uses?  
From: clipka
Date: 25 Mar 2009 11:40:00
Message: <web.49ca4fd59fb46029c1f399840@news.povray.org>
"[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
> Lets say that I have an array of vectors, and that I wish to use its
> elements a variable number of times (which might be different for each
> element) and then remove the used element from the array.
>
> The only thing that I can come up with would be to use a 3D array like this:

Oh, those pesky OOP-spoilt greenhorns! ;)

When I was still young and handsome, such information would be stored in a
separate array, like this:

    10 DIM x(100),y(100),z,used%(100)
    20 FOR loop% = 1 TO 4711
    30   LET i% = RND(100) + 1
    40   LET used%(i%) = used%(i%) + 1
    50   PRINT "<";STR$(x(%i));",";STR$(y(%i));","STR$(z(%i));">"
    60 NEXT loop%
    70 END
    5 RANDOMIE TIME
    12 GOSUB 1000 : REM fill data
    50   PRINT "<";STR$(x(%i));",";STR$(y(%i));","STR$(z(%i));">";
    55   PRINT " used ";STR$(used%(i));" times"
    LIST -100
    5 RANDOMIE TIME
    10 DIM x(100),y(100),z,used%(100)
    12 GOSUB 1000 : REM fill data
    20 FOR loop% = 1 TO 4711
    30   LET i% = RND(100) + 1
    40   LET used%(i%) = used%(i%) + 1
    50   PRINT "<";STR$(x(%i));",";STR$(y(%i));","STR$(z(%i));">";
    55   PRINT " used ";STR$(used%(i));" times"
    60 NEXT loop%
    70 END
    READY
    RUN
    SYNTAX ERROR IN LINE 5
    READY
    LIST 5
    5 RANDOMIE TIME
    READY
    5 RANDOMIZE TIME
    RUN
    LINE DOES NOT EXIST IN LINE 12
    READY

(Yeah, those were the days! You just flipped the power switch, and your
programming IDE would be up and running in 5 seconds... ah, modern
technological advancement has deprived us of all that joy...)

.... then someone invented structs (oh, well, "records" for me back then, because
I went for Turbo Pascal)...

But I'm getting a bit off topic... so back to your problem:

First thing to know: No, POV SDL unfortunately doesn't have something like
structs. Nor does it have dynamic lists. Be happy and content that you don't
have to mess around with line numbers ;)

>   #declare Array[i][0][0] = <RRand(RsA, Min, Max),RRand(RsA, Min,
> Max),RRand(RsA, Min, Max)>;
>   #declare Array[i][1][0] = <0,0,0>;
>   #declare Array[i][1][1] = <0,RRand(RsA, rMin, rMax),0>;

Why use a 3-dimensional array when a 2-dimensional one will do the job?

#declare Array[i][0] = <...>;
#declare Array[i][1] = <0,0,0>;
#declare Array[i][2] = <0,RRand(RsA, rMin, rMax),0>;

Then, to get rid of an entry of such an array, you could use:

#undef Array[i][0]
#undef Array[i][1]
#undef Array[i][2]

and check for #ifdef(Array[i][0]) when you loop through the array.

I guess that's as close as you can get to what you want.


Post a reply to this message

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