AtlatestRepositorysigil-studio

sigil-studio / tree / exampleshello-window.sgl

1;;; hello-window.sgl - Minimal Sigil Studio Example
2;;;
3;;; Opens a window and clears it to a cycling color.
4;;; Demonstrates the coroutine-based game loop where Scheme owns the main loop.
5
6(import (sigil app)
7 (sigil graphics)
8 (sigil math))
9
10;; Simple color cycling using sine waves
11(define (get-color t)
12 ;; Returns a list of (r g b) using offset sine waves
13 (let ((r (+ 0.5 (* 0.5 (sin t))))
14 (g (+ 0.5 (* 0.5 (sin (+ t 2.094))))) ; offset by 2*pi/3
15 (b (+ 0.5 (* 0.5 (sin (+ t 4.189)))))) ; offset by 4*pi/3
16 (list r g b)))
18;; Run the game using cooperative frame scheduling
19(run-game "Hello Sigil Studio" 800 600
20 (lambda ()
21 ;; Initialization
22 (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 time
29 ;; Update time
30 (let ((new-time (+ time dt)))
31 ;; Get cycling color and render
32 (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 requested
38 (if (key-pressed? 'escape)
39 (begin
40 (display "Goodbye!")
41 (newline)
42 (gfx-shutdown))
43 (loop new-time)))))))