Dart: Example of WebGL on Dart

My hacking attempts with webgl on dart has made me revert to using ‘dart:dom’. While I really enjoy ‘dart:html’, one might not be able to use some of the more important webgl methods. The reason would be the missing constructors on Float32Array, an issue has been filed. For now the following sample with code could help guide those excited to play with webgl on dart. Thank you Learning WebGL for the sample code work with.

Dart: fillstyle on cavnas

To be able to draw on canvas in Dart you need two things. A canvas element defined and a canvas rendering context to draw on. In this example we use a CanvasRenderingContext2D to fillstyle a set of rectangles with rgb colors of size x and y. Modified for Dart, mozilla developer example can be done the following way. Check a live example here.

    <canvas id="canvas" width="600" height="600"></canvas>
    <script type="text/javascript" src="CanvasFillstyleExample.dart.app.js"></script>
  draw() {
    var ctx = document.query('canvas').getContext('2d');
    for (var i=0;i<6;i++){
      for (var j=0;j<6;j++){
        ctx.fillStyle = 'rgb(' + (255-42.5*i).floor().toString() + ',' + 
                         (255-42.5*j).floor().toString() + ',0)';

Dart: CSS3 Slider Carousel

The slider carousel by html5rocks now comes with an example in dart. I may have loaded to many  images into the single page, might take a few seconds to load. The source code can be found on github. Dart provides a simpler way to deal with client side programming, cleaner syntax and simple access to the DOM. Go Dart!


Dart: Updated Dartium builds for Linux and Mac

Following the similar posts as before, you can get the latest Dartium builds for Mac OSX and 32bit Linux here. My public is can be found on pgp.mit.edu. Please contact me if you have any issues, only providing these until Dartium hits the prime time. Keep in mind that nothing is guaranteed to work at this point… but some stuff does.

wget http://dl.dropbox.com/u/33138127/dartium_macosx/Chromium.app.tar.gz
wget http://dl.dropbox.com/u/33138127/dartium_macosx/Chromium.app.tar.gz.sig
wget http://dl.dropbox.com/u/33138127/dartium_macosx/Chromium.app.tar.gz.md5
wget http://dl.dropbox.com/u/33138127/dartium_macosx/README.txt
gpg --verify Chromium.app.tar.gz.sig Chromium.app.tar.gz
md5sum -c Chromium.app.tar.gz.md5
wget http://gsdview.appspot.com/dart-editor-archive-continuous/latest/DartBuild-linux.gtk.x86.zip
wget http://dl.dropbox.com/u/33138127/dartium/dartium-linux-32bit-Release.tar.gz
wget http://dl.dropbox.com/u/33138127/dartium/dartium-linux-32bit-Release.tar.gz.sig
wget http://dl.dropbox.com/u/33138127/dartium/dartium-linux-32bit-Release.tar.gz.md5
wget http://dl.dropbox.com/u/33138127/dartium/README.txt
gpg --verify dartium-linux-32bit-Release.tar.gz.sig dartium-linux-32bit-Release.tar.gz
md5sum -c dartium-linux-32bit-Release.tar.gz.md5

Dart: Web terminal sample

I’ve always been impressed by the css/html5/javascript web terminals that show off the filesystem API. Now Dart has a sample web terminal with minimal implementation.


Simply add your command implementations to the Terminal.dart by adding commands to the CMDS list and providing functions to the matching switch statement.



With in the next day or so the dart-web-terminal should include an example with filesystem API in dart.

Dart: dart:builtin

dart:builtin are the runtime libraries available to the DartVM. They provide some of the more system level API you would expect such as streams I/O, filesystem I/O, basic TCP socket I/O, platform information, native process invocation.  Most of these class implementations do call “native”, which from the point of view of the DartVM means invoking native VM code. “native” tells the VM to look up in a list for the entry that maps to the following argument after “native”.



While Dart is still Alpha these builtin may not be written in stone, so try not to depend on them too much. They can and do provide you with some neat access to native functionality you would commonly need when written shell/system applications.

By including #import(‘dart:builtin’); you can view the builtin dart files from DartEditor. Currently the DartEditor might show  warnings when including this module but runtime should not be affected. The truth of the matter is, if you explicitly include ‘dart:builtin’ or not, it is still available to you from implicit inclusion in the DartVM.


The following should give an idea of what built in objects are accessible and how they may be used. The examples should not be considered best practices, just an idea of how you could use them and that they exist. The code is taken from a sample that can be found on Github


    Directory d;
    if (l.length >= 2) {
      d = new Directory(l[1]);
    } else {
      d = new Directory(".");
    d.dirHandler = (var dir) {
    d.fileHandler = (var file) {


    File f = new File(l[0]);
    if (!f.existsSync()) {
      print("Error: file does not exist");
    RandomAccessFile r = f.openSync(FileMode.READ);
    int length = r.lengthSync();
    List buffer = new List(length);
    int readLength = r.readListSync(buffer, 0, length);
    String s = new String.fromCharCodes(buffer);


    ChunkedInputStream chunkedInputStream = new ChunkedInputStream(f.openInputStream(), 16);
    List c = chunkedInputStream.read();
    while(c!=null) {
      StringBuffer sb = new StringBuffer();
      c.forEach((int b) {
        if (b.toRadixString(16).length == 1) {
        sb.add(" ");
      c = chunkedInputStream.read();


    File src = new File(arg[1]);
    File dest = new File(arg[2]);
    var srcStream = src.openInputStream();
    var destStream = dest.openOutputStream();



 Platform p = new Platform();


    Process ps = new Process.start('ps', []);
    StringBuffer messages = new StringBuffer();
    ps.exitHandler = (int status) {
    ps.stdout.dataHandler = () => _readAll(ps.stdout, messages);
    ps.stderr.dataHandler = () => _readAll(ps.stderr, messages);


    // initialize the server
    serverSocket = new ServerSocket(host, 0, 5);
    if (serverSocket == null) {
      throw "can't get server socket";
    serverSocket.connectionHandler = onConnect;
    print("accepting connections on ${host}:${serverSocket.port}");


    sendSocket = new Socket(host, serverSocket.port);
    if (sendSocket == null) {
      throw "can't get send socket";
    // send first 4 bytes immediately
    for (int i = 0; i < 4; i++) {
    // send next 4 bytes slowly
    new Timer.repeating((Timer t) {
      if (bytesSent == bytesTotal) {
        print("finished sending");
    }, 500);



<pre>    if (l.length >= 2) {
      try {
        milliSeconds = (Math.parseInt(l[1]).abs()*milliSeconds);
      } catch (BadNumberFormatException ex) {}
    timer = new Timer((var t) {
      print("\nTime elapsed on Timer");
    }, milliSeconds);

Dartium Mac OSX Build rev 117836

For those interested in trying Dartium on MacOSX, here is a build of Dartium from Dart’s bleeding_edge. I have just tested it enough to run hello world at the moment. I’d like to get feed back on how it runs for others if possible. 


wget http://dl.dropbox.com/u/33138127/dartium_macosx/Chromium.app.tar.gz
wget http://dl.dropbox.com/u/33138127/dartium_macosx/Chromium.app.tar.gz.md5
wget http://dl.dropbox.com/u/33138127/dartium_macosx/README.txt
md5sum -c Chromium.app.tar.gz.md5

It might be best to refer to this previous post for any additional information.