POV-Ray : Newsgroups : povray.newusers : Array coding problem Server Time
28 Mar 2024 08:35:38 EDT (-0400)
  Array coding problem (Message 1 to 4 of 4)  
From: AQ
Subject: Array coding problem
Date: 20 Sep 2016 11:39:11
Message: <06l2ub10339pagp3g18ljmaqimjnlc3ni8@4ax.com>
I want to fill a 6 by 3 array with either a 0 or a 1 chosen at random
and then use these values in a colour map.  I thought it would be easy
but the code below gives an error and I cannot see why.  

#declare Col = array[7][4]
#for (j,0,6,1)
  #for (k,1,3,1)
    Col[j][k] = int(2*rand(R))
  #end
#end  
.
When I run the code I get the messagePrese

"C:\Povray\Harmonograph\Harmonograph 12.pov" line 62: Parse Error:
Attempt to access uninitialized array element.

But I thought I had initialised it !!

I was planning to us the values in a colour map like this 

colour_map {
              [0.0/6  rgb < Col[0,1], Col[0,2], Col[0,3] >]        
              [1.0/6  rgb < Col[1,1], Col[1,2], Col[1,3] >] 
              [2.0/6  rgb < Col[2,1], Col[2,2], Col[2,3] >] 
              [3.0/6  rgb < Col[3,1], Col[3,2], Col[3,3] >] 
              [4.0/6  rgb < Col[1,1], Col[4,2], Col[4,3] >] 
              [5.0/6  rgb < Col[5,1], Col[5,2], Col[5,3] >] 
              [6.0/6  rgb < Col[6,1], Col[6,2], Col[6,3] >]
            }

Any suggestions please

John


Post a reply to this message

From: Bald Eagle
Subject: Re: Array coding problem
Date: 20 Sep 2016 12:10:01
Message: <web.57e15f33ed1fe0c7b488d9aa0@news.povray.org>
I get that error all the time - I just fiddle with the code until I get it to
stop.

This works for me on 3.7 :
(note : I changed the range of k to 0 to 3)
###################################################

  #declare R = seed(123);

#declare Col = array[7][4]
#for (j,0,6,1)
  #for (k,0,3,1)

    #declare Col[j][k] = int(2*rand(R));
  #end
#end


Post a reply to this message

From: clipka
Subject: Re: Array coding problem
Date: 20 Sep 2016 13:22:08
Message: <57e17040$1@news.povray.org>
Am 20.09.2016 um 17:39 schrieb AQ:
> I want to fill a 6 by 3 array with either a 0 or a 1 chosen at random
> and then use these values in a colour map.  I thought it would be easy
> but the code below gives an error and I cannot see why.  
> 
> #declare Col = array[7][4]
> #for (j,0,6,1)
>   #for (k,1,3,1)
>     Col[j][k] = int(2*rand(R))

You'll want to use

    #declare Col[j][k] = int(2*rand(R))


> colour_map {
>               [0.0/6  rgb < Col[0,1], Col[0,2], Col[0,3] >]        
>               [1.0/6  rgb < Col[1,1], Col[1,2], Col[1,3] >] 
>               [2.0/6  rgb < Col[2,1], Col[2,2], Col[2,3] >] 
>               [3.0/6  rgb < Col[3,1], Col[3,2], Col[3,3] >] 
>               [4.0/6  rgb < Col[1,1], Col[4,2], Col[4,3] >] 
>               [5.0/6  rgb < Col[5,1], Col[5,2], Col[5,3] >] 
>               [6.0/6  rgb < Col[6,1], Col[6,2], Col[6,3] >]
>             }

You'll also want to replace Col[x,y] with Col[x][y].


Post a reply to this message

From: AQ
Subject: Re: Array coding problem
Date: 20 Sep 2016 15:53:55
Message: <2r43ubdf4g2jj2r4695m68knmfpjqko7tr@4ax.com>
On Tue, 20 Sep 2016 19:22:10 +0200, clipka <ano### [at] anonymousorg>
wrote:

>Am 20.09.2016 um 17:39 schrieb AQ:
>> I want to fill a 6 by 3 array with either a 0 or a 1 chosen at random
>> and then use these values in a colour map.  I thought it would be easy
>> but the code below gives an error and I cannot see why.  
>> 
>> #declare Col = array[7][4]
>> #for (j,0,6,1)
>>   #for (k,1,3,1)
>>     Col[j][k] = int(2*rand(R))
>
>You'll want to use
>
>    #declare Col[j][k] = int(2*rand(R))
>
>
>> colour_map {
>>               [0.0/6  rgb < Col[0,1], Col[0,2], Col[0,3] >]        
>>               [1.0/6  rgb < Col[1,1], Col[1,2], Col[1,3] >] 
>>               [2.0/6  rgb < Col[2,1], Col[2,2], Col[2,3] >] 
>>               [3.0/6  rgb < Col[3,1], Col[3,2], Col[3,3] >] 
>>               [4.0/6  rgb < Col[1,1], Col[4,2], Col[4,3] >] 
>>               [5.0/6  rgb < Col[5,1], Col[5,2], Col[5,3] >] 
>>               [6.0/6  rgb < Col[6,1], Col[6,2], Col[6,3] >]
>>             }
>
>You'll also want to replace Col[x,y] with Col[x][y].

Thank you for the help.

Now I have the code working I do not like the effect !!!!!  and will
probably go back to the hand coded colour map.  It was an interesting
exercise though.

John


Post a reply to this message

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