Page 1 of 1

Circles Glow

Posted: Wed Dec 03, 2025 2:29 pm
by threedslider
Hi my new code :)

Code: Select all

; ------------------------------------------
;  Cercles violets avec Glow + Interaction
; ------------------------------------------

EnableExplicit

; Structure d'un cercle animé
Structure Circle
  x.f
  y.f
  dx.f
  dy.f
  radius.f
EndStructure

Global Dim Circles.Circle(20)   ; 21 cercles
Global speedBoost.f = 1.0       ; Multiplicateur de vitesse

; Initialisation des cercles
Procedure InitCircles()
  Protected i

  For i = 0 To ArraySize(Circles())
    Circles(i)\x = Random(800)
    Circles(i)\y = Random(600)
    Circles(i)\dx = (Random(40) / 10.0 - 2.0)
    Circles(i)\dy = (Random(40) / 10.0 - 2.0)
    Circles(i)\radius = 10 + Random(20)
  Next i
EndProcedure


; Mise à jour des positions
Procedure UpdateCircles()
  Protected i

  For i = 0 To ArraySize(Circles())
    
    Circles(i)\x + Circles(i)\dx * speedBoost
    Circles(i)\y + Circles(i)\dy * speedBoost

    ; rebond sur les bords
    If Circles(i)\x < 0 Or Circles(i)\x > 800
      Circles(i)\dx = -Circles(i)\dx
    EndIf

    If Circles(i)\y < 0 Or Circles(i)\y > 600
      Circles(i)\dy = -Circles(i)\dy
    EndIf
  Next i
EndProcedure


; Dessin glow d’un cercle violet
Procedure DrawGlowCircle(x, y, r)
  Protected i, alpha

  For i = 10 To 0 Step -1
    alpha = 12 * i
    Circle(x, y, r + i * 2, RGBA(180, 0, 255, alpha))
  Next i

  Circle(x, y, r, RGBA(200, 0, 255, 255))
EndProcedure


; ------------------------------------------
; Programme principal
; ------------------------------------------

Define i.i, event.i

InitSprite()
InitKeyboard()

SetFrameRate(60)

If OpenWindow(0, 0, 0, 800/DesktopResolutionX(), 600/DesktopResolutionY(), "Cercles Glow", #PB_Window_ScreenCentered )
  ;OpenWindowedScreen(WindowID(0), 0, 0, 800, 600) : SetFrameRate(60) ;: 
  If StartDrawing(WindowOutput(0))
    InitCircles()
    StopDrawing()
  EndIf
  

  Repeat
    event = WindowEvent()
    ; Gestion des événements souris
    If GetAsyncKeyState_(#VK_LBUTTON)
      speedBoost = 5.0
    Else
      speedBoost = 0.5
    EndIf

    ; Mise à jour
    UpdateCircles()

    ; Dessin
    StartDrawing(WindowOutput(0))
    Box(0, 0, 800, 600, RGB(0, 0, 0))   ; Effacer écran
    ;ClearScreen(RGB(0,0,0))
    

      For i = 0 To ArraySize(Circles())
        DrawGlowCircle(Circles(i)\x, Circles(i)\y, Circles(i)\radius)
      Next i
      
      

    StopDrawing()

    
    FlipBuffers()
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape)
EndIf

End
Key with escape to quit and mouse with left button to speed in move :)

Enjoy !

Happy coding !

Re: Circles Glow

Posted: Wed Dec 03, 2025 2:49 pm
by BarryG
Doesn't compile for me. Line 76 ("SetFrameRate") says there is no open screen.

Re: Circles Glow

Posted: Wed Dec 03, 2025 3:23 pm
by Sergey
BarryG wrote: Wed Dec 03, 2025 2:49 pm Doesn't compile for me. Line 76 ("SetFrameRate") says there is no open screen.
comment this line
; SetFrameRate(60)

If OpenWindow(0, 0, 0, 800/DesktopResolutionX(), 600/DesktopResolutionY(), "Cercles Glow", #PB_Window_ScreenCentered )
uncomment this line
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600) : SetFrameRate(60) ;:

and press left mouse button to speed up glow circles

Re: Circles Glow

Posted: Wed Dec 03, 2025 3:32 pm
by threedslider
BarryG wrote: Wed Dec 03, 2025 2:49 pm Doesn't compile for me. Line 76 ("SetFrameRate") says there is no open screen.
Strange, for me it works in windows 11... See Sergey if it works for you ?

Re: Circles Glow

Posted: Wed Dec 03, 2025 3:40 pm
by threedslider
Openwindowscreen looks a bit dark for circles glow... don't know what issue is it ? And a bit slower too :shock:

Re: Circles Glow

Posted: Wed Dec 03, 2025 6:14 pm
by JHPJHP
Hi threedslider,

It was only running on Windows 11 because your IDE debugger was disabled.

Here is a basic Sprite template to help with future examples.
• Not DPI Aware

Code: Select all

Enumeration
  #MainWindow
  #Template
EndEnumeration

InitSprite() : InitKeyboard()

xmax = 800 : ymax = 600
nFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

If OpenWindow(#MainWindow, 0, 0, xmax, ymax, "Template", nFlags)
  If OpenWindowedScreen(WindowID(#MainWindow), 0, 0, xmax, ymax)
    CreateSprite(#Template, xmax, ymax)

    Repeat
      Repeat
        Event = WindowEvent()

        If Event = #PB_Event_CloseWindow : Break 2 : EndIf

      Until Not Event
      FlipBuffers()
      ExamineKeyboard()

      If KeyboardReleased(#PB_Key_Escape) : PostEvent(#PB_Event_CloseWindow) : EndIf

      If StartDrawing(SpriteOutput(#Template))
        Box(0, 0, xmax, ymax, $000000)
        
        StopDrawing()
      EndIf
      DisplaySprite(#Template, 0, 0)
    ForEver
  EndIf
EndIf

Re: Circles Glow

Posted: Wed Dec 03, 2025 7:30 pm
by threedslider
Thanks for your modification, @JHPJHP :)

Yeah I have somewhat worked with AI but I don't find for glow very bright as beautiful as neon :shock: