Javascript <-> CaRMetal communication

This page is for javascript programmers only. It shows you how communication can work between javascript and CaRMetal applets. All of these commands must be sent by the JSsend call : you can see the source code of the bottom frame of this page. In order to see the command syntax, you just have to clic on the left frame links.

Those who wants to use javascript to drive CaRMetal applets must have at least the 2.8.8 version of CaRMetal.jar. You can find it here, if you need it.

Object creation

In all this section, you will find out how you can create objects with CaRMetal applet, using the JSsend call. It always possible, for all these commands, to write only the right part of the "=" sign. If you do this, CaRMetal will choose automatically a name for your object.

Random points :

Syntax 1: P

This will create a random point in the window

Syntax 2: A=P

This will create a random point A in the window. You can show its name by calling the "shownames" command before, or, after the creation by calling the "name(true,A)" command.

Fixed points :

Syntax : A=P(-1,2)

This will create a fixed point A in the applet with coordinates (-1,2).

Intersection points :

Syntax 1 : A=I(a,b)

This will create an intersection point A between two lines (or segments or rays) a and b.

Syntax 2 : A,B=I(c,d)

This will create two intersection points A and B between two circles (or between line and circle) c and d.

Midpoints :

Syntax : R=M(A,B)

This will create the midpoint R of segment [AB].

Segments :

Syntax 1: a=s(A,B)

This will create a segment a from A to B.

Syntax 2: a=s(A,3)

This will create a segment a from A with a fixed length.

Lines :

Syntax : a=l(A,B)

This will create a line a through A and B.

Parallel Line :

Syntax : b=par(a,A)

This will create a parallel line through point A to line a.

Perpendicular Line :

Syntax : b=perp(a,A)

This will create a perpendicular line through point A to line a.

Rays :

Syntax : a=r(A,B)

This will create a ray a from A to B.

Circles :

Syntax 1: a=c(A,B)

This will create a circle around A through B.

Syntax 2: a=c(A,3)

This will create a circle around A with fixed radius 3.

Syntax 3: a=c(A,B,C)

This will create a circle around A with radius BC.

Angles :

Syntax 1: a=a(A,B,C)

This will create the angle ∆ABC.

Syntax 2 : a=a(A,B,30)

This will create the fixed angle from A and B with a fixed angle.

Polygons :

Syntax 1: p=poly(A,B,C,D,E,F)

This will create the polygon ABCDEF

Conics :

Syntax 1: c=quadric(A,B,C,D,E)

This will create the conic throught points A, B, C, D, E.

Functions :

Syntax 1: u=function(a,b,d,t,x(t),y(t))

Create a parametric function on [a,b] with step d, plotting x(t),y(t), which are expressions depending on the variable t.

Syntax 2: u=function(a,b,d,x,,f(x))

Create a cartesian function on [a,b] with step d, plotting f(x) which is an expression depending on the variable x.

Working on objects

Renaming object :

Syntax : rename(A,B)

Rename the object A to B

Moving points :

Syntax : value(P,3,2)

Move point P to the coordinates (3,2)

Fix length and angles :

Syntax 1: value(s,2)

Fix the length of segment s to 2

Syntax 2: value(c,2)

Fix the radius of circle c to 2

Syntax 3: value(w,30)

Fix the size of angle w to 30

Display values :

Syntax 1: showvalues

After calling this command, values of new objects will be displayed.

Syntax 2: hidevalues

After calling this command, values of new objects will not be displayed

Syntax 3: value(true,o) or value(false,o)

Display or hide the value of an existing object o

Display names :

Syntax 1: shownames

After calling this command, names of new objects will be displayed.

Syntax 2: hidenames

After calling this command, names of new objects will not be displayed.

Syntax 3: name(true,o) or name(false,o)

this will show or hide the name of an existing object o in the applet.

Display objects :

Syntax: hide(true,o) or hide(false,o)

Hides or un-hides an object o.

Changing colors :

Syntax: color(green,o)

Changes the color of object o to green. Possible colors are : green, blue, brown, cyan, red, black.

Changing thickness :

Syntax: thickness(thick,o)

Changes the thickness of object o to thick. Possible thicknesses are : thick, normal and thin.

Changing shape of points :

Syntax: type(square,A)

Changes the shape of point A to square. Possible shapes are : square, circle, diamond, point, cross, dcross.

Window zoom and move :

Syntax: window(-1,1,3)

Set the center of the window to coordinates (-1,1) and set the width of the window to 2*3

Obtuse :

Syntax: obtuse(true,w) or obtuse(false,w)

Set angle w so that it can be greater than 180° or not.

Solid :

Syntax: solid(true,o) or solid(false,o)

Set the object to non-transparent state or not.

Arc :

Syntax: restrict(c,A,B)

Restrict circle c to become an arc from A to B.

Getting information from applet

It's possible at any time to get information from the CaRMetal applet using the JSreceive function (you can see the source code of the bottom frame of this page). The way to use it is simply enter an CaRMetal expression as argument.

For example, if A and B are existing points, you can give to the JSreceive function the string below:

sqrt((x(A)-x(B))^2+(y(A)-y(B))^2)

It will return, in your javascript code, the distance AB.