Tymless Tutorial: Drawing



   
  < irregular polygons

Colour

 
animation >
 

Drawing

Control

Data

Reference

 

Control of colour is one thing that makes Tymless special. You can manipulate the red, green and blue parts of a colour quite separately using the $r, $g and $b system variables. Each of these holds a value between 0 and 1, saying how much of that primary colour is used to make up the compound colour. For example, here is one way to draw a red square:

// a red square
$r=1
$g=$b=0
{}

You can access the current colour using the $c system variable, and use the rgb function to set a whole colour at once:

// a blue square!
$c=rgb(0,0,1)
{}

The value of these system variables really becomes apparent when you want to create gradients or other effects involving changes of colour:

// a gradient from blue to red
$c=rgb(0,0,1)   // the initial colour is pure blue
$border=0      
SquareCount=10  // the gradient is made of ten squares
{} ;            // draw a square and walk to the next position
do SquareCount  // start a loop
  $b=1-($r+=1/SquareCount)// adjust the red and blue colour parts
  {} ;          
end

You can also control the hue, saturation and brightness components of a colour using $h, $s and $v.

Hue represents the colour-wheel. Its value indicates the angle of the colour around the wheel (in radians). It takes values from 0 (red) to pi*2 (also red, being a full circle!). Values outside this range are equally acceptable, but the colours repeat.

Saturation means the 'colourfulness' of the colour. The less saturation the more insipid the colour. A saturation of 0 will be white or grey. The maximum saturation is 1.

Brightness is self-explanatory. A brightness of 0 means black, whatever the hue or saturation. The maximum brightness is 1.

// a square colour wheel!
$r=1 $s=1
$|=0
GridSize=101
RandomPoint= ??*GridSize by ??*GridSize
do GridSize
   do GridSize
      $h=!? RandomPoint
      {} ;
   end
   >;>;~
end

This program draws a grid of squares and colours them according to their direction from a random point within the grid. The grid is drawn using two loops. The random point is created using the random function ??. The direction from the random point is found using the query-direction function !?. The hue of each square is set to this direction on the colour-wheel.

Colours can also be assigned to variables, and manipulated via system properties.

 

   
  < irregular polygons
 
animation >