Skip to content

Instantly share code, notes, and snippets.

@fbanados
Last active December 2, 2019 23:42
Show Gist options
  • Save fbanados/142dda3cd78fc2ce36f389b7a24fd0f8 to your computer and use it in GitHub Desktop.
Save fbanados/142dda3cd78fc2ce36f389b7a24fd0f8 to your computer and use it in GitHub Desktop.
#lang slideshow
(require slideshow/play)
(provide timer-slide)
(module stopwatch racket
(provide (all-defined-out))
(define time? number?)
(define (seconds n) n)
(define (minutes n) (* 60 n))
(define (hours n) (* 3600 n))
(define (time->hhmmss x)
(values (quotient x 3600)
(quotient (remainder x 3600) 60)
(remainder x 60)))
(define (time->string x)
(let-values ([(hh mm ss) (time->hhmmss x)])
(apply format "~a : ~a : ~a"
(map (λ (x) (if (< (string-length x) 2)
(string-append "0" x)
x))
(map number->string (list hh mm ss)))))))
(require 'stopwatch)
(set-page-numbers-visible! false)
(define (stopwatch time)
(local ([define current-time (box time)])
(λ ()
(let ([old-time (unbox current-time)])
(if (zero? old-time)
old-time
(begin
(set-box! current-time (- old-time (seconds 1)))
old-time))))))
(define (time->pict period)
(text period
"Source Code Pro" 140))
(define (timer-slide #:title [msg ""] #:pict [pict time->pict] time)
(let ([current-time (stopwatch time)])
(play
#:steps time
#:delay 1
#:title msg
(λ (_)
(pict (time->string (current-time)))))))
(timer-slide #:title "Exam Time"
(+ (hours 2)
(minutes 30)
(seconds 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment