DrawCircularText() function
Posted: Tue Dec 01, 2020 10:18 pm
The function accepts the coordinates of the circle's center, the radius and the angle (polar coordinates):
Test it:
Code: Select all
Procedure DrawCircularText(px.f,py,f,R.f,a.f,t$,color.l=$FFFFFF,convexo.b=1)
Protected t.u,th.u=TextHeight(Mid(t$,1,1)),v.f
If convexo<0:convexo=-1
Else:convexo=1
R-th*1.333333
EndIf
For t=1 To Len(t$)
DrawRotatedText(px+R*Cos(a),py+R*Sin(a),Mid(t$,t,1),convexo*90-Degree(a),color)
a-convexo*th/R
Next
EndProcedure
Code: Select all
ExamineDesktops():SCREENWIDTH.u=DesktopWidth(0):SCREENHEIGHT.u=DesktopHeight(0)
InitMouse():InitSprite():InitKeyboard()
OpenScreen(SCREENWIDTH,SCREENHEIGHT.u,32,"texto circular")
MouseLocate(SCREENWIDTH.u/2,SCREENHEIGHT.u/2)
Procedure DrawCircularText(px.f,py,f,R.f,a.f,t$,color.l=$FFFFFF,convexo.b=1)
Protected t.u,th.u=TextHeight(Mid(t$,1,1)),v.f
If convexo<0:convexo=-1
Else:convexo=1
R-th*1.333333
EndIf
For t=1 To Len(t$)
DrawRotatedText(px+R*Cos(a),py+R*Sin(a),Mid(t$,t,1),convexo*90-Degree(a),color)
a-convexo*th/R
Next
EndProcedure
radio.f=190
Repeat
ExamineKeyboard():ExamineMouse()
px.f=MouseX():py.f=MouseY():di.f-MouseWheel()/13
MouseDeltaX():MouseDeltaY()
If MouseButton(#PB_MouseButton_Left)
pz.f-0.01
ElseIf MouseButton(#PB_MouseButton_Right)
pz.f+0.01
ElseIf KeyboardReleased(#PB_Key_Up)
u.b!2
EndIf
radio.f+pz
ClearScreen(0)
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Outlined)
For t.a=0 To 1
Circle(px.f,py.f,radio-t*20,$FABADA)
Next
DrawCircularText(px.f,py,f,radio,di,"This is a PureBasic function tip for 2D classic screen",$AABBCC,u.b-1)
StopDrawing()
FlipBuffers():Delay(16)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen():End