diff --git a/collects/teachpack/htdc/Docs/colors.thtml b/collects/teachpack/htdc/Docs/colors.scrbl similarity index 66% rename from collects/teachpack/htdc/Docs/colors.thtml rename to collects/teachpack/htdc/Docs/colors.scrbl index 48dc8a31e8..2000f72c18 100644 --- a/collects/teachpack/htdc/Docs/colors.thtml +++ b/collects/teachpack/htdc/Docs/colors.scrbl @@ -1,17 +1,17 @@ -{ (define LIBNAME "A Colors Library (HtDC)") - (include "head.tinc") } +#lang scribble/doc -

Add -


+@(require scribble/manual)
+
+@title[#:tag "colors"]{Colors: colors.*}
+
+Add 
+@verbatim[#:indent 3]{
   import colors.*
-
+} at the top of your Definitions Window to import this library. -

- -

This draw package provides classes for representing colors: -

-
+This package provides classes for representing colors: 
+@verbatim[#:indent 3]{
                               +--------+
                               | IColor |
                               +--------+
@@ -24,12 +24,6 @@ at the top of your Definitions Window to import this library.
          +-------+  +-------+ +-------+ +-------+ +-------+  +-------+ 
          | Blue  |  | Green | | Red   | | White | | Yellow|  | Black | 
          +-------+  +-------+ +-------+ +-------+ +-------+  +-------+ 
-
-
-

+} -

The IColor class is abstract. Its variants (subclasses) are -created with no arguments. -

- -{(include "foot.tinc")} +@deftech{IColor} is an interface. Its variants are created with no arguments. diff --git a/collects/teachpack/htdc/Docs/draw.scrbl b/collects/teachpack/htdc/Docs/draw.scrbl new file mode 100644 index 0000000000..880cc1b066 --- /dev/null +++ b/collects/teachpack/htdc/Docs/draw.scrbl @@ -0,0 +1,160 @@ +#lang scribble/doc + +@(require scribble/manual) + +@title[#:tag "draw"]{Draw: draw.*} + +Add +@verbatim[#:indent 3]{ + import draw.* +} +at the top of your Definitions Window to import this library. + +This package provides classes and methods for a visual +world. Here is its class diagram of public fields and methods: +@verbatim[#:indent 3]{ +import colors.*; +import geometry.*; + + +-----------------------------------+ + | abstract World | + +-----------------------------------+ +---------------------------------------+ + | Canvas theCanvas |------>| Canvas | + +-----------------------------------+ +---------------------------------------+ + | boolean bigBang(int,int,double) | +---------------------------------------+ + | boolean endOfTime(String) | | boolean show() | + | World endOfWorld(String) | | boolean close() | + | | | boolean drawCircle(Posn,int,IColor) | + | | | boolean drawDisk(Posn,int,IColor) | + | abstract World onTick() | | boolean drawRect(Posn,int,int,IColor) | + | abstract World onKeyEvent(String) | | boolean drawLine(Posn,Posn,IColor) | + | abstract boolean draw() | | boolean drawString(Posn,String) | + +-----------------------------------+ +---------------------------------------+ +} + +Methods in these classes may fail due to the unavailability of the physical +devices, inappropriate uses, etc. In those cases, they fail with an +exception. + +@section[#:tag "world"]{World} + +The abstract @scheme[World] class exports the following methods. + +@; ----------------------------------------------------------------------------- +bigBang(int width,int height,double speed) + +Initializes the world, associates it with a @scheme[width] x +@scheme[height] @scheme[Canvas], displays +this canvas, enables keyevents, and finally starts the clock at a rate of +one tick per @scheme[speed] seconds. If it succeeds with all of its +actions, the method produces @scheme[true]. + +@bold{Note}: @scheme[width], @scheme[height] and +@scheme[speed] must be a positive. + +@; ----------------------------------------------------------------------------- +The canvas in @scheme[World] is called + + @scheme[theCanvas]. + +References to a "canvas" in conjunction with the @scheme[World] class + denote this default canvas. + +@; ----------------------------------------------------------------------------- +endOfTime() + +Displays the given message, stops the clock and, if it succeeds, produces +@scheme[true]. After the end of time, events no longer trigger calls +to @scheme[onTick] or @scheme[onKeyEvent]. The canvas remains visible. + +@; ----------------------------------------------------------------------------- +endOfWorld(String msg) + +Displays the given message, stops the clock and, if it succeeds, produces the +last @scheme[World]. After the end of the world, events no longer trigger calls +to @scheme[onTick] or @scheme[onKeyEvent] (see below). The canvas +remains visible. + +@; ----------------------------------------------------------------------------- +A derived concrete class must supply definitions for the following methods: + +@; ----------------------------------------------------------------------------- +onTick() + +Invoked for every tick of the clock. Its purpose is to create a +@scheme[World] whose differences with @scheme[this] one represent +what happened during the amount of time it takes the clock to tick. + +@; ----------------------------------------------------------------------------- +onKeyEvent(String key) + +Invoked for every keyboard event associated with the canvas. Its purposes + is to create a @scheme[World] whose differences with + @scheme[this] one represent what happens due to the user's use of the + keyboard. The latter is represented with the string-valued argument + @scheme[key]. + +@; ----------------------------------------------------------------------------- +draw() + +Invoked after one of the two event handlers has been called. Its +purpose is to present @scheme[this World ] graphically on its +canvas. If it succeeds, its result is @scheme[true.] + +A program may, in principle, start several instances of (subclasses of) +@scheme[World]. If it does, the event handlers are called in a unpredictable +order. + +@section[#:tag "canvas"]{Canvas} + +To create an instance of the @scheme[Canvas] class, a program must supply +two @scheme[int] values: one for the width of the canvas and one for its +height. The canvas is a rectangle, whose borders are parallel to the computer +screen's borders. A program can use the following methods on instances of +@scheme[Canvas:] + +show() + +Initializes the canvas to a white area, enables the drawing methods, and + finally displays the canvas. If it succeeds, it produces + @scheme[true]. Invoking the method a second time without calling + @scheme[close] before has no effect. + +close() + +Hides the canvas and erases the current content. If it succeeds, it +produces @scheme[true]. + +Closing the Canvas using the display controls does not fully hide the +canvas; it is still necessary to invoke @scheme[close] before +@scheme[show] is re-enabled. + +drawCircle(Posn p,int r,IColor c)> + +Draws a circle on @scheme[this Canvas] at @scheme[p] with radius +@scheme[r] and color @scheme[c]. If it succeeds, it produces +@scheme[true]. + +drawDisk(Posn p,int r,IColor c) + +Draws a disk on @scheme[this Canvas] at @scheme[p] with radius +@scheme[r] and color @scheme[c]. If it succeeds, it produces +@scheme[true]. + +drawRect(Posn p,int w,int h,IColor c) + +Draws a solid rectangle on @scheme[this Canvas] at @scheme[p] with +width @scheme[w], height @scheme[h], and color @scheme[c]. The +rectangle's lines are parallel to the canvas's borders. If it succeeds, it +produces @scheme[true]. + +drawLine(Posn p0,Posn p1,IColor c) + +Draws a line on @scheme[this Canvas] from @scheme[p0] to +@scheme[p1] using color @scheme[c]. If it succeeds, it produces +@scheme[true]. + +drawString(Posn p,String s) + +Draws the string @scheme[s] at @scheme[p] on @scheme[this +Canvas]. If it succeeds, it produces @scheme[true]. diff --git a/collects/teachpack/htdc/Docs/draw.thtml b/collects/teachpack/htdc/Docs/draw.thtml deleted file mode 100644 index ee5bbd3053..0000000000 --- a/collects/teachpack/htdc/Docs/draw.thtml +++ /dev/null @@ -1,147 +0,0 @@ -{ (define LIBNAME "A Functional Drawing Library (HtDC)") - (include "head.tinc") } - -

Add -


-  import draw.*
-
-at the top of your Definitions Window to import this library. -

- -

-This draw package provides classes and methods for a visual -world. Here is its class diagram of public fields and methods: -

-
-import colors.*;
-import geometry.*;
-
- +-----------------------------------+
- | abstract World                    |
- +-----------------------------------+       +---------------------------------------+
- | Canvas theCanvas                  |------>| Canvas                                |
- +-----------------------------------+       +---------------------------------------+
- | boolean bigBang(int,int,double)   |       +---------------------------------------+
- | boolean endOfTime(String)         |       | boolean show()                        |
- | World endOfWorld(String)          |       | boolean close()                       |
- |                                   |       | boolean drawCircle(Posn,int,IColor)   |
- |                                   |       | boolean drawDisk(Posn,int,IColor)     |
- | abstract World onTick()           |       | boolean drawRect(Posn,int,int,IColor) |
- | abstract World onKeyEvent(String) |       | boolean drawLine(Posn,Posn,IColor)    |
- | abstract boolean draw()           |       | boolean drawString(Posn,String)       |
- +-----------------------------------+       +---------------------------------------+
-
-
-

- - -

The abstract World class exports the following methods: -

-The methods may fail due to the unavailability of the physical devices, -inappropriate uses, etc. In those cases, they fail with an exception.

- -

A derived concrete class must supply definitions for the following methods: -

-A program may, in principle, start several instances of (subclasses of) -World. If it does, the event handlers are called in a unpredictable -order.

- - -

To create an instance of the Canvas class, a program must supply -two int values: one for the width of the canvas and one for its -height. The canvas is a rectangle, whose borders are parallel to the computer -screen's borders. A program can use the following methods on instances of -Canvas: -

-The methods may fail due to the unavailability of the physical devices, -inappropriate uses, etc. In those cases, they fail with an exception.

-

- -{(include "foot.tinc")} diff --git a/collects/teachpack/htdc/Docs/geometry.scrbl b/collects/teachpack/htdc/Docs/geometry.scrbl new file mode 100644 index 0000000000..97e82a52eb --- /dev/null +++ b/collects/teachpack/htdc/Docs/geometry.scrbl @@ -0,0 +1,24 @@ +#lang scribble/doc + +@(require scribble/manual) + +@title[#:tag "geometry"]{Geometry: geometry.*} + +Add +@verbatim[#:indent 3]{ + import geometry.* +} +at the top of your Definitions Window to import this library. + +This package provides a class for representing positions in a Cartesian world: +@verbatim[#:indent 3]{ + +----------+ + | Posn | + +----------+ + | int x | + | int y | + +----------+ +} + +@deftech{Posn} is a class with two fields, one per coordinate. The +constructor consumes two integers. diff --git a/collects/teachpack/htdc/Docs/geometry.thtml b/collects/teachpack/htdc/Docs/geometry.thtml deleted file mode 100644 index 8995ccb86d..0000000000 --- a/collects/teachpack/htdc/Docs/geometry.thtml +++ /dev/null @@ -1,29 +0,0 @@ -{ (define LIBNAME "A Geometry Library (HtDC)") - (include "head.tinc") } - -

Add -


-  import geometry.*
-
-at the top of your Definitions Window to import this library. -

- -

This geometry package provides a class for representing -positions in a Cartesian world: -

-
-                      +----------+
-                      | Posn     |
-                      +----------+
-                      | int x    |
-                      | int y    |
-                      +----------+
-
-
-

- -

To create an instance of the Posn class, a program must supply -two int values: one for its x coordinate of the canvas and the -second for its y coordinate.

- -{(include "foot.tinc")} diff --git a/collects/teachpack/htdc/Docs/htdc.scrbl b/collects/teachpack/htdc/Docs/htdc.scrbl index a542ca6fcf..cf9779723b 100644 --- a/collects/teachpack/htdc/Docs/htdc.scrbl +++ b/collects/teachpack/htdc/Docs/htdc.scrbl @@ -7,7 +7,7 @@ @local-table-of-contents[] -@;include-section["draw.scrbl"] @;"A Functional Drawing Library (HtDC)" +@include-section["draw.scrbl"] @;"A Functional Drawing Library (HtDC)" @;include-section["idraw.scrbl"] @;"An Imperative Drawing Library (HtDC)" -@;include-section["geometry.scrbl"] @;"A Geometry Library (HtDC)" -@;include-section["colors.scrbl"] @;"A Colors Library (HtDC)" +@include-section["geometry.scrbl"] @;"A Geometry Library (HtDC)" +@include-section["colors.scrbl"] @;"A Colors Library (HtDC)"