' Screensaver sample with FreeBASIC. use FB_ScreenSaverKit.bas ' ' freeBASIC Screensaver Kit Updated - freebasic.net ' https://www.freebasic.net/forum/viewtopic.php?t=25235 ' ' Windows10 x64 22H2 + FreeBASIC 1.10.1 ' ssfbscrsample.bas ... License CC0 / Public Domain ' by mieki256 ' Last updated: <2024/02/01 20:34:03 +0900> #include "fb_screensaverkit.bas" ' use mmsystem #include "windows.bi" #include "win/mmsystem.bi" timeBeginPeriod(1) Randomize Timer Const MAX_FPS = 60.0 Const PI = 3.141592653 Dim As Double start_time, prev_time, now_time, next_time, delta, one_frame Dim As Integer frame_count Dim As String fps_text = "FPS" Dim As Integer sw, sh 'Start the Screen Saver StartScreenSaver #If 1 ' get screen size. width and height ScreenInfo sw, sh #Else 'You can also find the width & height of the screen by using SaverInfo.ScrWidth & SaverInfo.ScrHeight sw = SaverInfo.ScrWidth sh = SaverInfo.ScrHeight #Endif ' init work Dim As Double x, y, dx, dy, r x = sw / 2.0 y = sh / 2.0 dx = (CDbl(sw) / MAX_FPS) * 0.6 dy = (CDbl(sh) / MAX_FPS) * 0.4 r = sh / 16.0 start_time = Timer prev_time = start_time frame_count = 0 ' main loop Do Until SaverInfo.IsClosing = True ' get delta now_time = Timer delta = now_time - prev_time prev_time = now_time next_time = now_time + (1.0 / MAX_FPS) If delta < 0 Then delta = 1.0 / MAX_FPS ' count FPS If now_time >= start_time Then If (now_time - start_time) >= 1.0 Then fps_text = Str(frame_count) & " FPS" start_time += 1.0 frame_count = 0 End If Else start_time = now_time End If frame_count += 1 ' move ball position x += (dx * MAX_FPS * delta) y += (dy * MAX_FPS * delta) If (x <= (r / 2) And dx < 0) Or (x >= (sw - (r / 2)) And dx > 0) Then dx *= -1.0 If (y <= (r / 2) And dy < 0) Or (y >= (sh - (r / 2)) And dy > 0) Then dy *= -1.0 If SaverInfo.IsClosing <> True Then ' draw start ' ScreenLock ' clear screen ' Line (0, 0)-(sw, sh), Rgb(0, 0, 0), BF color RGB(0, 0, 0), RGB(0, 0, 0) cls ' draw ball circle (x, y), r, RGB(255, 0, 0), , , , F ' darw FPS Draw String ((sw - Len(fps_text) * 8) / 2, 10), fps_text, RGB(255, 255, 255) ' draw end ' ScreenUnlock End If ' sleep If Timer < next_time Then Dim As Double wait_time = (next_time - Timer) * 1000.0 If wait_time > 0 Then sleep wait_time End If End If Loop timeEndPeriod(1)