AtlatestRepositorysigil-studio
sigil-studio / tree / exampleshello-window.sgl
1
;;; hello-window.sgl - Minimal Sigil Studio Example2
;;;3
;;; Opens a window and clears it to a cycling color.4
;;; Demonstrates the coroutine-based game loop where Scheme owns the main loop.6
(import (sigil app)7
(sigil graphics)8
(sigil math))10
;; Simple color cycling using sine waves11
(define (get-color t)12
;; Returns a list of (r g b) using offset sine waves13
(let ((r (+ 0.5 (* 0.5 (sin t))))14
(g (+ 0.5 (* 0.5 (sin (+ t 2.094))))) ; offset by 2*pi/315
(b (+ 0.5 (* 0.5 (sin (+ t 4.189)))))) ; offset by 4*pi/316
(list r g b)))18
;; Run the game using cooperative frame scheduling19
(run-game "Hello Sigil Studio" 800 60020
(lambda ()21
;; Initialization22
(gfx-setup)23
(display "Hello, Sigil Studio!")24
(newline)26
;; Main loop - Scheme owns this!27
(let loop ((time 0.0))28
(let ((dt (wait-frame))) ; Yield to C, get delta time29
;; Update time30
(let ((new-time (+ time dt)))31
;; Get cycling color and render32
(begin-frame)33
(let ((color (get-color new-time)))34
(clear-screen (car color) (cadr color) (caddr color)))35
(end-frame)37
;; Continue unless quit requested38
(if (key-pressed? 'escape)39
(begin40
(display "Goodbye!")41
(newline)42
(gfx-shutdown))43
(loop new-time)))))))