POV-Ray : Newsgroups : povray.text.scene-files : circletext.pov : Make text go in circles Server Time
31 Oct 2024 08:14:44 EDT (-0400)
  circletext.pov : Make text go in circles (Message 1 to 1 of 1)  
From: Ron Parker
Subject: circletext.pov : Make text go in circles
Date: 13 Dec 2000 12:19:44
Message: <slrn93fbth.1lc.ron.parker@fwi.com>
// CircleText macro
    
#declare CircleText_Left = 1;
#declare CircleText_Right = 2;
#declare CircleText_Center = 3;    
  
#macro TextWidth( Text, Font, Size )
  #local TextObj = text { ttf Font concat("|",Text,"|") 1 0 scale 
     <Size, Size, 1> }
  #local TextObj2 = text { ttf Font "||" 1 0 scale <Size, Size, 1>}
  ((max_extent(TextObj).x-min_extent(TextObj).x)-
   (max_extent(TextObj2).x-min_extent(TextObj2).x))
#end  
    
#macro CircleText( Text, Font, Size, Depth, Radius, Inverted, Justification, 
                    Angle )
  #local FullWidth = TextWidth( Text, Font, Size );
  #local TextObj = text { ttf Font Text 1 0 scale <Size, Size, 1> }
  #local TextHeight = max_extent(TextObj).y;
  #local Chars = array[strlen(Text)]
  
  #if ( FullWidth > 2 * pi * Radius ) 
    #debug concat( "\n\n**** Text string \"", Text, 
           "\" is too long for a circle of the specified radius.\n\n\n" )
    #error ""
  #end                                                           
  
  #local AngleWidth = -FullWidth*180 / pi/Radius;
  #local StartAngle = Angle;
  #local EndAngle = Angle + AngleWidth;
  #if (((Justification = CircleText_Right) & !Inverted) | 
       ((Justification = CircleText_Left) & Inverted)) 
    #local StartAngle = Angle - AngleWidth;
    #local EndAngle = Angle;
  #else
    #if ( Justification = CircleText_Center )
      #local StartAngle = Angle - AngleWidth / 2;
      #local EndAngle = Angle + AngleWidth / 2;
    #end
  #end
  
  #local CharIndex = 1;
  #while ( CharIndex <= strlen( Text )) 
    #if (CharIndex != 1)
      #local LeftTextWidth = TextWidth(substr( Text, 1, CharIndex-1 ), 
                                    Font, Size );
    #else
      #local LeftTextWidth = 0;
    #end
    #local ObjExt = TextWidth(substr(Text, CharIndex, 1), Font, Size);
    #local LeftAngle = StartAngle + AngleWidth*LeftTextWidth/FullWidth+
                       .5*ObjExt.x/FullWidth*AngleWidth;
    #if (Inverted)
      #local LeftAngle = EndAngle - (LeftAngle - StartAngle);
    #end
    #local TextObj = text { ttf Font substr(Text,CharIndex,1) Depth 0 
                             scale <Size, Size, 1> }
    #if (Inverted)
      #local Chars[CharIndex-1] = object {TextObj rotate 180*z translate 
         <ObjExt/2, TextHeight, 0> rotate -90*z translate Radius*x 
         rotate LeftAngle*z}
    #else                                                             
      #local Chars[CharIndex-1] = object {TextObj translate -ObjExt/2*x 
         rotate -90*z translate Radius*x rotate LeftAngle*z}
    #end                                    
    #local CharIndex = CharIndex +1;
  #end                
  union {              
  #local CharIndex = 0;
  #while ( CharIndex < strlen( Text )) 
    object {Chars[CharIndex]}
    #local CharIndex = CharIndex + 1;
  #end                              
  }
#end

camera {location -3*z look_at 0}
light_source {-20*z rgb 1 shadowless}
cylinder {.1*z,.2*z,1 pigment {radial 
   color_map {[1/3 red 1][1/3 rgb 1][2/3 rgb 1][2/3 blue 1]} 
   frequency 30 rotate 90*x}}

union {
  CircleText( "\"These are the times that try mens' souls.\"", "arial.ttf", 
    .2, .01, 1.1, false, CircleText_Center, 90 )
  CircleText( "The American Crisis", "arial.ttf", .2, .01, 1.1, true, 
    CircleText_Center, -90 )
  CircleText( "Thomas Paine", "arial.ttf", .15, .01, 1.3, true, 
    CircleText_Left, -135)
  CircleText( "1780", "arial.ttf", .15, .01, 1.3, true, CircleText_Right, -45)
  pigment {color green 1}
}


-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

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