|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Is there a function I can use to convert a string into an array?
Thanks!
Mike
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
SharkD <mik### [at] gmailcom> wrote:
> Is there a function I can use to convert a string into an array?
I once saw a trick in which some pov code wrote the string to a file and then
#include'd it back. Might be a start.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"SharkD" <mik### [at] gmailcom> wrote in message
news:4ae7d67a@news.povray.org...
> Is there a function I can use to convert a string into an array?
>
> Thanks!
>
> Mike
I don't remember seeing a standard function, but it's quick to split a
string with the existing POVRay functions and a #while loop (see the 2
examples below).
If you want more sophisticated processing you'll find some macros in the
Scroll include file from the Object Collection that can left, right, centre
or full justify text strings.
Note that the examples below write the strings to the message stream and
produce only a completely black image.
Regards,
Chris B.
camera { location z look_at 0 }
light_source { <-5,30,-10> 1 }
#declare Str = "How many roads must a man walk down?";
// Convert string to array of single characters
#declare Arr = array[strlen(Str)];
#declare Ctr = 0;
#while (Ctr<strlen(Str))
#declare Arr[Ctr] = substr(Str,Ctr+1,1);
#debug concat(Arr[Ctr],"\n")
#declare Ctr = Ctr+1;
#end
// Split string on spaces
#declare Arr = array[strlen(Str)];
#declare Ctr = 0;
#declare Pos = 1;
#declare Words = 0;
#while (Ctr<strlen(Str))
#if (strcmp(substr(Str,Ctr+1,1)," ")=0)
#declare Arr[Words] = substr(Str,Pos,Ctr-Pos+1)
#declare Pos = Ctr+2;
#debug concat(Arr[Words],"\n")
#declare Words = Words+1;
#end
#declare Ctr = Ctr+1;
#end
#declare Arr[Words] = substr(Str,Pos,strlen(Str)-Pos+1)
#debug concat(Arr[Words],"\n")
#declare Words = Words+1;
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 10/28/2009 7:21 AM, Chris B wrote:
> I don't remember seeing a standard function, but it's quick to split a
> string with the existing POVRay functions and a #while loop (see the 2
> examples below).
>
> If you want more sophisticated processing you'll find some macros in the
> Scroll include file from the Object Collection that can left, right,
> centre or full justify text strings.
>
> Note that the examples below write the strings to the message stream and
> produce only a completely black image.
>
> Regards,
> Chris B.
Nice tip, thanks!
Next question: How do I modify a one character text object such that the
character fits inside a 1x1x1 cube? (Note that I am working only with
single character strings, so I don't have to worry about what happens
with larger strings.)
Mike
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"SharkD" <mik### [at] gmailcom> wrote in message
news:4ae8fd66$1@news.povray.org...
>
> Next question: How do I modify a one character text object such that the
> character fits inside a 1x1x1 cube? (Note that I am working only with
> single character strings, so I don't have to worry about what happens with
> larger strings.)
>
Assign a text object to an identifier, then use the min_extent and
max_extent functions to find the dimensions of the resulting object and
scale it accordingly as you add it to the scene:
#declare Letter = text {ttf "arial.ttf","~",1,0}
object {Letter
translate -min_extent(Letter)
scale 1/(max_extent(Letter)-min_extent(Letter))
pigment {rgb <1,1,0>}
}
box {-0.001,1.001 pigment {rgbt 0.7}}
Though you don't need it to, this should work the same with a
multi-character string and should work reasonably well with a lot of other
POV-Ray objects to boot. These functions actually measure the bounding box
of the object, but I think that the bounding box aligns pretty well with the
actual extents of a text object (I didn't yet notice any big differences).
It doesn't align very well with certain CSG objects and I hate to think what
would happen with infinite objects such as planes :-)
Regards,
Chris B.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 10/29/2009 4:39 AM, Chris B wrote:
> Assign a text object to an identifier, then use the min_extent and
> max_extent functions to find the dimensions of the resulting object and
> scale it accordingly as you add it to the scene:
Again, that worked perfectly. Much thanks!
Mike
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|