6.2.901.900
typed-big-bang
source code: https://github.com/AlexKnauth/typed-big-bang
1 typed/big-bang
(require typed/big-bang) | package: typed-big-bang |
see also typed/2htdp/universe
procedure
(big-bang init-state world? [ #:on-tick tick #:tick-rate rate #:tick-limit limit #:on-key handle-key #:on-pad handle-pad #:on-release handle-release #:on-mouse handle-mouse #:to-draw render #:width width #:height height #:stop-when last-world? #:name name #:on-key/key-event% handle-key-event% #:on-mouse/mouse-event% handle-mouse-event%]) → World init-state : World world? : [Any -> Boolean : World] tick : (TickHandler World) = identity rate : Positive-Real = 30 limit : (U Natural +inf.0) = +inf.0 handle-key : (KeyHandler World) = (λ ....) handle-pad : (PadHandler World) = #f handle-release : (KeyHandler World) = (λ ....) handle-mouse : (MouseHandler World) = (λ ....) render : (Renderer World) = (λ ....) width : (U Natural #f) = #f height : (U Natural #f) = #f last-world? : [World -> (U Boolean Image)] = (λ ....) name : (U Symbol String) = "World"
handle-key-event% : [World (Instance Key-Event%) -> (HandlerResult World)] = (λ ....)
handle-mouse-event% : [World (Instance Mouse-Event%) -> (HandlerResult World)] = (λ ....)
a function that bahaves like big-bang from 2htdp/universe.
An example world program:
#lang typed/racket (require typed/big-bang typed/2htdp/image) (define-type World Integer) (: main : [World -> World]) (define (main t) ((inst big-bang World) t exact-integer? #:on-tick add1 #:to-draw render #:stop-when (λ ([t : Integer]) (<= 10000 t)) #:on-key (λ ([t : Integer] [key : KeyEvent]) (cond [(key=? key "+") (+ 1000 t)] [else t])) #:on-release (λ ([t : Integer] [key : KeyEvent]) (- t 100)) #:on-mouse (λ ([t : Integer] [x : Integer] [y : Integer] [me : MouseEvent]) (- t 2)))) (: render : [World -> Image]) (define (render t) (overlay (text (number->string t) 36 "black") (empty-scene 200 200))) (main 0)
type
(TickHandler World)
type
(Renderer World)
type
(KeyHandler World)
type
(PadHandler World)
type
(MouseHandler World)
type
(HandlerResult World)
type
the type for a key event, corrosponding to KeyEvents from 2htdp/universe
type
the type for a mouse event, corrosponding to MouseEvents from 2htdp/universe
type
the type for a pad event, corrosponding to PadEvents from 2htdp/universe
a struct to tell big bang to stop the world with the final state w.
procedure
(key-event? v) → Boolean
v : Any
returns #t if the given KeyEvents are equal.
procedure
(pad-event? v) → Boolear
v : Any
returns #t if the given PadEvents are equal.
procedure
(mouse-event? v) → Boolean
v : Any
procedure
x : MouseEvent y : MouseEvent
returns #t if the given MouseEvents are equal.
2 typed/2htdp/image
(require typed/2htdp/image) | package: 2htdp-typed |
provides types for some functions from 2htdp/image.
type
the type for images from 2htdp/image
type
a color
procedure
(image-width img) → Natural
img : Image
returns the width of img
procedure
(image-height img) → Natural
img : Image
returns the height of img
procedure
(empty-scene width height) → Image
width : Natural height : Natural
returns an empty scene with the given width and height
overlays i1 on top of i2, and so on.
procedure
str : String size : Natural color : Image-Color
returns an image that draws str.