BFOIT - Introduction to Computer Programming

New TG Features - March 15, 2013

Introduction

Version .0.9.35 of TG has new features that make it easier to use and enhancements that allow you to put together much more interesting applications.

Multi-line Commands

I finally gave in and added support for a tilde ('~') continuation character in the Editor (but not CommandCenter).  You can now do things like:

   to doWhatsRight :value
     ifelse :value ~
	    [ doSomething ] ~
	    [ doOtherThing ]
     end

   to advancedIteration
     repeat (sentence startIdx maxIdx incrAmt) ~  
	    [ doSomething ]
     end 

LABEL Enhancements

Prior to version .9.35, the SETLABELHEIGHT command's input was a font size.  There was no easy way to map font sizes to the actual pixel height of characters.  I provided a table in documentation for SETLABELHEIGHT that gave estimates of character heights for a few font sizes.

	  Char      Char  
  Size   Height    Width
  ----   ------    -----
   12        9        7
   14       10        8
   16       12        9
   18       14       10
   24       18       14
   32       22       18

In v.9.35 of TG, the input to SETLABELHEIGHT is a requested height for capital letters in the current font.  TG does its best to choose the font size that has capital letters with the requested height.

In addition to better control over the height of LABELed text.  A new operator, LABELWIDTH, outputs the width in turtle steps (pixels) of the textual representation of its input. 

Following is an example of how the new LABEL stuff can be used to draw a button on the graphics canvas.

   ; Draw a button on the graphics canvas
   ; :x, :y is the bottom-left corner of the button
   ; :text is the button's label
   to drawButtonAt :x :y :text
     setpencolor white fillRect :x :y buttonWidth buttonHeight
     setpencolor black setpensize 2 drawRect :x :y buttonWidth buttonHeight   
     SETLABELHEIGHT buttonLabelHeight
     penup
     setx sum :x (quotient (difference buttonWidth (LABELWIDTH :text)) 2)
     sety sum :y (quotient (difference buttonHeight buttonLabelHeight) 2)
     label :text
     end 

Table 1 provides documentation for the new/modified LABEL stuff.

Name Input(s) Description
 LABELWIDTH   thing  Outputs the number of turtle steps wide the text representation of the input would be if it was drawn on the graphics canvas wit LABEL.  The current font and label height are used to compute the amount.
 SETLABELFONT   number  Sets the font face and style of characters drawn on the graphics canvas with the LABEL command.
Number
Font
Face
Font
Style
Number
Font
Face
Font
Style
Number
Font
Face
Font
Style
0
Courier Plain
4
Sans
Serif
Plain
8
Serif Plain
1
Courier Bold
5
Sans
Serif
Bold
9
Serif Bold
2
Courier Italic
6
Sans
Serif
Italic
10
Serif Italic
3
Courier Bold
Italic
7
Sans
Serif
Bold
Italic
11
Serif Bold
Italic
 SETLABELHEIGHT   number  The height of capital letters the turtle draws on the graphics canvas with the LABEL command is set to an approximation of the input.  All other characters in the current font are drawn with heights proportional to capital letters.
Table 1

Three Flavors of mouseClicked and mouseMoved

Name Input(s) Description
 MOUSECLICKED     When a mouseClicked Event is received by the TG program, if it is the left-button and it is in the graphics canvas, TG invokes a user-defined procedure with the name MOUSECLICKED if one has been defined.
 MOUSECLICKED     xCor   yCor  Similar to MOUSECLICKED defined without inputs, but the location of the mouse at the time of the click is provided in an X-coordinate input and a Y-coordinate input.
 MOUSECLICKED    posSentence  Similar to MOUSECLICKED defined without inputs, but the location of the mouse at the time of the click is provided as a two-number sentence input. The first number is the X-coordinate and the last number is the Y-coordinate (see POS operator).
MOUSEMOVED   When a mouseMoved Event is received by TG, it performs a user-defined procedure named mouseMoved if one has been defined.  mouseMoved Events only happen when the mouse is in an active graphics canvas.
 MOUSEMOVED     xCor   yCor  Similar to MOUSEMOVED defined without inputs, but the location of the mouse at the time of the mouseMoved Event is provided in an X-coordinate input and a Y-coordinate input.
 MOUSEMOVED    posSentence  Similar to MOUSEMOVED defined without inputs, but the location of the mouse at the time of the mouseMoved Event is provided as a two-number sentence input. The first number is the X-coordinate and the last number is the Y-coordinate (see POS operator).

Directive Additions/Changes

Directives HELP, JLOGOFILES, PICTFILES, and PRINTPROCS now print their output to the CommandCenter in columnar format, as many as fit across the CommandCenter.

The VERSION directive prints TG's version number, the version number of the Java Virtual Machine (JVM), and the name and version number of the operating system.

A new directive, PWD, prints TG's current working directory - where it looks for stuff you load, like .wav files (audio clips), .bmp files (images), and .jlogo files (source code).

New Value: null

For additional compatibility with Java, a null value has been introduced.  All variables initially contain null, including all members of an ARRAY.  In comparison and assignment contexts, the word "null is now treated as a special case, like the words "true and "false in boolean contexts.

Finally...

A first pass at character file input and output is complete.  I'm holding off documenting it until I've written a few programs, just to make sure that what is provided meets the needs of typical programs.  So, stay tuned...

Many other minor changes, have been made.  A few bugs have been fixed.  Checkout details at:

Public Domain Mark
This work (BFOIT: Introduction to Computer Programming, by Guy M. Haas),
identified by Berkeley Foundation for Opportunities in IT (BFOIT),
is free of known copyright restrictions.