User:Brian Schott/code/turtleGraphics/tgsjhs

From J Wiki
Jump to: navigation, search

Turtle Graphics System in JHS

Tgsjhs, a new version of tgsj, is a turtle graphics system in J patterned after Logo, the programming language developed by Seymour Papert and others at MIT in 1967. Its purpose is to enable the use of the power of J for further development.

The assumed location for the files in this version of tgsj(hs) is in the subdirectory named projects/tgsjhs under the j-user directory.

Another file named tgsjhshelp.html gives some additional pointers on using the features of tgsjhs.

A 3-frame example: Tgsjhs.png

Basic installation

Tgsj(hs) is best used with 2 browser tabs or frames open side by side: one ../jijx and one ../tgsj. The disadvantage of multiple tabs is that only one is visible at a time; the disadvantage of multiple frames is their step for construction. In this paragraph tabs are discussed, while frames are discussed in the next paragraph. To properly configure the ../jijx tab (or frame), enter the following command there: coclass'tgsj' . A simple direct way to start with two tabs is to enter the following command in ../jijx also: load'~Projects/tgsjhs/tgsjhs.ijs'. Then you must manually create a new tab with the following address: . Then use the new tab to control turtles by entering one line commands in the one text field, and read turtle status reports in the ../jijx tab after striking <enter> there. For example, you can change the pencolor or the number of turtles. You may also define/view multi-line features for the system by typing them in the ../jijx tab. For example you could author in J a stylized move/turn verb like poly3 (to see poly3, enter poly3 in the ../jijx window).

A very effective and simple 3-frame browser window (simplified by Joe Bogner) is embedded in the file frames.ijs which is now loaded automatically be the main file named tgsjhs.ijs. To use this 3-frame browser, after you have loaded tgsjhs.ijs as describe just above, open a new browser window or tab with the link

To restate the information in the previous paragraph: I (really Joe - after Eric, after ... - did it) have created a 3-frame html interface for tgsj, patterned after demo9.ijs for JHS. Because of this, you may choose to open a new browser tab with the link In any case, either in the jijx frame of the 3-frames or in the jijx tab, you will likely want to re-orient jijx so that the locale is 'tgsj': enter coclass'tgsj' by hand.

You can alter the number of turtles with the command initTurtles 2 by changing the 2 to another number.

Tgsjhs is set up to have 2 tetrahedral turtles, with a color scheme and pen colors derived from the colors in COLORTABLE. To alter the turtle colors is awkward, but some examples are given in the help file. Enter Turtlecolor and Pencolorin jijx to see how they are reported.

Oh, that reminds me, a result of adopting webgl, over openGL, is that there may be a way to add an extra imaginary "Eye" turtle to empower control over the viewer's viewpoint, but not completely. I have attempted to revive the programmatic control of the "Eye" turtle, but the manual movement of the viewport and the "Eye" are unaware of one another. We'll see if this works or not. Please let me know. (Editted 4/20/14).


You can download the several files here. They should go inside a single directory named tgsjhs inside the projects directory.

File:Tgsjhszip.png contains all files You must rename this file
File:Tgsjhs.ijs simulates 2 turtles in 3D
File:Tgsjhsutil.ijs utilities
File:Tgsjhshelp.txt help You must rename this file tgsjhshelp.html
File:Frames.ijs allows for a 3-frame browser interface (first enter load'~Projects/tgsjhs/tgsjhs.ijs' in the jijx window, then open a browser tab with

A Wifi Classroom

JHS can be made to work over a local wireless network where all users access the same resources on their own tablets, smartphones, laptops. The teacher and students can experience tgsjhs with one another, seeing the turtles' behavior somewhat anonymously, in the sense that the teacher can whisper to each student a turtle number to control. But each student's behavior can potentially restart the drawing canvas either mischievously or unintentionally.

While the teacher launches tgsjhs.ijs on a computer with J installed, all the other devices only require a webgl enabled browser. The teacher's version of J must be configured so that the file named


must have the following line

BIND=: 'localhost'

changed to

BIND=: 'any' .

The result is that JHS can be accessed on student devices using the SERVER_IP_ADDRESS shown on the teacher's computer in the window below.

/PATH/TO/j64-803/bin/jhs.command ; exit;

J HTTP Server - init OK

Requires HTML 5 browser with javascript.

A : separates ip address from port.

Access from another machine:

Start a web browser on this machine and enter URL:

Tgsjhs assumes initially there will be only a teacher and 1 student and therefore is initialized with initTurtles 2, but the number 2 can be altered by the teacher in the jijx frame by just typing initTurtles 5 and hitting the return key.


Quick look
Quick look at a classroom wifi demo
Quick look at "pendula waves"

Pendula waves demo

A script for producing "pendula waves" is below.


NB. to execute load this after loading tgsjhs.ijs; enter something like: 30 main 9


GA =: 9.80665 NB. Gravitational Acceleration (meters per second squared)

sin=: 1&o.
pi=: 1p1
dfr=: *&(180%pi)
rfd=: *&(pi%180)

scale =: 2
fdscale =: 0.05
NB. 21 main 5 works but 60 main 9 may not, for example
main =: 4 : 0
duration =: x
NB. Step_scale =: %100
init ''
initTurtles y
pu ''

reverse01 =. _1 -@+ +:
scalediff =. scale * 0.05
setlength =. <.@-: + 4 +i.
length =. setlength y
FD =. fdscale * length
xdist =. * i:@-:@<:
ngol =: - GA % length    NB. Negative G over L
total_time =: 0.0        NB. Seconds
angle =: 1.0             NB. Initial angle of pendulum (radians)
sinAngle =. sin angle
goto scale * (xdist,.-@setlength,.sinAngle * -@setlength) y
speed =: 0.0             NB. Initial angular velocity (radians/second)
time_step =: 0.05        NB. Seconds
while. total_time < duration do.
    total_time =: total_time + time_step
    oldspeed =: speed
    speed =: speed + ngol * (sin angle) * time_step
    angle =: angle + speed * time_step
    mask =. speed ~:&*&(+&scalediff) oldspeed  NB.reverse direction
    NB. if. +./mask do. pt dfr pi * mask end.
    FD =. (reverse01 mask) * FD
    pt dfr speed * time_step
    NB. fd fdscale * length
    fd FD