Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
40
Task/Animation/Racket/animation-1.rkt
Normal file
40
Task/Animation/Racket/animation-1.rkt
Normal 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)
|
||||
42
Task/Animation/Racket/animation-2.rkt
Normal file
42
Task/Animation/Racket/animation-2.rkt
Normal 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])
|
||||
Loading…
Add table
Add a link
Reference in a new issue