spinblur clock

Share your advanced PureBasic knowledge/code with the community.
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

spinblur clock

Post by firace »

Just a little idea for a cool clock - I'm sure it can be made much better!

Notes:
- Tested under Win10, Win 11 and Ubuntu
- (optional) try setting the Library Subsystem in Compiler options to DirectX9


Code: Select all

InitSprite() :  

W=760 : H=540  : C = $324F72 : Cellsize = 50 : LoadFont(99, "Consolas", 32)

OpenWindow(0, 35, 35, W+1, H, "firace's spinblur clock", #PB_Window_SizeGadget|#PB_Window_SystemMenu)

OpenWindowedScreen(WindowID(0),0,0,W+1,H,1,0,0)  : AddWindowTimer(0, 1, 1000)


Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow :   Break
    Case #PB_Event_Timer :
     
      ClearScreen(0)
      FlipBuffers()
      CreateSprite(33, W+200,W+200)
     
      StartDrawing(SpriteOutput(33))
      DrawingFont(FontID(99))
           
      sec$ = FormatDate("%hh:%ii:%ss", Date())
      DrawText(350,350,Sec$)
     
      StopDrawing()  
     
      x = 0
      Repeat : x+1
        StartDrawing(ScreenOutput())
        Box(-90,-140,W+200,W+200,0)
        StopDrawing()
        RotateSprite(33,  18,#PB_Relative) : DisplayTransparentSprite(33,-90,-140,42)
        FlipBuffers()
      Until x = 20
     
      StartDrawing(ScreenOutput())
      Box(-90,-140,W+200,W+200,0)
      StopDrawing()
      DisplayTransparentSprite(33,-90,-140,242)
      FlipBuffers()
     
  EndSelect
ForEver
Last edited by firace on Thu Nov 02, 2023 8:51 am, edited 4 times in total.
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: spinblur clock

Post by firace »

BTW Is anyone able to get a screenshot of the spinning effect ? I can't :)
User avatar
HeX0R
Addict
Addict
Posts: 1204
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: spinblur clock

Post by HeX0R »

That doesn't seem to work with latest PB version, I saw only a black window.
But with PB 5.73 it works just fine
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: spinblur clock

Post by firace »

HeX0R wrote: Wed Nov 01, 2023 8:04 pm That doesn't seem to work with latest PB version, I saw only a black window.
But with PB 5.73 it works just fine
Damn! Not sure how to fix it.
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: spinblur clock

Post by miso »

That way I can see something:

Code: Select all

InitSprite() :  W=750 : H=540  : C = $324F72 : Cellsize = 50 : LoadFont(99, "Consolas", 36)

OpenWindow(0, 35, 35, W+1, H, "firace's spinblur clock", #PB_Window_SizeGadget|#PB_Window_SystemMenu)

OpenWindowedScreen(WindowID(0),0,0,W+1,H,1,0,0)  : AddWindowTimer(0, 1, 1000)


Repeat 
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow :   Break
    Case #PB_Event_Timer :
      
      ClearScreen(0) 
      CreateSprite(33, W+200,W+200) 
      
      StartDrawing(SpriteOutput(33)) 
      : DrawingFont(FontID(99))
      
      
      a = 350  
      b = 350   
      
      sec$ = FormatDate("%hh:%ii:%ss", Date())
      ;DrawingMode(#PB_2DDrawing_Transparent)
      DrawRotatedText(a+3,b+3,Sec$,0) 
      
      StopDrawing()  
      TransparentSpriteColor(33,0)
      x = 0 
      Repeat : x+1
        RotateSprite(33,  18,#PB_Relative) : DisplayTransparentSprite(33,-90,-140,42) 
        FlipBuffers()
      Until x = 20
      DisplayTransparentSprite(33,-90,-140,242)
      FlipBuffers()
      
  EndSelect
ForEver
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: spinblur clock

Post by Paul »

HeX0R wrote: Wed Nov 01, 2023 8:04 pm That doesn't seem to work with latest PB version, I saw only a black window.
But with PB 5.73 it works just fine
Works here if I change Library Subsystem to DirectX9
Image Image
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: spinblur clock

Post by firace »

Paul wrote: Wed Nov 01, 2023 9:51 pm
HeX0R wrote: Wed Nov 01, 2023 8:04 pm That doesn't seem to work with latest PB version, I saw only a black window.
But with PB 5.73 it works just fine
Works here if I change Library Subsystem to DirectX9
Confirmed! Thanks for testing
User avatar
Kiffi
Addict
Addict
Posts: 1503
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: spinblur clock

Post by Kiffi »

firace wrote: Wed Nov 01, 2023 7:17 pm BTW Is anyone able to get a screenshot of the spinning effect ? I can't :)
At your service
Hygge
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: spinblur clock

Post by firace »

Kiffi wrote: Wed Nov 01, 2023 11:03 pm
firace wrote: Wed Nov 01, 2023 7:17 pm BTW Is anyone able to get a screenshot of the spinning effect ? I can't :)
At your service
Thanks!
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: spinblur clock

Post by firace »

Made a few tweaks to have it work under Linux
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: spinblur clock

Post by BarryG »

@Miso, Your version doesn't fade the numbers, so they all just become a blurred circle:

Image
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: spinblur clock

Post by miso »

@BarryG
Yes, I did not know what should I see. With the base OpenGL the first version was pitch black, with the change a saw something. Looks like the OpenGL behaves much different...

With extra ClearScreen()s, thats the closest I can get, but this should work with OpenGL subsystem.
Edit: looks like the first version has also been updated, to be OK with OpenGL.

Code: Select all

InitSprite() :  W=750 : H=540  : C = $324F72 : Cellsize = 50 : LoadFont(99, "Consolas", 36)

OpenWindow(0, 35, 35, W+1, H, "firace's spinblur clock", #PB_Window_SizeGadget|#PB_Window_SystemMenu)

OpenWindowedScreen(WindowID(0),0,0,W+1,H,1,0,0)  : AddWindowTimer(0, 1, 1000)


Repeat 
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow :   Break
    Case #PB_Event_Timer :
      
      ClearScreen(0) 
      ;If IsSprite(33) : FreeSprite(33) :EndIf
      CreateSprite(33, W+200,W+200) 
      
      StartDrawing(SpriteOutput(33)) 
      : DrawingFont(FontID(99))
      
      
      a = 350  
      b = 350   
      
      sec$ = FormatDate("%hh:%ii:%ss", Date())
      ;DrawingMode(#PB_2DDrawing_Transparent)
      DrawRotatedText(a+3,b+3,Sec$,0) 
      
      StopDrawing()  
      TransparentSpriteColor(33,0)
      x = 0 
      Repeat : x+1
        
        RotateSprite(33,  18,#PB_Relative) : DisplayTransparentSprite(33,-90,-140,42) 
        FlipBuffers()
      ClearScreen(0)  
      Until x = 20
      
      DisplayTransparentSprite(33,-90,-140,242)
      FlipBuffers()
      
  EndSelect
ForEver
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: spinblur clock

Post by Mijikai »

Nice (works fine for me on PB x64 6.03)
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: spinblur clock

Post by firace »

Mijikai wrote: Thu Nov 02, 2023 5:11 pm Nice (works fine for me on PB x64 6.03)
Thanks!

By the way I'm trying to convert it to SpiderBasic, but there are still some hurdles to resolve, as I'm not that familiar with SpiderBasic.
In case anyone from this topic wants to try it out and "fix" it... :)
Post Reply