On this page:
1.1 Big bang
big-bang
name
on-tick
on-key
on-release
on-mouse
to-draw
tick-rate
stop-when
check-with
record?
state
1.2 Universe
universe
on-new
on-msg
on-disconnect
to-string
5.92

 (require class/universe) package: base

procedure

(big-bang obj)  World

  obj : World
An object-oriented version of big-bang.

The given world object should provide some of the methods descibed below. For any methods that are not provided, DrRacket will use a default behavior. The world must at least provide a to-draw method.

Here is an example world program that counts up from zero:

#lang class/0
(require class/universe)
(require 2htdp/image)
 
(define-class counter-world%
  (fields n)
 
  (define (on-tick)
    (new counter-world% (add1 (send this n))))
 
  (define (tick-rate)
    1)
 
  (define (to-draw)
    (overlay (text (number->string (send this n))
                   40
                   "red")
             (empty-scene 300 100))))
 
(big-bang (new counter-world% 0))

syntax

(send a-world name)

Produces the name of the world.

syntax

(send a-world on-tick)

Tick this world, producing a world.

syntax

(send a-world on-key key)

 
  key : key-event?
Handle the keystroke key, producing a world.

syntax

(send a-world on-release key)

 
  key : key-event?
Handle the key release key, producing a world.

syntax

(send a-world on-mouse x y m)

 
  x : integer?
  y : integer?
  m : mouse-event?
Handle the mouse event m at location (x,y), producing a world.

syntax

(send a-world to-draw)

Draw this world, producing an image.

syntax

(send a-world tick-rate)

Produce the rate at which the clock should tick for this world.

syntax

(send a-world stop-when)

If this method produces true, the world program is shut down.

syntax

(send a-world check-with)

If this method produces true, the world is considered a valid world; otherwise the world program signals an error.

syntax

(send a-world record?)

If this method produces true for the initial world, DrRacket enables a visual replay of the interaction.

syntax

(send a-world state)

If this method produces true for the initial world, DrRacket displays a seperate window in which the current state is rendered.

procedure

(universe obj)  Universe

  obj : Universe
An object-oriented version of universe.

The given universe object should provide some of the methods descibed below. For any methods that are not provided, DrRacket will use a default behavior. The universe must at least provide a on-new and on-msg method.

syntax

(send a-universe on-new iw)

 
  iw : iworld?
Signal that the given new world has joined the universe, producing a bundle.

syntax

(send a-universe on-msg iw msg)

 
  iw : iworld?
  msg : sexp?
Signal that the given world has sent the given message to the universe, producing a bundle.

syntax

(send a-universe on-tick)

Tick this universe, producing a bundle.

syntax

(send a-universe tick-rate)

Produce the rate at which the clock should tick for this universe.

syntax

(send a-universe on-disconnect iw)

 
  iw : iworld?
Signal that the given world has left the universe, producing a bundle.

syntax

(send a-universe check-with)

If this method produces true, the universe is considered a valid universe; otherwise the universe program signals an error.

syntax

(send a-universe to-string)

Produce a string representation of the universe.

syntax

(send a-universe state)

If this method produces true for the initial universe, DrRacket displays a seperate window in which the current state is rendered.