Tymless Tutorial: Data



   
  < locations

Shapes

 
affines >
 

Drawing

Control

Data

Reference

 

When you draw a line or polygon in Tymless, it doesn't appear directly onto the screen (unless you say otherwise). Instead Tymless adds it to a list which is only drawn at the end of the program, or when you explicitly say "paint the image". This allows you to further manipulate shapes after they have been created.

You can assign these shapes to variables. This does not remove the shapes from the list - all shapes are always on the list, unless you clear the list, in which case the shapes disappear completely. One shape can therefore be assigned to more than one variable. If you change its properties, any variable which refers to it will detect the changes. Shapes can also be copied, and the new copy is immediately added to the list.

There are two system variables which give you access to shapes. $lastshape always points to the last shape added to the list. $shapes holds an array of all shapes. They can be referred to by subscript.

do 20
   {} ;
end

ashape = $shapes_1   // the first shape
bshape = $shapes_#   // the last shape
cshape = $lastshape  // also the last shape

Shapes have a lot of system properties. You can change their appearance using .$border and .$fill. You can give them a new colour using .$c, or just change one part of their colour using .$r, .$g, .$b etc. You can make them invisible by setting .$visible to 0. You can access their corner points using .$^ which holds an array of locations (lines have two 'corner' locations at start and finish. Pixels and dots have one). You can change these locations directly using the array, e.g.

$lastshape.$^_2 = 3 by 4

Because the corners of a shape are locations, and therefore complex numbers, you can do arithmetic with shapes to transform them. This may seem a daunting business at first but a little experimentation soon starts to make it clearer.

As a guideline, adding a location to a shape will move the whole shape bodily in the same direction from the origin (0,0) as the location. The shape is not resized or rotated at all.

Multiplying a shape by a location may rotate the shape around the origin, and/ or shrink or expand the shape.

Now you can find out what the sine of a hexagon is!

// the sine of a hexagon
${}=6
;: 3 by 4
{}
sin $lastshape

Note that there is no need to assign the result of a shape transformation. The transformation occurs to the actual shape used in the expression.

   
  < locations
 
affines >