POV-Ray : Newsgroups : povray.advanced-users : read colors from file Server Time
5 Jul 2024 15:37:05 EDT (-0400)
  read colors from file (Message 1 to 3 of 3)  
From: kurtz le pirate
Subject: read colors from file
Date: 10 Jun 2007 02:12:06
Message: <kurtzlepirate-6907DD.08120610062007@news.povray.org>
hello.

i am trying to read colors (as defined in colors.inc) from a file. code 
part here :


#declare fileName = "datas.txt";
#declare infos = array[20][3];

#set index=0;
#fopen FILE fileName read
#while (defined(FILE))
  #read (FILE,pourcentage,decalage,couleur)
  #declare infos[index][0] = pourcentage; 
  #declare infos[index][1] = decalage;  
  #declare infos[index][2] = couleur; 
  #set index=index+1;
#end
#fclose FILE

if "datas.txt" contains :
2, 0, Red
12, 1, Green
...
...

i get a parse error : expected 'float, vetor or string literal', colour 
identifier found instead for the first line of the file.


if "datas.txt" contains :
2, 0, "Red"
12, 1, "Green"
...
...

i get a parse error for the line "#declare infos[index][2] = couleur" : 
attempted to redefine float identifier as string identifier.



any chance to read a "named color" from a file an put it in an array ?



+
-- 
klp


Post a reply to this message

From: Tim Attwood
Subject: Re: read colors from file
Date: 10 Jun 2007 03:01:53
Message: <466ba1e1$1@news.povray.org>
You can only read CSV floats, vectors, and
quote delimited strings from a file.

Arrays can only hold elements of the same type.

You can use three arrays instead though.

Then you can construct a string to parse with
the Parse_String macro in strings.inc, and that
will convert a string like "Red" to a color identifier.

#include "strings.inc"
#declare fileName = "datas.txt";
#declare pourcentage = array[20];
#declare decalage = array[20];
#declare infocouleur= array[20];

#set index=0;
#fopen FILE fileName read
#while (defined(FILE))
  #read (FILE,P,D,C)
  #declare pourcentage[index]= P;
  #declare decalage[index]=D;
  cmd=concat("#declare infocouleur[index]=",C,";")
  Parse_String(cmd)
  #set index=index+1;
#end
#fclose FILE


Post a reply to this message

From: kurtz le pirate
Subject: Re: read colors from file
Date: 10 Jun 2007 10:40:46
Message: <kurtzlepirate-38CC25.16404510062007@news.povray.org>
In article <466ba1e1$1@news.povray.org>,
 "Tim Attwood" <tim### [at] comcastnet> wrote:

> You can only read CSV floats, vectors, and
> quote delimited strings from a file.
> 
> Arrays can only hold elements of the same type.
> 
> You can use three arrays instead though.
> 
> Then you can construct a string to parse with
> the Parse_String macro in strings.inc, and that
> will convert a string like "Red" to a color identifier.
> 
> #include "strings.inc"
> #declare fileName = "datas.txt";
> #declare pourcentage = array[20];
> #declare decalage = array[20];
> #declare infocouleur= array[20];
> 
> #set index=0;
> #fopen FILE fileName read
> #while (defined(FILE))
>   #read (FILE,P,D,C)
>   #declare pourcentage[index]= P;
>   #declare decalage[index]=D;
>   cmd=concat("#declare infocouleur[index]=",C,";")
>   Parse_String(cmd)
>   #set index=index+1;
> #end
> #fclose FILE



thank tim. very very interresting things in your post : writing in a 
file then including it !!

just correcting with #declare cmd=...




-- 
klp


Post a reply to this message

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