Prerequirements

If you dont have project set up with Spite then see installation.

Hello world

Make new file called main.scm with this content:

(import (scheme base)
        (scheme write)
        (retropikzel spite v0-3-6 main))

(spite-init "Hello Spite" 400 400)

(define update
    (lambda (delta-time events)
      (when (> (vector-length events) 0)
        (write events)
        (newline))))

(define draw
    (lambda ()
    #t))

(spite-start update draw)

Remember to check that the vN-N-N matches the Spite version you have installed.

Then run it with one of these:

Guile:

guile -L ./schubert main.scm

Sagittarius:

sash -L ./schubert main.scm

If everything went okay a window should appear and in the terminal you should see the list of events as you move the mouse, click and press keys.

Reacting to events

Update then update procedure to look like this:

(define update
  (lambda (delta-time events)
    (when (> (vector-length events) 0)
      (vector-for-each
        (lambda (event)
          (when (and (equal? (event-type-get event) 'key-down)
                     (string=? (cdr (assoc 'key (event-data-get event))) "Space"))
            (display "Hello world!")
            (newline)))
        events))))

After the changes you should see text "Hello world" appear whenever you press space

Drawing images

For the image we will be using the rainbow lambda logo made by ramin_hal9001.

Download the image from here and place it in the same directory as main.scm.

Then update the code to have new line after the line with spite init, that looks like this:

(define rainbow-lambda-logo (spite-image-load "rainbow-lambda-logo.png"))

and update the draw function to look like this:

(define draw
  (lambda ()
    (spite-image-draw rainbow-lambda-logo 100 100 32 32)))

Now run the script again and a beautifull rainbow lambda should appear, well done! :)