I need to draw big range on screen, so I've decided to split a circle into different lines and assemble them in a proper way to make a circle:
Code: Select all
EnableExplicit
#screen_width = 1920
#screen_height = 1080
#app_title = "TITLE"
Define sprite_mouse.i, sprite_fps.i
Define frame.i, frame_refresh, frame_time.i, event.i
Global delta.d
InitKeyboard() : InitMouse() : InitSprite()
OpenWindow(0, 0, 0, #screen_width, #screen_height, #app_title, #PB_Window_BorderLess | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #screen_width, #screen_height, #False, 0, 0, #PB_Screen_SmartSynchronization)
sprite_mouse = CreateSprite(#PB_Any, 7, 7)
StartDrawing(SpriteOutput(sprite_mouse))
Box(0, 0, OutputWidth(), OutputHeight(), #Black)
Box(0, 0, OutputWidth() - 2, OutputHeight() - 2, #White)
StopDrawing()
sprite_fps = CreateSprite(#PB_Any, 40, 20)
;{ Circle segments.
Procedure.d GetDistance(x1.d, y1.d, x2.d, y2.d)
ProcedureReturn Abs(Sqr(Pow(x2 - x1, 2) + Pow(y2 - y1, 2)))
EndProcedure
Define i.i,
width.d,
height.d,
sprite.i,
x.d, y.d,
anchor_x.d, anchor_y.d,
radius.i,
size_modifier.d = 1.0,
size_modifier_trend.d = 0.001
NewList sprites.i()
#radius = 500
radius = #radius
anchor_x = #screen_width / 2
anchor_y = #screen_height / 2
#step = 5
width = GetDistance(anchor_x + radius * Cos(Radian(0)),
anchor_y + radius * Sin(Radian(0)),
anchor_x + radius * Cos(Radian(#step)),
anchor_y + radius * Sin(Radian(#step)))
width + 1
height = 2
For i = 0 To 360 Step #step
sprite = CreateSprite(#PB_Any, width, height)
StartDrawing(SpriteOutput(sprite))
Box(0, 0, width, height)
StopDrawing()
AddElement(sprites())
sprites() = sprite
Next i
;}
MouseLocate(DesktopMouseX(), DesktopMouseY())
Repeat
Repeat
event.i = WindowEvent()
If event = #PB_Event_CloseWindow : Break 2 : EndIf
Until event = 0
ClearScreen(RGB(0, 0, 0))
ExamineKeyboard() : ExamineMouse()
MouseLocate(DesktopMouseX(), DesktopMouseY())
; Draw the lines at the right place.
size_modifier + size_modifier_trend
If size_modifier >= 1.5 Or size_modifier <= 0.5
size_modifier_trend * -1
EndIf
i = 0
radius = #radius * size_modifier
ForEach sprites()
ZoomSprite(sprites(), Round(width * size_modifier, #PB_Round_Up), Round(height * size_modifier, #PB_Round_Up))
x = (anchor_x + radius * Cos(Radian(i))) - width / 2 ; - width / 2 to center the sprite on itself.
y = anchor_y + radius * Sin(Radian(i))
RotateSprite(sprites(), i - 90, #PB_Absolute)
DisplaySprite(sprites(), x, y)
i + #step
Next
DisplaySprite(sprite_fps, 0, 0)
DisplaySprite(sprite_mouse, MouseX(), MouseY())
; FPS and Delta Time
frame + 1
If ElapsedMilliseconds() > frame_refresh
StartDrawing(SpriteOutput(sprite_fps))
DrawText(0, 0, "fps:" + frame)
StopDrawing()
frame_refresh = ElapsedMilliseconds() + 1000
frame = 0
EndIf
delta = (ElapsedMilliseconds() - frame_time) / 1000
frame_time = ElapsedMilliseconds()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)