JavaSketchpad applet composition

Syntax

The compiler syntax is slightly different from that of JavaSketchpad, to avoid the drawback of absolute numbering of items.
For more details about JavaSketchpad® see the JavaSketchpad web site.
See also
This compiler doesn't replace JavaSketchpad, it is just an additional facility for hand writing of scripts.

Every source line is either
{comments} or
{id} entity (parameters...)[options];
In bold, mandatory part

id is a comment for JavaSketchpad, here it is the item name.
Allowed characters are a-z A-Z 0-9 _ @ § # $ % & ~ | ! ? = : / ^ * + . - and spaces inside the name (ignored before and after the name)
Forbidden < > ( ) [ ] { } , ; \ '  " accented letters é and alike (ç €)
Leading numbers and space are just ignored before id, {24 T} is the same as {T} (compatible with existing scripts)
Without an id (or just numbers and spaces) an id is automatically generated by the compiler as "typennn", or the label value if any, and the source is everywhere updated accordingly.
The Declic syntax is also allowed :
{id} {#num} Entité (paramètres...)[options];
If id starts with a # (intermediate elements in Declic), it is numbered to have a unique id.
(this substitution is done only in a DEclic syntax, otherwise # is a normal character)

The optional... options are comma separated inside a square bracket pair [ ] :

Example :
{ a construction }
{A} Point (200,300);
{B} Point (300,300)[label('B''')];
{AB} Segment (A,B)[yellow,layer(5)];
...
{C} Circle (D,E);
...
Intersect1 (AB,C);
Note : in the labels and also in other text fields a ' is coded ' ', the " is forbidden, use ' ' ' ' instead

Example :
{B!} Point (300,300)[label('B''')]; for a point dispalyed as B'
Note that the id B' being forbidden, it was named B!

We may 'import' by copy-paste of existing "Construction value", not symbolic, the compiler generating symbols by itself.
Inversely, the only way to save the work is by copy-paste of the source or the construction value field into a text file.
To insert the construction in a Web page, it should be copied inside an <applet<> tag of the page
Only the 'construction value' can be fed to the applet, a source text doesn't work.

Instead of typewriting everything, selection boxes allow to add/modify the only last line of the construction.

The frequently used options are also triggered by direct buttons for :
label(), hidden, layer(), thick and the values π/2 and π/3

Macros

The macro are defined in the corresponding selection box
This list may be edited with the Add, Del, Edit buttons just below.
Only the macros in the "macros" box are concerned. The "expression macros" in the Calculate box for Calculate and Function, like min(A,B) = "AB+AB-@abs_-2/" can't be edited nor created.
A macro is a normal construction that can be tested as a normal figure.
The only difference is at the very timpe of insertion into a construction, some symbols are replaced :

The symbols starting with $ are parameters, the value being asked at insertion time by a dialog box.
THey have to be declared as such in the macro by a line :
{ $A='prompt for A', $X='prompt for X' .. }
Otherwise the $ character is a normal character, and the symbols won't be substituted by a value which is not asked !!
Symboles starting with % are internal symbols to the macro
They are set unique at insertion time by adding the number of the macro in the construction.
Otherwise, outside macro insertions, these $ and % are normal characters.

A few macros are predefined at page loading, being merely examples.
The list is reset to these predefined macros when reloading the page, all user defined or modified macros are lost.
The triggered actions (Add, Del, Edit) are given up when doing anything else.

Inserting a macro into the construction

Directly by selecting the macro in the selection box, this is added at the end of source, like any single element.
If the macro has parameters ($), a dialog box asks the value of these parameters, reply as a comma separated list of existing objects or values.

Creating a macro

The Add button make pop a macro editing window up.
The name is mandatory and must be short. This name will be shown in the macro selection box to insert this macro.
It is truncated to 16 characters (too long a name would distort the size of the macro selection box)
This name should be unique, otherwise the scripts offers to replace the macro with the same name, instead of adding a new one.

The source of the macro must be manually typewritten (no possibility of using the selection boxes from the main window)
However you may copy-paste a construction from the source of the main window, as a macro is a normal construction, just with "strange names".

A macro with parameters ($..) must contain a comment line defining the corresponding prompts
These prompts are the text asked in the dialog box when inserting the macro.

For instance

{ conjuguate of $m/($a,$b) }
{ $a='A', $b='B', $m='M' }
{%r} Ratio/Points ($m,$b,$a,0,0,' ')[hidden];
{%s} Calculate (0,0,' ','A1+@sgn_@abs_1-@sqrtA+2*A1+/')(%r)[hidden];
{%N} Dilation/MarkedRatio ($b,$m,%s);

The parameters are $a, $b et $m
Intermediate objects %r, %s and the final result %N are created by the macro

When inserting the macro the aliases A, B, M are asked in the dialog box
These aliases may describe the parameters, for instance : { $a='End', $b='Center', $m='Current Point' }
It is just text for the dialog box.

The generated macro is, if we reply "P, Q, R" :

{ conjuguate of R/(P,Q) }
{%15r} Ratio/Points (R,Q,P,0,0,' ')[hidden];
{%15s} Calculate (0,0,' ','A1+@sgn_@abs_1-@sqrtA+2*A1+/')(%15r)[hidden];
{%15N} Dilation/MarkedRatio (Q,R,%15s);

The parameters $a, $b and $m have been replaced everywhere with P, Q and R respectively
%r, %s and %N have been numbered into %nnnr, %nnns et %nnnN with nnn is the number of this macro in the construction, to have a unique id.

Arithmetic expressions
The parameters in a macro may be used, if they are numbers, inside arithmetic expressions
Such an expression is to be encloesed in « ». Example :

{%xgrid} Locus (%XX,%yg,%YY, «abs(ceil($Ymax) - floor($Ymin))*5 + 1»);
The parameters $Ymax and $Ymin are used to calculate the Locus number of points.
At macro insertion, supposed you answered -2.5, 5.7 at the prompt for $Ymin and $Ymax, the (static) generated line is

{%5xgrid} Locus (%5XX,%5yg,%5YY, 46);
resulyt of calculating : abs(ceil(5.7) - floor(-2.5))*5 + 1 = 46, for ceil(5.7) = 6 and floor(-2.5) = -3
The '5' is the macro number in the construction, as usual for the symbols with %

The "weird" caracteres « » not on a keyboard are inserted by the corresponding button, at the caret location.
THe syntaxe used in the expressions is the JavaScript.Math syntax (refer to JavaScript doc)
THat is mainly :
Operations + - * / an parenthesis, % (modulo, not the % used in names !)
Math functions abs(), floor(), ceil(), max( , ), min( , ), cos(), sqrt(), etc, the values PI, E etc
The unary - minus
The result is intended to be a numeric value
These expressions have then to be used only in this context
You have to add parenthesis or spaces if the parameters may take negative values :
«$A-$B» results into a JavaScript error if $B is negative as this is translated first as 1--2
«$A-($B)» is OK : translated into 1-(-2) = 3
«$A - $B» is also OK : translated into 1 - -2) = 3

Note : The errors in expressions are reported directly by JavaScript and not in the compiler.

Editing a macro

To modify a macro, clic on Edit, then select the macro to be edited in the macro selection box.
The macro editing windows pos up, if not already done and allows editing the macro
Clic OK to register the edited macro.
Even the predefinbed macros can be edited, to meet your needs.

If we select another macro while editing, this newly selected macro is proposed in the edit window instead of the first.
The previous edition is given up, the first macro is unchanged and every modification is lost.
To give up edition and allow inserting macros again, clic the Cancel button, or select anything else but a macro.

Copying a macro

To create a new copy, may be edited, of an existing macro :
Edit
Select the initial existing macro
Modify it, changing its name
Clic Add
OK

If we don't change the name, the script ofers to replace the first macro instead of creating a new one.
If we don't clic Add, it would modify the existing macro, changing also its name.

Deleting a macro

Clic Del, then select the macro to delete in the macro selection box. No confirm is asked.

Saving the macro

As for the constructions, the macro can be savedd only by manually copying them into a text file, one at a time, from the macro editing window by copy paste.

JavaSketchpad version

The compiler generates by default an applet for version 5 of JavaSketchpad (jsp5), the most up to date.
But we may want to use the older version 4 (jsp4). The version is chosen by a checkbox in the compiler.
Note that version 4 is out of date and no more available at the official JavaSketchpad web site.
The drawback of version 5 is hideous big points, and antialiasing (a drawback just for screen copy and post processing of the copy)
Otherwise of course the most recent version (jsp5) is to be used !

JavaSketchpad items

(in red the new functions in jsp5)

Point (numx, numx)     Upper left corner = (0,0)
FixedPoint (numx, numy)
Midpoint (segment)
Point on object (straight|circle|polygon, num)
Intersect (straight, straight)
Intersect1 (straight|circle, circle)
Intersect2 (straight|circle, circle)

Segment (pointB, pointA)    Oriented A→ B
Ray (pointB, pointA)
Line (pointB, pointA)
Perpendicular (straight, point)    (Rotation -π/2)
Parallel (straight, point)
Bisector (pointA, center, pointB)      (generate a Ray from 'center')

Circle (center, point)
Circle by radius (center, dist|calc)
Circle interior (circle)
Polygon (point, point, point ...)

Reflection (obj, straight)
Dilation (obj, point, num)
Dilation/SegmentRatio (obj, center, segmentN, segmentD)     segmentN/segmentD
Dilation/3PtRatio (obj, center, pointA, pointD, pointN)     AN/AD !! reverse order of SegmentRatio
Dilation/MarkedRatio (obj, center, ratio|calc)
Rotation (obj, center, num)
Rotation/MarkedAngle (obj, center, pointA, pointO, pointB)     angle (OA,OB)
Rotation/MeasuredAngle (obj, center, angle|calc)
Translation (obj, deltax, deltay)     deltay > 0 upwards
VectorTranslation (obj, pointA, pointB) A→B
Translation/FixedAngle/MarkedDistance (obj, dist|calc, num)
Translation/MarkedAngle/FixedDistance (obj, angle|calc, num)
Translation/MarkedAngle/MarkedDistance (obj, angle|calc, dist|calc)
Locus (point|straight, freepoint, path, num)

Colorized_Spectrum (obj, measure, min, max, 0/1/2) (0 = between min-max, 1 = repeat, 2 bidirectionnal)
Colorized_Grayscale (obj, measure, min, max, 0/1/2)
Colorized_RGB (obj, measR, measV, measB, min, max, 0/1/2)
Colorized_HSV (obj, measH, measS, measV, min, max, 0/1/2)

Length (segment, numX, numY, string)
Angle (pointA, pointO, pointB, numX, numY, string)     angle (OA,OB)
Perimeter (polygon, numX, numY, string)
Circumference (circle, numX, numY, string)
Radius (circle, numX, numY, string)
Area (circle|polygon, numX, numY, string)
Slope (straight, numX, numY, string)      slope (tanα)
Distance (pointA, pointB, numX, numY, string)
Ratio/Segments (segmentN, segmentD, numX, numY, string)     segmentN/segmentD
Ratio/Points (pointO, pointD, pointN, numX, numY, string)     ON/OD !! reverse order of Ratio/Segments
Calculate (numX, numY, prefixStr, exprStr)(measureA, ..., measureZ)
    + - / * ^ ! A-Z num, in reverse Polish notation . num must be ≥0 (no unary - )
    ! is negate, ^ is power
    @sin_ @cos_ @tan_ @abs_ @sqrt @ln__ @rond @trnc @sgn_ @asin @acos @atan @log_
    @fx with x = [A-Z]
Function (numX, numY, prefixStr, exprStr)(measureA, ..., measureZ)
    exprStr using the dummy variable 'x' in addition to the same syntax as Calculate

ShowButton (numX, numY, string)(obj1, obj2 ... objN)
HideButton (numX, numY, string)(obj1, obj2 ... objN)
ToggleVisibilityButton (X, Y, 'off|on')(obj1, ... objN)
MoveButton (numX, numY, speed, string)(point1a, point1b, point2a, point2b ... pointNa, pointNb)     pointXb → pointXa (!!!)
AnimateButton (numX, numY, string)(point1, path1, point2, path2 ... pointN, pathN)     pathX=straight|circle|polygon
    (num1, num2 ... numN)     list of speeds
    (flag1_1, flag1_2 ... flag1_N)     0=forever, 1=only once
    (flag2_1, flag2_2 ... flag2_N)     0=trigonometric|back and forth, 1=clockwise|one direction
SimultaneousButton (numX, numY, string)(button1, button2 ... buttonN)

FixedText (numX, numY, string)
PeggedText (point, caption|measure)
ConcatText (numX, numY)(caption|measure1, caption|measure2 ... caption|measureN)

Image (numX, numY, urlstring)     displays an image, url inside the (codebase) directory of the JavaSketchpad applet (jsp*.jar)
ImageOnPoint (point, urlstring)
ImageBetweenPoints (PntA, PntB, urlstring)     resizes the image to fit in the rectangle defined by the two points

Origin&Unit (origin, unitpoint)     defines a coordinate system (grid)
CoordSysByAxes (axeX, axeY)
UnitCircle (circle)     idem from a circle
UnitPoint (origine , num)     defines a dragable 'unit' point
AxisX (coord)     draws Ox axis
AxisY (coord)     draws the Oy axis the 0 and 1 points of these axes are .. weird (-200, +200 pixels !)
PlotXY (MesureX, coord, MesureY)     displays a point at coordinates (X,Y)
PlotFixedXY (coords, X, Y)
FunctionPlot (func, coord, num, min, max, 0/1/2/3)     coord must be a CoordSysByAxes (an Origin&Unit doesn't work)
         0 : y = f(x), 1 : x = f(y), 2 : r = f(theta), 3 : theta = f(r).
Coordinates (Point, coord, numX, numY, string)     measures the coordinates of the point
   used as #XY in calculate, Y = 1 abscissa of element X, Y = 2 ordinate of element X
Abscissa (Pnt, coord, X, Y, 'str')
Ordinate (Pnt, coord, X, Y, 'str')
CoordinateDistance (Pnt, Pnt, coord, X, Y, 'str')

Options

hidden
layer(n)
color(r,g,b)
traced (points, lines and circles)
    Points only :
label('str')
dot
small
mediumPoint
large
    Lines (straight, circles etc) only :
thick
hairline
thin
mediumLine
dashed
dotted
solid
    texts :
font('str')
size(n)
plain
bold
italic
justifyLeft
justifyRight
justifyCenter
    buttons :
auto
image('url.gif')
    measures and calculates :
suffix('str')
digits(n)

<applet> tag

Although discouraged by the W3C, using the <applet> tag is the only efficient way to invoke ... a Java applet.
The "recommanded" method with embedded <object> and <embed> is unpracticable as all the parameters have to be duplicated !! and the syntax is browser dependant.

The format of this tag is, for using JavaSketchpad :

<applet code="GSP.class" codebase="../jsp" archive="jsp5.jar" width="800" height="450"> 
<param name=Frame value=0>
<param name=BackRed value=255>
<param name=BackGreen value=255>
<param name=BackBlue value=221>
<param name=MeasureInDegrees value=1>
... other applet parameters ..
<param name=Construction value="
{1 O} Point (90,350)[blue,label('(d)')];
{2 §x} Translation (1,200,0)[hidden];
{3 §Ko} Circle (1,2)[hidden];
{4 x} Point on object (3,0)[blue];
...
"> 
Alternate text if Java is not enabled.
</applet>
code must be "GSP.class" (entry point in the applet)
codebase is the path in the web site of the directory containing the jsp*.jar file
archive is the name of the JavaSketchpad file jsp4.jar or jsp5.jar
And also general HTML options (width, style etc..)

The applet parameters <param name=... value=...> are forwarded to the applet itself
See the doc on the JavaSketchpad site for a full description of these parameters
The most useful are :

Frame
0/1 defines whether the applet is surrounded by a frame
BackRed
BackGreen
BackBlue
define the background color (0-255 for each component)
MeasureInDegrees
Measurements are done in degrees or radians (radians by default)
Note that all angles are handled in radians.
If measurements are in degrees, they have to be converted (by a Calculate) into radians to use them inside the construction.
Conversedly if measurements are in radians, they have to be converted in degrees by a Calculate to display them in degrees.
DirectedAngles
0/1, defines if angles are unsigned/signed (signed by default)
LabelFont
ActionFont
MeasureFont
Default font for labels : "TimesRoman", "Helvetica", "Courier" etc (some Java font)
LabelSize
LabelBold
LabelItalic etc
0/1, and the same for Action or Measure
Digits
(jsp5) display accuracy, the number of digits after the decimal point. 3 by default

Differences with JavaSketchpad®

Local installation

dir/mathie.css         (css style sheets)
dir/math.css            "
dir/exe_en/genapp.html (html interface for the compiler)
dir/exe_en/colors.html (html popup for palette)
dir/exe_en/macro.html  (html popup for macro edition)
dir/exe/genapp.html     idem in french
dir/exe/colors.html     "
dir/exe/macro.html      "
dir/jsp/jspc.js        (The compiler's Javascript)
dir/jsp/colors.jar     (the palette Java applet)
dir/jsp/jsp5.jar       (The JavaSketchpad applet, to be downloaded from the JavaSketchpad web site
dir/jsp/jsp4.jar       (the old version, obsolete and not available anywhere else)
dir/jsp/url.gif        test image.
dir/imgc/*.gif|bmp     menu icons.

Then launch the compiler by dir/exe_en/genapp.html
It is a "stand alone" version of the compiler (reduced menu, etc)
It doesn't include the example files, that stay on my website.

JavaSketchpad® is the property of Key Curriculum Press Inc.