Tuesday, 27 August 2013

Barnsley Fern Fractal

When selecting an idea for this week's demo, I wanted to do something new and settled on the fern fractals. The Barnsley fern is a super simple algorithm that produces amazingly natural looking images. These look just like the ones in my garden!

The online demo is here (click on the canvas to draw a new fern) and the code is on GitHub.

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.

Saturday, 3 August 2013

This Week In Dart #7

The Dart Editor and SDK was updated to version r25630. Highlights include fixes and performance improvements to code completion, analysis improvements and updated Todo.MVC sample.

Seth Ladd's presentation to JAXConf was put online. Has he ever done a presentation not including kittens! :-)

Interested in Angular and Dart? James deBoer has written a skeleton project available on GitHub. This has a wonderful 3 (yes only 3) step README to get started.

VectorShapes describes itself as 'an App Bazaar for designers, artists and developers looking for different ways to incorporate web technology into their craft'. This site was built with Dart and SVG and is well worth a look.

Kevin Moore was interviewed by InfoQ on the subject of Dart. MP3 file and transcipt are available here!

Coming up soon on the blog... there will be another digestable HTML5 demo and a look at that game I have started to convert to Dart. Have a great week coding Dart!

Friday, 2 August 2013

Get 'With' It Dart! One Thing Dart Could Learn From VB.net

UPDATE : Turns out the cascade operator does work as I expect - my syntax was a bit off as only the final semi-colon is required! This works today - yippee! :

  crc
    ..beginPath()
    ..moveTo(ax,ay);

Thanks to those who provided me with such rapid feedback!

Dart has a great feature - the cascade operator - that helps construct a new or returned configured object fast.

query('#button')
    ..text = 'Ok'
    ..classes.add('Bold')

But oddly it doesn't seem to work if you have an existing reference:

  crc
    ..beginPath();
    ..moveTo(ax,ay);

This will give an error.

Consider the following Dart code snippet:

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

It would nice to have the cascade operator work this way or have a With ... End With statement (from VB.net) to use (I'll use curly brackets so it is C style) like so:

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

Before I raise a feature request, I'd love to hear what you think. It is a nice to have but I think it helps make it clearer and more consistent. Are you with me? :-)