Martin Fitzgibbons wrote: (Sept. 28, '01)
I would like to print some individual letters in a
circular pattern but can't seem to nut it out.
For simplicity sake say there was 36 letters that I
want to go around the circumference.
How would I calculate their positions?
Any suggestions?
Here is a demo I put together that may show what you want. It
calculates the position of each letter in a text string using a
little bit of trigonometry and adjusts the position slightly for the
size of the characters so the mid-point of each letter is on the
desired circle to get a more pleasing look. The letters are still
vertically oriented; to rotate them you would need to also use an
of-screen GWorld.
Hope this helps.
- Stu Cram, Regina, Sask. Canada
' --------------- START OF PRGRAM ---------------
'~'2
' Printing Text Around A Circle Between 2 Angles - Demo Program;
' By Stu Cram, Regina, Sask Canada - Sept. 29, 2001
' For FB^3 Forum & reply to Martin Fitzgibbons' question.
'~'2
LOCAL FN showRefCircle( X,Y,R )
' draws a light gray circle with 12 radiating spokes
DIM degrees, radians#, h,v
DIM spokeNum
LONG COLOR -16384, -16384, -16384' light gray (25%)
CIRCLE x,y,r
FOR spokeNum = 1 TO 12
LET degrees = spokeNum * 30
' ... convert degrees to radians (PI is a built-in FB^3 value)
LET radians = degrees*PI/180
' ... calc. position for end of spoke a bit beyond edge of circle
LET h = X + (R+4) * SIN( radians )
LET v = Y - (R+4) * COS( radians )
' ... draw spoke from center to end of the spoke
PLOT X,Y TO h,v
NEXT spokeNum
END FN
'~'2
LOCAL FN ShowTextAroundCircle( T$, X,Y,R, B,E )
' X,Y Position (x,y) of circle's center
' R Radius of the circle
' B,E Beginning and Ending angles in degrees
' (North = 0°; positive = clockwise)
DIM numChars, charNum
DIM degrees#, radians#, angleStep#
DIM 1 ch$
DIM h, v
FN showRefCircle( X,Y,R ) ' <--- omit in final version
LET numChars = LEN( T$ )
' calc. angular distance between letters
LET angleStep = (E - B ) / (numChars-1)
FOR charNum = 1 TO numChars
' ... get the character to be shown
LET ch$ = CHR$( T$[charNum] )
' ... calc. angular position in degrees around circle
LET degrees = B + (charNum-1) * angleStep
' ... convert degrees to radians (PI is a built-in FB^3 value)
LET radians = degrees*PI/180
' ... calc. horz. position on screen & adjust for char. width
LET h = X + R * SIN( radians )
LET h = h - FN StringWidth( ch$ )/2
' ... calc. vert. position on screen & adjust for char. height
LET v = Y - R * COS( radians )
LET v = v + FN GetDefFontSize / 2
COLOR _zRed
' ... show the character in desired position
PRINT %(h,v) ch$;
DELAY 100 '<--- remove for final version
NEXT v
DELAY 1000 '<--- remove for final version
END FN
'~'2
WINDOW 1, "Text on a Circle - Demo", (0,0)-(800,600), 5
TEXT _Geneva, 14, 1
FN ShowTextAroundCircle( "0123456789", 100,100,75, 0,90 )
FN ShowTextAroundCircle( "0123456789", 260,340,100, 90,0 )
FN ShowTextAroundCircle( "ABCDEFGHIJKL", 600,400,150, 30,150 )
FN ShowTextAroundCircle( "12345", 600,400,150, -60,-120 )
FN ShowTextAroundCircle( "123456789", 500,100,60, -60,60 )
COLOR _zBlack
PRINT %( 20, WINDOW(_height)-5 ) "Click mouse to stop.";
DO
HandleEvents
UNTIL FN Button
'~'2
' --------------- END OF PRGRAM ---------------