svn: r9446
This commit is contained in:
parent
3db855fab1
commit
65467c8483
|
@ -1,17 +1,17 @@
|
|||
{ (define LIBNAME "A Colors Library (HtDC)")
|
||||
(include "head.tinc") }
|
||||
#lang scribble/doc
|
||||
|
||||
<p>Add
|
||||
<pre><code>
|
||||
@(require scribble/manual)
|
||||
|
||||
@title[#:tag "colors"]{Colors: colors.*}
|
||||
|
||||
Add
|
||||
@verbatim[#:indent 3]{
|
||||
import colors.*
|
||||
</code></pre>
|
||||
}
|
||||
at the top of your Definitions Window to import this library.
|
||||
</p>
|
||||
|
||||
|
||||
<p>This <code>draw</code> package provides classes for representing colors:
|
||||
<pre>
|
||||
<code>
|
||||
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 |
|
||||
+-------+ +-------+ +-------+ +-------+ +-------+ +-------+
|
||||
</code>
|
||||
</pre>
|
||||
</p>
|
||||
}
|
||||
|
||||
<p>The <code>IColor</code> class is abstract. Its variants (subclasses) are
|
||||
created with no arguments.
|
||||
</p>
|
||||
|
||||
{(include "foot.tinc")}
|
||||
@deftech{IColor} is an interface. Its variants are created with no arguments.
|
160
collects/teachpack/htdc/Docs/draw.scrbl
Normal file
160
collects/teachpack/htdc/Docs/draw.scrbl
Normal file
|
@ -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] <a href="#canvas">@scheme[Canvas]</a>, 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 <em>after</em> 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].
|
|
@ -1,147 +0,0 @@
|
|||
{ (define LIBNAME "A Functional Drawing Library (HtDC)")
|
||||
(include "head.tinc") }
|
||||
|
||||
<p>Add
|
||||
<pre><code>
|
||||
import draw.*
|
||||
</code></pre>
|
||||
at the top of your Definitions Window to import this library.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
This <code>draw</code> package provides classes and methods for a visual
|
||||
world. Here is its class diagram of public fields and methods:
|
||||
<pre>
|
||||
<code>
|
||||
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) |
|
||||
+-----------------------------------+ +---------------------------------------+
|
||||
</code>
|
||||
</pre>
|
||||
<p>
|
||||
|
||||
<a name="world" />
|
||||
<p>The abstract <code>World</code> class exports the following methods:
|
||||
<ul>
|
||||
|
||||
<li><code>bigBang(width,height,speed)</code>, which initializes the world,
|
||||
associates it with a <code>width</code> x <code>height</code> <a
|
||||
href="#canvas"><code>Canvas</code></a>, displays
|
||||
this canvas, enables keyevents, and finally starts the clock at a rate of one tick per
|
||||
<code>speed</code> seconds. If it succeeds with all of its actions, the method
|
||||
produces <code>true</code>.
|
||||
|
||||
<p><strong>Note:</strong> <code>width</code> and <code>height</code> must be
|
||||
positive <code>int</code>s, <code>speed</code> must be a positive
|
||||
<code>double</code>.
|
||||
</p>
|
||||
|
||||
<p>The canvas in <code>World</code> is called
|
||||
<code>theCanvas</code>. References to a "canvas" in conjunction with the
|
||||
<code>World</code> class denote this default canvas.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>endOfTime</code>, displays the given message, stops the clock and, if it succeeds, produces
|
||||
<code>true</code>. After the end of time, events no longer trigger calls
|
||||
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
|
||||
remains visible.
|
||||
</li>
|
||||
|
||||
<li><code>endOfWorld</code>, displays the given message, stops the clock and, if it succeeds, produces the
|
||||
last <code>World</code>. After the end of the world, events no longer trigger calls
|
||||
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
|
||||
remains visible.
|
||||
</li>
|
||||
</ul>
|
||||
The methods may fail due to the unavailability of the physical devices,
|
||||
inappropriate uses, etc. In those cases, they fail with an exception.</p>
|
||||
|
||||
<p>A derived concrete class must supply definitions for the following methods:
|
||||
<ul>
|
||||
<li><code>onTick()</code>, which is invoked for every tick of the clock. Its
|
||||
purpose is to create a <code>World</code> whose differences with
|
||||
<code>this</code> one represent what happened during the amount of time it takes
|
||||
the clock to tick.
|
||||
</li>
|
||||
|
||||
<li><code>onKeyEvent(key)</code>, which is invoked for every keyboard event
|
||||
associated with the canvas. Its purposes is to create a
|
||||
<code>World</code> whose differences with <code>this</code> one represent
|
||||
what happens due to the user's use of the keyboard. The latter is
|
||||
represented with the string-valued argument <code>key</code>.
|
||||
</li>
|
||||
|
||||
<li><code>draw()</code>, which is invoked <em>after</em> one of the two event
|
||||
handlers has been called. Its purpose is to present <code>this World </code>
|
||||
graphically on its canvas. If it succeeds, its result is <code>true.</code>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
A program may, in principle, start several instances of (subclasses of)
|
||||
<code>World</code>. If it does, the event handlers are called in a unpredictable
|
||||
order. </p>
|
||||
|
||||
<a name="canvas" />
|
||||
<p>To create an instance of the <code>Canvas</code> class, a program must supply
|
||||
two <code>int</code> 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
|
||||
<code>Canvas:</code>
|
||||
<ul>
|
||||
|
||||
<li><code>show()</code>, which initializes the canvas to a white area,
|
||||
enables the drawing methods, and finally displays the canvas. If it
|
||||
succeeds, it produces <code>true</code>. Invoking the method a second
|
||||
time without calling <code>close</code> before has no effect.
|
||||
</li>
|
||||
|
||||
<li><code>close()</code>, which hides the canvas and erases the current content.
|
||||
If it succeeds, it produces <code>true</code>.
|
||||
|
||||
<p>Closing the Canvas using the display controls does not fully hide the
|
||||
canvas; it is still necessary to invoke <code>close</code> before
|
||||
<code>show</code> is re-enabled.</p>
|
||||
</li>
|
||||
|
||||
<li><code>drawCircle(p,r,c)</code>, which draws a circle on <code>this
|
||||
Canvas</code> at <code>p</code> with radius <code>r</code> and color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawDisk(p,r,c)</code>, which draws a disk on
|
||||
<code>this Canvas</code> at <code>p</code> with radius <code>r</code> and color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawRect(p,w,h, c)</code>, which draws a solid rectangle on <code>this
|
||||
Canvas</code> at <code>p</code> with width <code>w</code>, height
|
||||
<code>h</code>, and color <code>c</code>. The rectangle's lines are parallel to
|
||||
the canvas's borders. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawLine(p0,p1,c)</code>, which draws a line on <code>this
|
||||
Canvas</code> from <code>p0</code> to <code>p1</code> using color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawString(p,s)</code>, which draws the string <code>s</code> at
|
||||
<code>p</code> on <code>this Canvas</code>. If it succeeds, it produces
|
||||
<code>true</code>.</li>
|
||||
|
||||
</ul>
|
||||
The methods may fail due to the unavailability of the physical devices,
|
||||
inappropriate uses, etc. In those cases, they fail with an exception.</p>
|
||||
</p>
|
||||
|
||||
{(include "foot.tinc")}
|
24
collects/teachpack/htdc/Docs/geometry.scrbl
Normal file
24
collects/teachpack/htdc/Docs/geometry.scrbl
Normal file
|
@ -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.
|
|
@ -1,29 +0,0 @@
|
|||
{ (define LIBNAME "A Geometry Library (HtDC)")
|
||||
(include "head.tinc") }
|
||||
|
||||
<p>Add
|
||||
<pre><code>
|
||||
import geometry.*
|
||||
</code></pre>
|
||||
at the top of your Definitions Window to import this library.
|
||||
</p>
|
||||
|
||||
<p>This <code>geometry</code> package provides a class for representing
|
||||
positions in a Cartesian world:
|
||||
<pre>
|
||||
<code>
|
||||
+----------+
|
||||
| Posn |
|
||||
+----------+
|
||||
| int x |
|
||||
| int y |
|
||||
+----------+
|
||||
</code>
|
||||
</pre>
|
||||
</p>
|
||||
|
||||
<p>To create an instance of the <code>Posn</code> class, a program must supply
|
||||
two <code>int</code> values: one for its x coordinate of the canvas and the
|
||||
second for its y coordinate. </p>
|
||||
|
||||
{(include "foot.tinc")}
|
|
@ -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)"
|
||||
|
|
Loading…
Reference in New Issue
Block a user