DrawCircularText() function

Share your advanced PureBasic knowledge/code with the community.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

DrawCircularText() function

Post by Psychophanta »

The function accepts the coordinates of the circle's center, the radius and the angle (polar coordinates):

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
Test it:

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
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
BarryG
Addict
Addict
Posts: 4175
Joined: Thu Apr 18, 2019 8:17 am

Re: DrawCircularText() function

Post by BarryG »

Interesting! Thanks.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 572
Joined: Tue Jan 04, 2011 6:21 pm

Re: DrawCircularText() function

Post by SPH »

Very nice :!:

Original :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: DrawCircularText() function

Post by Kwai chang caine »

Yes never see this effect :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply