POV-Ray : Newsgroups : povray.general : Automatically named identifiers : Re: Automatically named identifiers Server Time
23 Nov 2024 03:23:15 EST (-0500)
  Re: Automatically named identifiers  
From: kurtz le pirate
Date: 5 Nov 2024 05:24:42
Message: <6729f26a$1@news.povray.org>
On 04/11/2024 23:52, Thomas Fester wrote:
> Hello everybody: I have got a (seemingly) simple programing question: Suppose I
> I want to declare a number of splines in a loop-process with one spline per
> loop. The splines should have identifiers like SplineXA, SplineXB, SplineXC and
> so on. Is there a way to automatically generate such names within the loops? At
> the moment I am only able to explicitely generate every identifier on its own.

To my knowledge, it is not possible to generate variables on the fly.

One workaround may be to generate an “inc” file and then use this same.

For example :
-----------------------------------------------------------------------
...
...
// -----------------------
// --- file generation ---
// -----------------------
#declare alea = seed(2753);

// name of include file containing splines
#declare FileName = "Splines.inc";
// opening the file
#fopen FILE FileName write


// five splines in this example
#declare Nb = 5;
// i : spline index
#declare i = 0;
// loop for splines
#while ( i < Nb )
	// build declaration string for named splines
	#declare Name = concat("#declare SplineX",chr(i+65)," = spline 
{\n\tcubic_spline\n")
	// write it to the file
	#write (FILE, Name)
	// --- fake spline generation ---
	// random number of points in spline
	#declare SplinePoint = 2+int(12*rand(alea));
	// calculates increment to go from zero to one
	#declare inc = 1/(SplinePoint-1);
	// j : points in spline index
	#declare j = 0;
	// loop for points in each spline
	#while ( j < SplinePoint )
		// random 3d point
		#declare point = concat("< ",str(rand(alea)*20-10,0,2),", 
",str(rand(alea)*20-10,0,2),", ",str(rand(alea)*20-10,0,2),">")
		// 'time' value for the point
		#declare splineItem = concat("\t",str(inc*j,0,2),", ",point,"\n")
		// write to the file
		#write (FILE, splineItem)
		// increment points index
		#declare j = j + 1;
		// to the next point...
	#end
	// write end of spline declaration
	#write (FILE, "\t}\n\n")
	// increment spline index
	#declare i = i + 1;
	// to the next spline
#end
// close the include file
#fclose FILE
#debug "\nEnd of spline generation\n"
...
...
// ----------------------------
// --- use generated spline ---
// ----------------------------
#include FileName

// here you can use SplineXA, SplineXB, ...

-----------------------------------------------------------------------


Hope that help ;)


Post a reply to this message

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