Tool authoring is done in Desktop Sketchpad (GSP). To create a tool, add a page to your GSP document, giving the new tool page a special name that instructs the WebSketchpad exporter to convert the page into a tool.
By default, tools are document-wide: If the document has multiple pages, the tools for that document will be accessible from every page.
When the user taps a WSP tool button, toolplay begins: The entire tool construction appears, with the givens highlighted and the productions faded. One given object glows to indicate that it’s the currently active given ready either to be matched to a sketch object or to be located in the sketch. The user can match the active given in any of these ways:
For tools with more than one given, you can choose to drag a different given instead of the currently active (glowing) given. Press and drag the given you want to match or plqce, and it immediately becomes the active given, allowing you to place it (by releasing in empty space) or to match it (by releasing on the desired object as described above).
You can use GSP to create a web page with three WSP tools by following the directions below.
This tool is similar to GSP’s Compass tool, constructing a circle based on two given points. (Unlike GSP, the WSP tool will show the full construction the moment you activate the tool, with the center point and radius point glowing in turn, to invite you to place or match them.)
Your tool will measure an angle, serving the same function as GSP’s
command. (Unlike GSP, the WSP tool will show the full construction immediately, with the three given points glowing in turn to designate the initial direction, the vertex, and the final direction of the angle.)This tool will measure the circumference of a circle, operating in either of two ways. It can be used directly to measure the circumference of an existing circle, or it can be used parentally to construct a new circle and measure its circumference.
This type of given object is called a constructible given because you can use it either to match an existing object or to construct a new object by constructing the required parents. (In this example, the required parents are a center point and a radius point. The parents of a constructible given are called given parents. The constructible given must be labeled
WSP tools perform constructions involving two kinds of objects: givens (the independent objects on which the construction depends) and productions (the constructed objects that are produced based on the givens).
WSP supports four different roles for given objects. For
Like a simple given, an assumed given must be an object that has no parents. Because it’s matched by label, it must have a label, and the sketch into which the tool is played must already have an object of the same kind and with the same label. The tool object’s label must begin with
If the sketch does not contain an object to match the assumed given, the assumed given is placed in the sketch, using the same location (if a point) or the same value (if a parameter) as it had in the page that defines the tool. (Such an automatically-placed object can be used as an assumed object during later use of the same, or a different, tool.)
If all givens for a tool are assumed, the tool is an auto-play tool and creates its productions instantly when the user taps the tool button.
Objects such as captions and pictures do not have labels, and thus cannot be assumed givens. A coordinate system is a special case, handled automatically as an assumed given. There’s no need to specify that a coordinate system is assumed.
If multiple objects in a sketch match the assumed given of a tool, the tool chooses the most recently-created of the matching objects. This makes it possible to create a tool that iterates by producing a new object with the same label as its assumed given. Each subsequent use of the tool will use as its assumed given the object just constructed by the previous use of that tool.
Refer to Tool Object Labels below for more options for labeling tool objects.
You can use constructible givens to create a variety of tools that require given objects that are not independent. Examples include a Length tool that measures the length of its given segment, a Circumference tool that measures the circumference of its given circle, or an Area tool that measures the area of its given polygon. Though the constructible given is not independent, each of its givenParents must be independent and must have no children other than the constructible given itself.
For example, to create a Circumference tool, you can
When a tool’s constructible given is matched to an existing sketch object, the tool object’s givenParents are automatically matched to the parents of the existing sketch object. For example, if a tool has a constructible circle whose givenParents are a center point and a radius point, and the tool’s circle is matched to an existing sketch circle that also has a can be a constructible given, provided that its givenParents (the center and radius points) have no other children. However, the perpendicular bisector of a segment cannot be a constructible given, because its parent object is a segment, which is not an independent object and cannot serve as a givenParent. The user can place or match a constructible directly (by placing or matching the constructible itself) or parentally (by placing or matching its givenParents).
To place or match the circle directly, the user (a) taps in empty space (thereby placing the constructible circle), or (b) taps an existing circle, or (c) drags the constructible circle to leave it in a new location or to match it to an existing circle.
To place or match the circle parentally, the user first drags one of the constructible’s parents to match or place that parent. This action switches the constructible from direct to parental mode, and each of the remaining givenParents will become active in turn.
After switching the constructible to parental mode, the user can still switch back to direct mode as long as long as one of the givenParents remains active.
Refer to Tool Object Labels below for more options for labeling tool objects.You can label constructibles and their givenParents as you would label other given objects. For instance, in a Reflect tool you might want to label the constructible as
Web Sketchpad allows the tool user to switch back and forth between direct and parental matching. The default is direct matching of the constructible, but if the tool user instead drags one of the constructible’s parents, the tool switches to parental matching. Even after the switch to parental matching, the tool user can drag the constructible itself to switch back to direct matching.
Refer to Tool Object Labels below for more options for labeling tool objects.
As you use a GSP page to define a WSP tool, note that the given objects of the resulting tool will include only independent objects whose role you have determined, either by providing the given object itself with a label that begins with one of the above keywords, or by identifying the given object’s only child as a
When the user chooses a tool containing more than a single given, the tool’s given objects become active, one after the other. Sometimes (for instance, with a Line Tool), the order may not matter. In other cases (for instance, the Measure Angle Tool) it may be important; you might prefer the three given points to become active in a specific order: first the point-on-initial-side, then the point-vertex, and last the point-on-final-side. As the tool author, you can set this as the sort order by appending a number to each given object’s keyword, labeling the point-on-initial-side as
By default, givens are activated in the order in which they were originally constructed
The keywords you use on the GSP source page for a tool do not appear when the WSP user eventually activates the tool. To specify a label that you want the tool user to see, append a colon to the given keyword (and sort-order number, if present), followed by the label you want to provide. See the section below on Labeling Tool Objects for more details on labeling the givens and productions of a tool.
There are four categories of given objects, based on the roles they play. The first three of these are simple givens, assumed givens, constructible givens, and given parents.
As you author a tool, you can use the label of each tool object to detrmine both the behavior and the label of that object during toolpLay.
You can use the label of a given tool object to determine the behavior of that given object during toolplay. The following methods apply only to given tool objects::
To be recognized, the tool object’s label must begin with the tool-role followed by the match-order (if any). If you also want to specify a label or any other signal (see below for Label Signals), you must insert a colon immediately after the match-order, or immediately after the tool role if there is no match-order.
When you create a tool, you can use the labels of the tool’s objects to control the labeling of the resulting objects in the sketch. The following methods apply to all tool objects:
PICK UP FROM HERE...
In the source sketch for a tool, you label objects in ways that determine how they will be used, labeled, and formatted during toolplay. Because the tool author seldom knows ahead of time what labels are already in use by the sketch into which the tool is played, tools don’t normally apply specific labels to either their givens or their productions. But you can add certain codes to the labels of tool objects to determine formatting options, visibility, and other features.
Because it serves multiple functions, the label of a tool object can have multiple elements, ordered as follows:
For an assumed given you must indicate the label of the sketch object to which it will be matched; for instance, “assumed: Center” to automatically match this assumed given to a sketch object labeled “Center.”
You might want to use a label to help you keep track of the roles of particular objects in the source sketch. If you specify the label of a given, the label must follow the colon. If you specify the label of a production, the label should start at the very beginning.
Examples: “assumed: Center”, “given3: A”, “P”
Note that only the “assumed: Center” example represents an actual label in the sketch. When the tool with point “P” as one of its productions is used in a sketch, the point it creates will be unlabeled. (But see the _apply_ code described below.
You can label any tool object in ways that affect the visibility and format of the label. Below are the codes you can use. Note that each code begins and ends with an underscore, and that one code must be separated from another by a space.
The label of any given object starts with given or constructibleGiven optionally followed by a number defining its sort order, optionally followed by a colon (“:”) and its desired user-facing label. Thus a given object labeled given3: Center is a simple given, has a sort order of 3, and will appear to the user with the label “Center”. To provide this label without making it visible during toolplay, hide the entire label. If you hide the label given3: Center, the label will not appear during toolplay, but if the user reveals it later it will appear as “Center.”
You can specify the format to use in labeling certain objects (such as transformed objects) created by tools. To apply a specific format in the source GSP sketch, label the object this way: "nameOrigin: format", replacing format> with one of the formats listed below. (In both GSP and WSP, labels can include subscripts by enclosing the subscript in square brackets.)
The first row of the table shows the formats available for labeling a transformed object in the source GSP sketch. The second row shows the same formats as they appear in the Label Widget. The third row shows an example: the label that results when a pre-image point A has been rotated about center point C by angle θ. For example, if the tool’s rotated image in the source GSP sketch is labeled "nameOrigin: namedByFullFn", the resulting image point is labeled rC,θ(A).
Format (GSP source) | namedByPrime | namedByShortFn | namedByFullFn | namedFromLabel |
---|---|---|---|---|
Format (Label Widget) | Prime | Short | Full | Manual |
Label Code | _prime_ | _short_ | _full_ | _manual_ |
Resulting Label | A′ | r(A) | rC,θ(A) | (next available default label) |
The first row of the table shows the formats available for labeling a measurement or calculation in the GSP source sketch, and the second row shows the formats as they appear in the Label Widget. The third and fourth rows show examples of the resulting labels that result when a tool has been used to create a measurement (the ordinate of point A) and a calculation.
Format (GSP Source) | namedFromTemplate | (user label) | namedFromLabel | noVisibleName |
---|---|---|---|---|
Format (Label Widget) | Auto | Manual | None | |
Label Code | _auto_ | _manual_ | _none_ | |
Resulting Label (measurement) | xA = 3.00 | m[1] | m1 = 3.00 | 3.00 |
Resulting Label (calculation) | 2·xA+ 5 = 11.00 | m[2] | m2 = 11.00 | 11.00 |
The first row of the table shows the formats available for labeling a parameter in the GSP source sketch, and the second row shows the formats as they appear in the Label Widget. The third row shows an example: the resulting label when a tool has been used to create a parameter.
Format (GSP Source) | (user label) | namedFromLabel | noVisibleName |
---|---|---|---|
Format (Label Widget) | Manual | None | |
Label Code | _manual_ | _none_ | |
Resulting Label | t[1] | t1 = 1.50 | 1.50 |
All other objects not mentioned above have “manual” labels that can be created in the GSP source sketch or typed into the Label Widget.
You can match a parameter to any compatible value in the sketch, where “compatible” means having the same kind of units: distance, angle, or scalar (without units). A parameter or measurement in radians can be interpreted either as an angle or as a scalar (in its sense as the ratio between arc length and diameter), so radian values are considered to be compatible with both angle values and scalar values.
Matching a parameter to “any compatible value” means that the user of the sketch can match not only another parameter, a measurement, or a calculation, but can also match any text object in the sketch that contains or refers to a compatible value. This includes both pegged text—text attached to a point—and composite text—text that includes values and/or labels of other objects in the sketch. (Composite text is sometimes referred to as “hot text.”) In such cases, the pegged text or composite text must have exactly one value-containing ancestor. It doesn’t matter whether the actual value or only the label of the value-containing ancestor appears in the pegged or composite text; in either case the given parameter will be matched to that ancestor’s value.
When creating tools, it’s often desirable to specify the order in which the given objects become active. This order is determined as follows:
Below are some examples of these rules in action.
One Given Label | Another Given Label | Order of Active Givens | Note |
---|---|---|---|
given11 | given9 | given9, then given11 | |
given2: A | given1: B | given1: B, then given2: A | Explicit sort order takes precedence |
given: B | given: A | given: A, then given: B | |
given | given | The first, then the second | |
given3 | given3 | ? | Undetermined; don’t duplicate sort values |
given | given3 | given3, then given | Explicit sort order takes precedence |
given3: y | given3: x | given3: x, then given3: y | Bad form; don’t duplicate sort values |
given | given: x | given: x, then given | Label takes precedence over empty |
given: 1 | given1 | given1, then given: 1 | Sort order takes precedence over label |
Simple givens have no parents; they are free points, parameters, or functions. Point givens can be matched only to points; parameter givens can be matched only to values (including parameters), and functions can be matched only to functions. But it’s often desirable to have a tool with givens that can be matched to other objects such as segments, lines, rays, circles, or polygons. Constructible givens make this possible.
A constructible given is a segment, line, ray, circle, or polygon constructed from given points, and with its own label beginning with constructibleGiven. The user can drag or tap to match such an object to a similar existing sketch object, or to locate the object in the sketch; alternatively the user can drag the constructible given object’s parent points to match or locate the parent points in the sketch.
With certain restrictions (described below), a constructible-given polygon can be matched to an existing polygon with a different number of vertices and sides. Thus you can create a polygon area tool that allows the user to measure the area of any polygon.
As you drag a constructible given to an existing sketch object, a brief animation occurs, animating the given object’s parent points to the corresponding locations for the existing objects.
This complex of objects (the constructible given and its parents) is always in one of two states:
When a complex is in a composed state (state 1) and the user drags a parent of the constructibleGiven, we say that the constructibleGiven is “decomposed” and the complex switches to state 2. If the constructibleGiven was matched to an existing sketch object, that match is dissolved.
When a complex is in a decomposed state (state 2) and the user drags the constructibleGiven, we say that the constructibleGiven is “recomposed” and the complex switches to state 1. Any matches between its parents and existing sketch objects are dissolved.
Below are some examples of whether a complex of constructibleGiven and its given parents start out in the composed or decomposed state, described in reference to a triangle. The triangle is the constructibleGiven, and the vertices are its given parents.
Triangle Label | Vertex Labels | Initial State | Note |
---|---|---|---|
constructibleGiven | given, given, given | Composed | Constructible takes precedence |
constructibleGiven1 | given2, given3, given4 | Composed | |
constructibleGiven | given2, given3, given4 | Decomposed | 2 precedes unnumbered |
constructibleGiven4 | given1, given2, given3 | Decomposed | |
constructibleGiven2 | given1, given3, given4 | Decomposed | Bad form! But 1 precedes 2 |
constructibleGiven: P | given: A, given: B, given: C | Decomposed | A, B, and C precede P |
constructibleGiven1: P | given: A, given: B, given: C | Composed | The 1 takes precedence |
constructibleGiven2: P | given1: A, given: B, given: C | Decomposed | Bad form! |
constructibleGiven1: P | given2: A, given: B, given: C | Composed | 1 precedes 2 |
constructibleGiven1 | given1: A, given2: B, given3: C | Undetermined | Don’t duplicate sort values! |
[This section is rather technical in nature.] A constructible given can always match any construction defined the same way. For instance, a triangle constructible given can always match any triangle defined by three points; a segment constructible given can always match any straight object defined by two points (though in this latter case, a tool that includes a measurement of the segment’s length would not give meaningful results if the matched object is a line or a ray).
It’s also possible, with certain restrictions, to match a constructible given to a compatible object defined differently. For instance, a constructible-given triangle (defined by 3 points) can be matched to the transformed image of a triangle only if the given parents of the constructible given triangle don’t define any productions of their own, except for the constructible given triangle itself. If the tool’s given parents define other objects (for instance, the segments that form the three sides of the triangle), those objects cannot be defined based on the transformed image of a triangle, because that transformed image doesn’t have any actual vertex points that could be used to define the sides.
As a result, the rule is that a constructible given whose parents have no children other than the constructible given itself can be matched to any compatible sketch object (straight object to straight object, triangle to triangle, triangle to quadrilateral, arc to arc, etc.). However, if the constructible given’s parents do have other children (such as the side segments of a triangle), the constructible given can be matched only to a sketch object defined in the same way (such as a triangle defined by three points, but not a triangle defined as the reflected image of another triangle).
The term sequential snapping refers to the fact that during toolplay there’s always a single active given object, an object that glows to indicate that the user can either match or locate it by tapping the desired objects or location in the sketch. This is the default mode for toolplay. In the alternative mode, with sequential snapping off, all given objects glow, and the only way for the user to locate or match a given object is to drag it to the desired location or object. This mode is generally less useful, as it’s more user-friendly to give the user the choice of either tapping or dragging to match a given object. To turn off sequential snapping, add a “WSP Preferences” page to your sketch and insert a caption with this text: “sequentialSnapping = false”.
You can specify which tools should appear on each page of a websketch. For instance, if your GSP document has three tool pages named WSP Tool: Point, WSP Tool: Segment, and WSP Tool: Circle, you could make the Point tool appear on all pages, make the Segment tool appear on both pages 2 and 3, and make the Circle tool appear only on page 3. To do so, create a WSP Preferences page, and enter the following captions:
Because the Point tool is not listed, it will appear on all pages of the websketch.
You can author a tool that allows the user to create and edit a new Parameter, Calculation, or Function. If your tools has only a single such given, then when that tool is played by the user, the numberpad or calculator will automatically come up. A given calculation of 1+1 is automatically replaced by an empty calculation, and will appear in the sketch in edit mode.
An auto-play tool has only assumed givens, and no other givens that can be matched. When you tap such a tool, it completes its constructions and finishes without any further interaction. [Unfortunately at the current time the Exporter doesn’t support tools without simple givens, so there is a temporary work-around in place to make it possible for you to author such a tool. In desktop Sketchpad, create the auto-play tool with all its assumed given objects, and then add to your sketch a single point labeled "given: delete". This will satisfy the current exporter, and the "given: delete" point will automatically be deleted from your tool when your sketch is loaded.]
To identify your tool in the WSP toolbox using an image rather than the tool name, add a free picture to the sketch. If there are multiple free pictures in the sketch, the first one is used, and the others are ignored.
There are three skins that determine the appearance of the toolbox: classic, new, or compact. Use Author Preferences to set the desired skin, by placing a caption on the WSP Preferences page. The caption should be of the form "Tool Look = " followed by the name of one of the three skins.
There are two pathways to enabling Tool Help for tools in websketches that you create. Both involve using the Web Sketchpad Tool Library, because all tools in the library’s Basic collection are help-enabled.
Once your sketch is finished in the Tool Library, download it in .json format and incorporate it into your webpage.