Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,40 @@
#lang racket/gui
;; One of 'left or 'right
(define direction 'left)
;; Set up the GUI
(define animation-frame%
(class frame%
(super-new [label "Animation"])
;; reverse direction on a click
(define/override (on-subwindow-event win evt)
(when (send evt button-down?)
(set! direction
(if (eq? direction 'left)
'right
'left))))))
(define frame (new animation-frame%))
(define msg (new message%
[label "Hello World! "]
[parent frame]))
;; Timer callback to adjust the message
(define (callback)
(define old-label (send msg get-label))
(define len (string-length old-label))
(if (eq? direction 'left)
(send msg set-label
(string-append (substring old-label 1)
(substring old-label 0 1)))
(send msg set-label
(string-append (substring old-label (- len 1) len)
(substring old-label 0 (- len 1))))))
;; Set a timer and go
(define timer (new timer%
[notify-callback callback]
[interval 500]))
(send frame show #t)

View file

@ -0,0 +1,42 @@
#lang racket
(require racket/match)
(require 2htdp/image)
(require 2htdp/universe)
; program state
; value -> no. of rotations of string
; step -> number (positive for right rotations, else negative)
(struct rotations (value step) #:transparent)
(define STR "Hello World! ")
(define LEN (string-length STR))
; font
(define COLOR "red")
(define TEXT-SIZE 16) ;; pixels
(define (render rots)
(define val (rotations-value rots))
(text (string-append (substring STR val)
(substring STR 0 val))
TEXT-SIZE
COLOR))
(define (update rots)
(match rots
[(rotations val dir)
(rotations (modulo (+ val dir) LEN) dir)]))
; reverse direction on mouse click
(define (handle-mouse rots x y event)
(case event
; "button-up" indicates mouse click
[("button-up") (rotations (rotations-value rots)
(- (rotations-step rots)))]
[else rots]))
; start GUI, with given event handlers
(big-bang (rotations 0 1)
[to-draw render]
[on-tick update]
[on-mouse handle-mouse])