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. Windows can be forgiving at times :)

Your example was giving AI a bad name :lol: so I rewrote it to produce what I believe is the intended visual effect.

Code: Select all

Enumeration
  #MainWindow
  #SpriteCircle
EndEnumeration

Structure CIRCLE
  x.f
  y.f
  dx.f
  dy.f
  radius.f
EndStructure

Macro ScaleFactor
  DesktopResolutionX()
EndMacro

Macro ScaleFactorM(value)
  (value) * ScaleFactor
EndMacro

Procedure InitCircles(Array Circles.CIRCLE(1), SpriteWidth, SpriteHeight)
  For rtnCount = 0 To ArraySize(Circles())
    Circles(rtnCount)\x = Random(SpriteWidth)
    Circles(rtnCount)\y = Random(SpriteHeight)
    Circles(rtnCount)\dx = (Random(40) / 10 - 2)
    Circles(rtnCount)\dy = (Random(40) / 10 - 2)
    Circles(rtnCount)\radius = 10 + Random(20)
  Next
EndProcedure

Procedure UpdateCircles(Array Circles.CIRCLE(1), SpriteWidth, SpriteHeight, SpeedBoost.f)
  For rtnCount = 0 To ArraySize(Circles())
    Circles(rtnCount)\x + Circles(rtnCount)\dx * SpeedBoost
    Circles(rtnCount)\y + Circles(rtnCount)\dy * SpeedBoost

    If Circles(rtnCount)\x < 0 Or Circles(rtnCount)\x > SpriteWidth
      Circles(rtnCount)\dx = -Circles(rtnCount)\dx
    EndIf

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

Procedure DrawGlowCircle(x, y, radius)
  For rtnCount = 10 To 0 Step -1
    alpha = 12 * rtnCount
    Circle(x, y, radius + rtnCount * 2, RGBA(180, 0, 255, alpha))
  Next
  Circle(x, y, radius, RGBA(200, 0, 255, 255))
EndProcedure

InitSprite() : InitKeyboard()

SpeedBoost.f = 3
CircleTotal = 20
Dim Circles.CIRCLE(CircleTotal)

WindowWidth = 800 : WindowHeight = 600
SpriteWidth = ScaleFactorM(WindowWidth)
SpriteHeight = ScaleFactorM(WindowHeight)
Title$ = "Glowing Circles  " + Chr(9205) + "  Left / Right Arrow Keys  =  Speed Boost  :  "
nFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

If OpenWindow(#MainWindow, 0, 0, WindowWidth, WindowHeight, Title$ + StrF(SpeedBoost, 1), nFlags)
  If OpenWindowedScreen(WindowID(#MainWindow), 0, 0, SpriteWidth, SpriteHeight)
    SetFrameRate(60)
    SpriteQuality(#PB_Sprite_BilinearFiltering)
    CreateSprite(#SpriteCircle, SpriteWidth, SpriteHeight, #PB_Sprite_AlphaBlending)

    If StartDrawing(SpriteOutput(#SpriteCircle))
      InitCircles(Circles(), SpriteWidth, SpriteHeight)
      StopDrawing()
    EndIf
    ArraySize = ArraySize(Circles())

    Repeat
      Repeat
        Event = WindowEvent()

        Select Event
          Case #PB_Event_CloseWindow
            Break 2
        EndSelect
      Until Not Event
      FlipBuffers()
      ClearScreen($000000)
      ExamineKeyboard()

      If KeyboardReleased(#PB_Key_Left)
        If SpeedBoost > 1
          SpeedBoost - 0.5
          SetWindowTitle(#MainWindow, Title$ + StrF(SpeedBoost, 1))
        EndIf
      EndIf

      If KeyboardReleased(#PB_Key_Right)
        If SpeedBoost < 5
          SpeedBoost + 0.5
          SetWindowTitle(#MainWindow, Title$ + StrF(SpeedBoost, 1))
        EndIf
      EndIf

      If KeyboardReleased(#PB_Key_Escape) : Break : EndIf

      UpdateCircles(Circles(), SpriteWidth, SpriteHeight, SpeedBoost)

      If StartDrawing(SpriteOutput(#SpriteCircle))
        DrawingMode(#PB_2DDrawing_AlphaBlend)
        Box(0, 0, SpriteWidth, SpriteHeight, RGBA(0, 0, 0, 255))

        For rtnCount = 0 To ArraySize - 1
          DrawGlowCircle(Circles(rtnCount)\x, Circles(rtnCount)\y, Circles(rtnCount)\radius)
        Next
        StopDrawing()
      EndIf
      DisplaySprite(#SpriteCircle, 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: