User:Brian Schott/code/turtleGraphics/oldopengl

From J Wiki
Jump to navigation Jump to search

This page has bee superceded by the page which uses "modern" opengl. This old system worked with j602 and maybe j7, but not j8.

This graphics system is like classic Logo, but implemented in a way that is compatible with the vector-oriented data of J. The current system is in 3D.

I have reorganized the openGL version of tgsj (turtle graphics system for j) to be more like the standalone script which supports the openGL demos. [I plan to have this system supercede the earlier systems which I have left temporarily hyperlinked at the bottom of this page.]

As the standalone script which supports the openGL demos has jzopenglutil.ijs, there is now a script

File:Tgsjutil.ijs which is meant to support all tgsj simulations; also, tgsjutil.ijs calls (requires) jzopenglutil.ijs. While openGL is used to create the turtle objects in this system, none of the examples require the user to have any knowledge of openGL because the turtle objects are all pre-defined.

Gosper.png

At present there are two working simple examples of tgsj,

File:Tgsjbasic.ijs simulates 1 turtle in 3D
File:Tgsjbasic2.ijs simulates n turtles in 3D.

There are also some auxiliary files, including the following.

File:Tgsjcommands.ijs lists several of the available turtle commands
File:Tgsjhelp.ijs gives some examples and help as a large noun

All 5 files must be put into the same directory. If they are put directly into the Jxxx-user directory they should work without alteration. If they are put into another directory, the noun Path in the simulation script file (eg, tgsjbasic.ijs, tgsjbasic2.ijs, tgsjdancers.ijs) must be altered.

A typical application of tgsj would have an ijx window for loading simulation file and entering turtle commands, an ijs window for accumulating series of turtle commands to produce more complex graphics, and a graphics window to show the dynamics of the turtle simulation. I have had some success placing the graphics window in the upper left corner, and after using the menu Window|Tile, dragging the other two windows away from the upper left corner reserved for the graphics window; ymmv.

I recommend that you start by loading either tgsjbasic.ijs or tgsjbasic2.ijs into the ijx window using menu Run|File and opening tgsjcommands.ijs into an ijs window using menu File|Open User... so that you can execute example commands from the ijs by selecting them and using the Run menu or its equivalent keystroke shortcuts. If you want to save your series of turtle commands as you develop new turtle movements, you may like one more ijs file.

At the present time (11/19/9) on my ancient Macintosh computer I am getting frequent system failures using this system. They seem to occur after I have exercised the turtles for a while, not as a result of a particular sequence of commands. I am anxious to find the cause of this problem and would appreciate any insights or observations you may have on any computer platform.

The Gosper flowsnake graphic above is drawn with this system. The code below was translated from the Logo at Wikipedia.

File:Gosper.ijs


I also have a set of files for simulating contra dancing. This dancers system is even less well developed than the basic ones above. But I am making the scripts available to suggest a more complex system. The dancers simultion files are listed below.

File:Tgsjdancers.ijs the simulation script; male-dancers and female_dancers are defined; initialization verbs are defined, esp. tgsjD_run
File:Tgsjdancermoves.ijs formation verbs hands4, hands4cross, and becket; also moves like circle, allemande, dosido, swing
File:Tgsjdancerdemo.ijs sample dance sequences

To start you may want to type the following.

   load'~user/tgsjdancers.ijs'
   hands4 10      NB. tgsjD_run 10 is embedded in hands4 10

The tgsj system shows dancer couples in contra dancing "sets". Instead of turtle-like objects, male and female dance pairs are generated using the verb tgsjD_run with an even (small) integer argument, say n. This produces two lines of dancers facing the imaginary dance caller.

Colors are used to organize the contra dancers. For example a set is subdivided into sub-sets of 4 dancers, each of whose clothes are colored the same, and within each group of four, one pair is dark skinned (the "active" or "#1" couple) and the other is light skinned. Each dancer, up to 15, has different colored shoes.

There are three formations of dance sets for starting dances: proper, improper, and becket. These three formations correspond to three verbs which each call tgsjD_run: hands4, hands4cross and becket and each takes a small even integer argument >: 4. In the J scripts a list Dancers is initialized as i. n and the dancers will be given that number in the verb tgsjD_run and they keep that number throughout the dance, but the list Dancers is permuted according to what position the dancers take in their "set". Furthermore there is a corresponding list of alphabetic characters in the that are shown in ijx window as the simulation progresses using a code snippet like the following.

DancerSymbols {~ each sfd Dancers

In the ijx window, a trivial start of a dance with 6 dancers might look like the following, where capital letter are gents and partners share the same letter, but different case. Often there are "neutral" dancers who are temporarily "out" of the dance as in this example pair Cc is neutral, and thus are not in Foursomes but are in Dancers.

   hands4 6
+--+-+
|ab|c|
|AB|C|
+--+-+
   Dancers
0 1 2 3 4 5
   Foursomes
0 1 2 3

To see how the starting formations differ and it may be worth your while to experiment by entering hands4cross 6 and Dancers and Foursomes, for example. Also try becket .... I recommend also that you close the graphics window each time before you start a new starting formation, to prolong the time before the system crashes as does my ancient Macintosh. In case you are impatient, I am adding similar screen copies below.

   hands4cross 6
+--+-+
|Ab|c|
|aB|C|
+--+-+
   Dancers
1 0 2 3 4 5
   Foursomes
1 0 2 3
   becket 6
+--+-+
|aA|c|
|Bb|C|
+--+-+
   Dancers
2 1 3 0 4 5
   Foursomes
2 1 3 0

Once the dancers are in their starting formation, several dance moves are available and many are not (yet) available. Some example moves or "calls" are listed next. The verbs are lower case words, and there is an attempt to arrange the arguments for dyadic verbs so that the left argument names the type of dancers and the right argument quantifies or qualifies the move somehow.

Partners dosido Whole
circle 1
Partners swing Faceacross
chain Women
Neighbors allemande 1.5

You can try some examples provided in the file tgsjdancerdemo.ijs also. If you want some dancers to mark their path along the floor, treat them as turtles and type something like pendown 0 3 -- notice men are even and women are odd numbers.

The main file is tgsjdancers.ijs which calls others including tgsjutil.ijs.


What follows is material that is dated. I am now developing the material above.


2D turtle graphics: /2D
3D turtle graphics: /3D
3D turtle graphics openGL: /3Dogl
2D turtle graphics Lab: /lab