' Screensaver sample with FreeBASIC. use FB_ScreenSaverKit.bas ' ' fork FreeBASIC Screensaver Kit ' https://www.freebasic.net/forum/viewtopic.php?t=25235 ' ' Windows10 x64 22H2 + FreeBASIC 1.10.1 32bit ' ssfbscrsample3.bas ... License CC0 / Public Domain ' by mieki256 ' Last updated: <2024/02/02 08:15:11 +0900> #include "fb_screensaverkit.bas" ' use mmsystem #include "windows.bi" #include "win/mmsystem.bi" ' global work Type wk scrw As Integer scrh As Integer x As Double y As Double dx As Double dy As Double r As Double max_fps As Double End Type Dim Shared wk As wk '-------------------- ' Initialize work Sub InitProc() ' get screen size. width and height ' ScreenInfo scrw, scrh wk.scrw = SaverInfo.ScrWidth wk.scrh = SaverInfo.ScrHeight wk.max_fps = SaverInfo.max_fps wk.x = wk.scrw / 2.0 wk.y = wk.scrh / 2.0 wk.dx = (CDbl(wk.scrw) / wk.max_fps) * 0.6 wk.dy = (CDbl(wk.scrh) / wk.max_fps) * 0.4 wk.r = wk.scrh / 16.0 ' timeBeginPeriod(1) End Sub '-------------------- ' Rendering Sub Render(ByVal delta As Double) If delta >= 1.0 Then delta = 1.0 / wk.max_fps ' move ball position wk.x += (wk.dx * wk.max_fps * delta) wk.y += (wk.dy * wk.max_fps * delta) If (wk.x <= wk.r And wk.dx < 0) Or (wk.x >= (wk.scrw - wk.r) And wk.dx > 0) Then wk.dx *= -1.0 If (wk.y <= wk.r And wk.dy < 0) Or (wk.y >= (wk.scrh - wk.r) And wk.dy > 0) Then wk.dy *= -1.0 ' draw start ' clear screen ' Line (0, 0)-(scrw, scrh), Rgb(0, 0, 0), BF color RGB(0, 0, 0), RGB(0, 0, 0) cls ' draw ball circle (wk.x, wk.y), wk.r, RGB(255, 0, 0), , , , F ' Get and draw FPS Dim As String fpstext = Str(SaverInfo.fps) & "FPS" Draw String ((wk.scrw - Len(fpstext) * 8) / 2, 10), fpstext, RGB(255, 255, 255) fpstext = "" ' destroying a string ' draw end End Sub '-------------------- ' End process Sub ExitProc() ' timeEndPeriod(1) End Sub ' -------------------- ' main routine Randomize Timer 'Start the Screen Saver. Set timer XX sec StartScreenSaver(14) ' Wait until the screensaver ends Do Until SaverInfo.IsClosing = True sleep 10 Loop