Tuesday, 6 August 2013

Triangles And Bouncy Text

This is a reworking of an OpenGL example from the Pyglet library for Python. I have toned down the colours for this version - it was previously a Christmas demo.

The demo is online here and the code is here.

The canvas context is a good object to use the cascade operator with '..'. It soon becomes tedious to type crc.this, crc.that and crc.nextthing. Be careful not to fall for my mistake of adding a semi-colon after every method call!

  crc
   ..beginPath()  
   ..moveTo(ax,ay)  
   ..lineTo(bx,by)  
   ..lineTo(cx,cy)
   ..fill(); 

To generate the path of the text, the main function calculates a path of points stored in a list. This uses dart:math and the trigonometry functions. These work in radians, oddly there are not radian conversions build into this library. This is documented in this bug which also contains the code (a convenient copy&paste) to implement them.