Tuesday, 22 December 2015

Get 'Dart By Example' for just $5!!

Packt are running a great offer with every single eBook and Video course Packt has ever created will be available on packtpub.com for just $5! Pick up my 'Dart By Example' eBook for only $5. They also have several other Dart titles available. Don't hesitate!

Wednesday, 25 November 2015

Moar Better Rainbows! - mcpi_dart 0.0.4 Minecraft and Dart

I recently purchased a Raspberry Pi 2 with the snazzy 'official' case, so it was time to dust off my old Dart Minecraft library for an update. TLDR : Moar Better Rainbows!

Screenshot from the PC version of Minecraft.

The setBlock method now takes an extra parameter for data which allows the use of color on blocks such as wool. This means the rainbow can now be drawn in better colours. Yay!

The getPos method now returns a list of int's so the rainbow is built close to the player's position in the game. You may need to spin around to see it. Unfortunately, the Rasperry Pi version of the API does not allow us to obtain the players direction of view so this will be the case with everything we build.

So what is next? I am starting to have fun building structures using this package. Hopefully feeding back a nice set of utility functions to mcpi_dart. Now that ARM builds of Dart are available, it is possible to run Dart on the Raspberry Pi itself so it would be great to get something running without a remote machine.

Have fun and please send screenshots of anything you build!

Thursday, 19 November 2015

Dart SDK and Dartium 1.13.0 Chocolatey Packages for Windows

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying the install version during installation.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.13.0
To verify you have the right version on your path.
dart --version

Dart VM version: 1.13.0 (Wed Nov 18 12:24:20 2015) on "windows_x64"

Command line installation:

choco uninstall dartium

choco install -y dartium  -version 1.13.0

Friday, 6 November 2015

Sprite Lifecycle - Simplegamelib Part Ten

This is the tenth part in an ongoing series where we will look at the package I am currently writing called simplegamelib. Development is usually a little ahead of the current blog post. The projects homepage is located here.

Ninjas have a tough life and often have a lot thrown at them at once. This sometimes involves painful objects. In a game, we need to check how each object is interacting with others in the game world. The projectiles will be in the SpriteGroup. Sadly these will cause the Ninja to die but we don't want the character just to suddenly vanish. We want a skeleton to appear (or an explosion in a game set in space). This is why the Sprite has both an alive property and a dying property.

import 'dart:html';
import 'package:simplegamelib/simplegamelib.dart';

Sprite player;
SpriteGroup fireballs = new SpriteGroup();
Game game = new Game("My Game", '#surface');

void main() {
  player = game.createSprite('images/ninjadude.png', 48, 48);
  player
    ..setDyingImage('images/deaddude.png')
    ..cyclesToDie = 1000;
  for (int i = 0; i < 5; i++) {
    var fireball = game.createSprite('images/fire.png', 24, 24);
    fireball
      ..movement = Movements.west
      ..x = 290 + i * 100
      ..y = 60
      ..speed = 3;
    fireballs.add(fireball);
  }

  game
    ..player.sprite = player
    ..renderer.liveBackground.setImageBackground('images/background.png')
    ..customUpdate = spriteDying;

  player
    ..position = new Point(10, 30)
    ..movement = new Point(0, 0);

  print('starting game...');
  game.start();
}

void spriteDying() {
  if (player.dying) return;
  List collisions = fireballs.detectCollision(player);

  collisions.forEach((Sprite fireball) {
    fireball.alive = false;
    fireballs.removeDead();
    game.player.sprite.dying = true;
  });
}

Next time, we will take a break and have a look at the Left-Right shoot-em-up I have been working on using simplegamelib!

Wednesday, 4 November 2015

Internet of Programmable Things - Kasper Lund

This introduction to IOT and Fletch (a new VM that runs Dart on embedded devices) was recorded at GOTO Copenhagen 2015. Very interesting!

Thursday, 29 October 2015

Last Few Days - Special Offer 'Dart By Example' - Get 50% Off The Ebook From Packt Pub

Just a few more days to go on this offer!

Special offer runs until the end of this month on the e-book 'Dart By Example'. Get your copy of the e-book with a massive 50% discount!

Monday, 26 October 2015

Collectibles - Simplegamelib Part Nine

This is the ninth part in an ongoing series where we will look at the package I am currently writing called simplegamelib. Development is usually a little ahead of the current blog post. The projects homepage is located here. There's been some refactoring going on, documentation being updated and general bug fixing. I have also started a Space Invaders/Galaxian game using the library though too soon to share!

This time we are looking at picking up items. A Collectible is a specialisation of the Sprite class that stores some extra information - the points and health delta (collectible items can have both a positive and negative effect!). The collectibles are added to the game by the createCollectibles function and the picking up in the collectibleDemo function.

If the Player's health or points change, we need to broadcast this message in order to update the game display. The function updateScorePanel is called by the Player class when one of these properties changes.

import 'dart:html';
import 'package:simplegamelib/simplegamelib.dart';

Sprite player;
AudioBank sounds = new AudioBank();
Game game = new Game("My Game", '#surface');

void main() {
  sounds.load('test', 'sounds/coin.mp3');
  player = game.createSprite('images/ninjadude.png', 48, 48);

  game
    ..player = new Player.withNotifications(updateScorePanel)
    ..player.sprite = player
    ..renderer.liveBackground.setImageBackground('images/background.png');

  createCollectibles();

  player
    ..position = new Point(0, 30)
    ..movement = new Point(0, 0);

  game.customUpdate = collectibleDemo;

  print('starting game...');
  game.setUpKeys();
  updateScorePanel(game.player);
  game.start();
}

void collectibleDemo() {
  List pickUps = game.collectiblesGroup.detectCollision(player);

  pickUps.forEach((Sprite pickup) {
    pickup.alive = false;
    game.collectiblesGroup.removeDead();
    sounds.play("test");
    game.player.apply(pickup);
  });
}

void createCollectibles() {
  Collectible heart = new Collectible.fromFilename('images/heart.png', 24, 24);
  heart
    ..position = new Point(100, 100)
    ..healthDelta = 15;

  game.collectiblesGroup.add(heart);

  Collectible diamond =
      new Collectible.fromFilename('images/diamond.png', 24, 24);
  diamond
    ..position = new Point(175, 100)
    ..scoreDelta = 1000;

  game.collectiblesGroup.add(diamond);
}

void updateScorePanel(Player p1) {
  DivElement statusPanel = querySelector("#gameStatus");
  statusPanel.innerHtml =
      "Health : ${p1.health}      Score : ${p1.score}";
}

Click here to see it in action. Use the cursor keys to pick up the objects.

Next time, we will look at Sprite's being hit by projectiles and expiring. Yikes!

Thursday, 22 October 2015

Dart SDK and Dartium 1.12.2 Chocolatey Packages for Windows

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying the install version during installation.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.12.2
To verify you have the right version on your path.
dart --version

Dart VM version: 1.12.2 (Wed Oct 21 07:10:52 2015) on "windows_x64"

Command line installation:

choco uninstall dartium

choco install -y dartium  -version 1.12.2

Tuesday, 20 October 2015

Special Offer 'Dart By Example' - Get 50% Off The Ebook From Packt Pub

Special offer runs until the end of this month on the e-book 'Dart By Example'. Get your copy of the e-book with a massive 50% discount!

Sunday, 18 October 2015

Obstacles - Simplegamelib Part Eight

This is the eighth part in an ongoing series where we will look at the package I am currently writing called simplegamelib. Development is usually a little ahead of the current blog post. The projects homepage is located here. There's been some refactoring going on, documentation being updated and general bug fixing.

This time we are looking making sprites solid to they don't just float over each other. This little ninja is going to hit a brick wall!

To achieve this, we set the obstacles property which is a SpriteGroup with anything the player is not allowed to walk over. The wall Sprite is created like any other and added to this group. That's it!

  Game game = new Game("My Game", '#surface');
  SpriteGroup walls = new SpriteGroup();
  player = game.createSprite("images/ninjadude.png", 48, 48);
  wall = game.createSprite("images/brick.png", 100, 100);

  game.player.sprite = player;
  walls.canvas = player.canvas;
  walls.add(wall);

  player
    ..position = new Point(0, 10)
    ..movement = Movements.none
    ..speed = 3
    ..obstacles = walls;

  wall..position = new Point(150, 0);

  print('starting game...');
  game
    ..setUpKeys()
    ..start();

Click here to see it in action. Use the cursor keys to bump into the wall.

Next time, we will look at creating some collectible items.

Friday, 16 October 2015

Sprite Speed and Limits - Simplegamelib Part Seven

This is the seventh part in an ongoing series where we will look at the package I am currently writing called simplegamelib. Development is usually a little ahead of the current blog post. The projects homepage is located here.

We have already seen how to get sprites on the screen moving about. Sometimes it is useful to speed up a particular Sprite, whilst this could be done with setting a higher movement value, it is also possible to set a speed value that acts as a multiplier. This is useful, for example, in a game where the Player picks up a speed up bonus. Once the power-up has run out the speed can be set back to 1 and we don't need to worry about direction either.

  Game game = new Game("My Game", '#surface');

  player = game.createSprite("images/ninjadude.png", 48, 48);
  dude = game.createSprite("images/ninjadude.png", 48, 48);

  player
    ..position = new Point(0, 10)
    ..movement = Movements.east
    ..speed = 3;

  dude
    ..position = new Point(10, 10)
    ..movement = new Point(1, 1)
    ..limits = new Rectangle(0, 0, 133, 133);

  print('starting game...');

  game.start();

The other aspect we want to address is limiting a Sprite's position on the screen. Imagine a Space Invaders type game where the player's sprite is restricted to the lower portion of the screen. To achieve this for one of our ninja's, we set the limit property to desired rectangular area.

Click here to see it in action. Hit reload to start again. One Ninja will zoom off never to be seen again. The other will head diagonally down the screen until it hits an invisible wall. These things happen to ninjas.

Next time, we will look at making sprites solid to they don't just float over each other.

Wednesday, 14 October 2015

Unit Testing - Simplegamelib Part Six

In this post, we take a step back and look at how the Simplegamelib is tested. Sorry no ninjas this time!

The awesome test package allows unit tests to be created and run. For example:

    test('Check empty', () {
      SpriteGroup sg = createSpriteGroup(4);
      expect(sg.empty, equals(false));
      sg.reset();
      expect(sg.empty, equals(true));
    });

The unit tests (20 or so) can be found on GitHub. In contrast to other command line apps, it can run code that imports dart:html which saves splitting of packages to remove browser dependencies. This is hugely useful and a real plus point for Dart Unit Testing. It has certainly helped in the development of this little package!! :-)

These can be run using the command:

pub run test .\test\simplegamelib_test.dart -p dartium

Providing the system has a binary called dartiumon the path. The Dart content shell is another possibility but as dartium worked first time I have tried anything else locally.

This is all great for running unit tests when I want to but how about getting them running every time a change goes into the GitHub repository? Turns out the continuous integration service Travis CI supports Dart. The claim to be set up in minutes turns out to be true! All you need to add is a small YML file to the GitHub repository and it will monitor the repo for changes and even email you the results. The current implementation is focussed on the old unittest package but I hear it is to be move to test very soon!

language: dart
dart:
  - stable
  - dev
sudo: false
with_content_shell: true
before_install:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
script: pub run test -p content-shell -p firefox

This time we use the content shell and firefox. As a bonus, we can run the tests on Dart STABLE and DEV.

You can see the test reports for the Simplegamelib package here.

Next time, we will get back to a traditional demo and look at adding some speed to our sprites.

Saturday, 10 October 2015

Background and Sound - Simplegamelib Part Five

This is the fifth part in an ongoing series where we will look at the package I am currently writing called simplegamelib. Development is usually a little ahead of the current blog post. The projects homepage is located here.

This demo is our most complicated so far. First change is that the white background is replaced by an image. The ninja will still be movable via the cursor keys but will be able to pick up the collectible hearts (ninja's need love too!) which emit a little sound when collected.

To set the background, the Renderer must be told of the image to be used. The Audiobank class loads a mp3 file which is given the name 'test' which is used to request that sound to play later on. Three heart sprites are created and added to the collectables list in the Game object. In the update method, the player is checked for collision with any of the hearts. If there is a collision, the heart is set to alive = false, the SpriteGroup is cleared of dead entries and the sound is played.

Remember Dartium does not play MP3 files so run from another browser!

Sprite player;
AudioBank sounds = new AudioBank();
Game game = new Game("My Game", '#surface');

void main() {

  sounds.load('test', 'sounds/coin.mp3');
  player = game.createSprite('images/ninjadude.png');
  game.player.sprite = player;
  game.renderer.liveBackground.setImageBackground('images/background.png');

  for (int i = 0; i < 3; i++) {
    Sprite heart = new Sprite.fromFilename('images/heart.png');
    heart
      ..position = new Point(100 + (i * 75), 100)
      ..width = 24
      ..height = 24;
    heart.updatePos();
    game.collectablesGroup.add(heart);
  }

  player
    ..position = new Point(0, 30)
    ..movement = new Point(0, 0)
    ..width = 48
    ..height = 48;

  game.customUpdate = soundDemo;

  print('starting game...');
  game.setUpKeys();
  game.start();
}

void soundDemo() {
  List pickedHearts = game.collectablesGroup.detectCollision(player);

  pickedHearts.forEach((Sprite heart) {
    heart.alive = false;
    game.collectablesGroup.removeDead();
    sounds.play("test");
  });
}

Click here to see it in action.

Next time, we will look behind the scenes at the unit testing for this package!

Thursday, 8 October 2015

Sprite Keyboard Movement - Simplegamelib Part Four

This is the fourth part in an ongoing series where we will look at the package I am currently writing called simplegamelib. Development is usually a little ahead of the current blog post. The projects homepage is located here.

This time we will be able to move the ninja around using the arrow/cursor keys. Game controls are specific to each game but for getting started simplegamelib provides basic movement of the player sprite. We have to tell the Game object which sprite is the player for this to work. When writing a larger game is is likely that you would sub-class or replace entirely the Game object.

Sprite player;
Game game = new Game("My Game", '#surface');

void main() {
  player = game.createSprite("images/ninjadude.png");
  game.player.sprite = player;

  player
    ..position = new Point(0, 30)
    ..movement = new Point(0, 0);

  print('starting game...');
  game.setUpKeys();
  game.start();
}

Click here to see it in action.

Next time, we will look at adding a background and some sound to liven things up!

Monday, 5 October 2015

Sprite Priority - Simplegamelib Part Three

This is the third part in an ongoing series where we will look at the package called simplegamelib

This time we will create a little forest of trees to walk down the middle of. Two trees will be in the foreground and two in the background. This is achieved by placing the ninja sprite in the SpriteGroup after the background sprites but before the foreground. When the ninja goes off screen, the order of the sprites is reversed by calling the reverse method. The display will not look as good the second time around as the foreground will be drawn first but it does clearly show the order the drawing of the sprites SpriteGroup.

Sprite player;
Sprite backTree, backTree2;
Sprite foreTree, foreTree2;
Game game = new Game("My Game", '#surface');

void main() {

  backTree = game.createSprite("images/ftree.png");
  backTree2 = game.createSprite("images/ftree.png");
  player = game.createSprite("images/ninjadude.png");
  foreTree = game.createSprite("images/ftree.png");
  foreTree2 = game.createSprite("images/ftree.png");

  player
    ..position = new Point(0, 30)
    ..movement = Movements.east;

  backTree.position = new Point(200, 20);
  backTree2.position = new Point(20, 20);

  foreTree.position = new Point(180, 60);
  foreTree2.position = new Point(40, 60);

  game.customUpdate = priorityDemo;
  print('starting game...');

  game.start();
}

void priorityDemo() {
  if (player.x > 333) {
    player.x = -50;
    game.spriteGroup.reverse();
  }
}

Click here to see it in action.

Next time, we will look at adding some keyboard controls so we can start getting interactive!

Friday, 2 October 2015

Sprite Collisions - Simplegamelib Part Two

This is the second part in an ongoing series where we will look a Dart package I am developing for simple Canvas based sprites games. I have written a couple of little games in Dart and always thought it would be an idea to split off all the general code into a reusable package.

The library is called simplegamelib and is heavily inspired by PyGame. The source is on GitHub here and the package is on pub. My personal aims are to write a Space Invaders type game and have really understandable library so it can be used to learn Dart. The code (so far!) is on GitHub and the project's homepage is here on blogger.

This time we will create a simple scene and again have a familiar looking sprite move from one side of the screen to the other. This time they will bump into another ninja so we add another sprite.

void main() {
  Game game = new Game("My Game", '#surface');

  player = game.createSprite("images/ninjadude.png");

  player
    ..position = new Point(0, 10)
    ..movement = Movements.east;

  dude = game.createSprite("images/ninjadude.png");

  dude..position = new Point(200, 20);

  dude.height = 48;
  dude.width = 48;
  player.height = 48;
  player.width = 48;

  game.customUpdate = collisionDemo;

  print('starting game...');

  game.start();
}

// Custom detection routine.
void collisionDemo() {
  document.body.style.backgroundColor =
      player.detectCollision(dude) ?  "#ffcc00" : "cornflowerblue";
  if (player.x > 333) {
    player.x = -50;
  }
}

This time around we create another sprite and both are set to a width and height of 48 pixels. This area for each ninja is used to detect whether they overlap. This type of collision detection can be used in all sorts of games. We take advantage of a hook in the Game object customUpdate that is called after each update. Here we can check if the two sprites collide and change the colour of the page accordingly. If the moving player sprite goes out of view it is set back to just off screen on the left. Click here to see it in action.

Next time, we will look at Sprite drawing priority!

Thursday, 1 October 2015

Simple Sprite Based Web Games In Dart - Part One

This is a new series where we will look a Dart package I am developing for simple Canvas based sprites games. I have written a couple of little games in Dart and always thought it would be an idea to split off all the general code into a reusable package.

The library is called simplegamelib and is heavily inspired by PyGame. The source is on GitHub here and the package is on pub. My personal aims are to write a Space Invaders type game and have really understandable library so it can be used to learn Dart. The code (so far!) is on GitHub and the project's homepage is here on blogger.

Yes it is time to get around to our 'Hello World'. We will create a simple scene and have a familiar looking sprite move from one side of the screen to the other.

import 'dart:html';
import 'package:simplegamelib/simplegamelib.dart';

void main() {
  Game game = new Game("My Game", '#surface');
  Sprite player = game.createSprite("images/ninjadude.png");

  player
    ..position = new Point(0, 10)
    ..movement = Movements.east;
  print('starting game...');

  game.start();
}

As you can see it is easy to get started with just a few lines of code. Click here to see it in action. Hit reload to start again.

Next time, we will look at adding more than one sprite and collision detection!

Tuesday, 29 September 2015

'Dart By Example' Book Is Available!

I am delighted to say that 'Dart By Example' is out now! You can find it on Packt, Amazon USA and Amazon UK.

Who This Book Is For
If you are a front- or back-end web developer who is looking to build complex full-featured web applications without the quagmire of disconnected JavaScript frameworks, this book is a practical walkthrough of substantial applications that will have you and your team coding Dart in a productive manner.
This book will give you a compiled, optional typed, scalable environment to rapidly develop applications. As Dart was designed to be familiar, any developer with even a small amount of knowledge of JavaScript or another programming language will be at home with the language immediately and will be coding quickly.

Friday, 25 September 2015

Introduction To Dart In 8 Minutes

"In this video, Faisal, Dart GDE will answer most common questions of Dart, like what is Dart for and how hard it is. Then he will show you the easy way to get stared with Dart."

Tuesday, 22 September 2015

Dart POW - ( Package Of The Week) #11 : colorful

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

colorful is a package that helps creates 'a List of equally distant random colors'. Handy if you need a palette and you know I like some colour on this blog!


  var output = querySelector('#output');
  WarmPalette wp = new WarmPalette(10);
  List cl = wp.colors();

  cl.forEach((HexColor color) {
    var line = new HeadingElement.h1();
    line
      ..text = 'Dart is Awesome!'
      ..style.color = '#ffffff'
      ..style.backgroundColor = color.toCssString()
      ..style.margin = '15px'
      ..style.padding = '2px';
    output.append(line);
  });

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

Saturday, 12 September 2015

Dart POW - ( Package Of The Week) #10 : irc

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

The irc package is a 'one-stop shop for all your irc needs in Dart'. IRC (Internet Relay Chat) has been around a long time and is still a great way to connect. There are a number of IRC packages on pub so be sure to check them all out.

This example is taken straight from the irc docs:

import "package:irc/client.dart";

// This stores our configuration for this client
var config = new Configuration(host: "irc.esper.net", port: 6667, nickname: "DartBot", username: "DartBot");
// "Primary" IRC class
var client = new Client(config);

main() {
  // Register an onReady event handler
  client.onReady.listen((event) {
    // Join a channel
    event.join("#directcode");
  });

  // Register an onMessage event handler    
  client.onMessage.listen((event) {
    // Log any message events to the console
    print("<${event.target.name}><${event.from.name}> ${event.message}");
  });

  // Connect to the server
  client.connect();
}

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

Thursday, 10 September 2015

Learn Dart In One Video - YouTube Link

Derek Banas has done a great job on this video. Good to see the Dart Chocolatey packages in action too!

Wednesday, 9 September 2015

Dart SDK and Dartium 1.12.1 Chocolatey Packages for Windows

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying the install version during installation.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.12.1
To verify you have the right version on your path.
dart --version

Dart VM version: 1.12.1 (Tue Sep 08 04:22:07 2015) on "windows_x64"

Command line installation:

choco uninstall dartium

choco install -y dartium  -version 1.12.1

Tuesday, 1 September 2015

Dart SDK and Dartium 1.12.0 Chocolatey Packages for Windows

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying the install version during installation.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.12.0
To verify you have the right version on your path.
dart --version

Dart VM version: 1.12.0 (Mon Aug 31 03:21:50 2015) on "windows_x64"

Command line installation:

choco uninstall dartium

choco install -y dartium  -version 1.12.0

Monday, 24 August 2015

Coming Soon - 'Dart By Example' Book!

Yes this blog has been a little quiet lately, apart from Chocolatey updates because I have been working on a special Dart project. I am excited to announce that 'Dart By Example' will be published September 2015 by Packt Publishing. More details soon!

After the book, I hope to bring the blog back to life with some more fun demos along the lines of some of the games posted here already! Have fun.

Friday, 14 August 2015

Dart SDK and Dartium 1.11.3 Chocolatey Packages for Windows

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying the install version at the install.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.11.3
To verify you have the right version on your path.
dart --version

Dart VM version: 1.11.3 (Mon Aug 03 04:44:18 2015) on "windows_x64"

Command line installation:

choco uninstall dartium

choco install -y dartium  -version 1.11.3

Thursday, 25 June 2015

Dart SDK 1.11.0 Chocolatey Packages for Windows

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying it at the install.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.11.0
To verify you have the right version on your path.
dart --version

Dart VM version: 1.11.0 (Wed Jun 24 06:44:48 2015) on "windows_x64"

Wednesday, 24 June 2015

Dart POW - ( Package Of The Week) #9 : dart_feed

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

dart_feed is a simple RSS 2.0 feed reader library. It is pretty easy to use - here's my simplified version of one of the examples.

library DartFeed.example;

import 'dart:io';
import 'package:dart_feed/dart_feed.dart';

List webFeeds = [
  "http://divingintodart.blogspot.com/feeds/posts/default?alt=rss"
];

main() {
  
  FeedParser parser = new FeedParser();
  parser.stream.listen(printFeed);
  
  for (var feed in webFeeds) {
    parser.fromUri(Uri.parse(feed));
  }
}

void printFeed(Feed feed) {
  print(feed.title);
  for (var item in feed.items) {
    stdout.write("\t ${item.title}");
    if (item.title == "") print(item.description);
    else print("");
  }
}

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

Monday, 22 June 2015

Get 80% off a Book from Packt including Dart titles

Here's a way to pick up a Dart or other book at a discount but move fast! Packt Publishing are running a 'Skill Up Survey' to keep in touch with the development community. Check out their selection of Dart books.

In return, you will receive an 80% discount on your next Packt purchase and the survey results will be shared in July!

Thursday, 18 June 2015

Dart POW - ( Package Of The Week) #8 : rpi_gpio

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

rpi_gpio is a Dart library for accessing the Raspberry Pi GPIO pins.

Code snippet:

...
main() async {
  Gpio.hardware = new RpiHardware();
  var gpio = Gpio.instance;
  var pin = gpio.pin(1, output);
  for (int count = 0; count < 5; ++count) {
    pin.value = 1;
    await _delay(1000);
    pin.value = 0;
    await _delay(1000);
  }
}
...

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

Friday, 12 June 2015

Chocolatey Dart SDK Packages for Windows 1.10.1

Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

Chocolatey still has a large moderation backlog - however you can install unmoderated versions by specifiying it at the install.

Command line installation:

choco uninstall dart-sdk

choco install -y dart-sdk  -version 1.10.1
To verify you have the right version on your path.
dart --version

Dart VM version: 1.10.1 (Mon May 11 14:08:44 2015) on "windows_x64"

Thursday, 4 June 2015

Programming Minecraft with Dart - mcpi-dart v0.1

The Minecraft phenomena has been an amazing success with game players and coders. A version was released for the Raspberry Pi computer that allowed programming via a Python wrapper. The same programming API was added to regular Minecraft servers via Raspberry Juice.

Of course, it would be better if you could program Minecraft in Dart... and now you can! I have put up a first version of mcpi-dart on GitHub. An early version so please be kind, try it out and provide feedback. Make sure you Dart is up to date as it requires async.

This entire project was inspired by the awesome book 'Adventures in Minecraft' by Martyn O'Hanlon.

Let's take a run through the main.dart demo sample.

Connecting to the server

Make sure the IP is pointing to your Minecraft server running Bukkit & Raspberry Juice. This was tested on a slightly older Minecraft 1.6.4 on Bukkit Server with Raspberry Juice.

  mci = new Minecraft();
  await mci.connect("192.168.0.110", 4711);

Chat Messages

Talkie talkie! Easy one this.

mci.chat("Dart is awesome!");

Placing Blocks

This is what it is all about. Let's get building!

blockDemo() {
  print("Block Demo Start");
  for (int i = 0; i < 99; i++) {
    mci
      ..setBlock(1, i, 0, Block.GOLD_BLOCK)
      ..setBlock(3, i, 0, Block.DIAMOND_BLOCK)
      ..setBlock(5, i, 0, Block.WOOL);
  }
  print("Block Demo End");
}

Getting the Player's Position

This method is a little trickier as we have to await a response.

  var s = (await mci.getPos());
  print(s);

Building a Rainbow

Just for fun :-)

  print("Starting rainbow...");
  var colors = [
    Block.BRICK_BLOCK,
    Block.GOLD_BLOCK,
    Block.MELON,
    Block.DIAMOND_BLOCK,
    Block.SANDSTONE,
    Block.GLOWSTONE_BLOCK,
    Block.LAPIS_LAZULI_BLOCK
  ];

  var height = 80;

  for (int x = 0; x < 128; x++) {
    for (int ci = 0; ci < colors.length; ci++) {
      double y = math.sin((x / 128.0) * math.PI) * height + ci;
      mci.setBlock(x - 64, y.round(), 0, colors[(colors.length - 1) - ci]);
    }
  }
  print("Built rainbow.");

Next steps

  • Some blocks require data rather than just an ID.
  • Get package onto Pub.
  • More Demos!

  • Monday, 1 June 2015

    Diving Into Dart HTML5 Demo Collection

    I have been wanting to gather all the HTML5 demos form this blog into one page for a while now. Thankfully the awesome Google+ has come up with its Collections which helps me share it with you.

    Enjoy!

    Wednesday, 13 May 2015

    Dart POW - ( Package Of The Week) #7 : bwu_docker

    Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

    bwu_docker is a provides a typed interface to the Docker REST API and deserializes JSON response to Dart classes.

    Code snippet:

    ...
      // initialize the connection to the Docker service
      final conn = new DockerConnection('localhost', dockerPort);
      await conn.init();
    
      // create a container from an image
      CreateResponse created = await conn.createContainer(
          new CreateContainerRequest()
        ..image = 'busybox'
        ..hostConfig.logConfig = {'Type': 'json-file'});
    ...
    

    Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

    Tuesday, 12 May 2015

    This Week In Dart #27

    The Dart on Android 'experiment' Sky continues to get coverage in the tech press. whatech.com. More coverage at TechWorm.

    Joel Trottier-Hebert has an interesting two part write up on the recent Dart Developer Summit. Day One and Day Two

    Speaking of the summit, the following video 'Sky: An Experiment Writing Dart for Mobile' is the most popular so far (66000+), going by YouTube views.

    A document bubble up on the internet discussing Dart's Macro Language.
    "You won't find it in the language specification, but Dart supports macros."
    Interesting reading!

    Finally the Dev channel for the Dart Editor released 1.11 with the following announcement: "We have shipped the first dev channel release of 1.11. As already announced, we are sunsetting the editor and the newly released version 1.11 does not contain the editor . Existing dev channel editor users will be updated to the stable channel 1.10.1 release, which will disable auto update."

    Saturday, 9 May 2015

    Chocolatey Dart Packages for Windows 1.10

    Chocolatey is a package manager for Windows similar to Linux's apt-get, based on Microsoft's Nuget tool and Powershell scripting language. It works from the command-line and from a WPF GUI interface.

    Recently I have recently taken over as maintainer of the Dart packages, and thanks to some timely pull requests and help from the Chocolatey community, the packages are now much more up to date. The Chocolatey moderation queue is around 2 weeks at the moment, however you can click on 'All Versions' to see the 1.10 releases.

    Packages:

  • Dart Editor
  • Dart Sdk
  • Dartium
  • N.B. The Dart Editor includes the SDK + Dartium.

    Command line installation:

    choco install -y DartEditor  -version 1.10.0
    choco install -y dart-sdk  -version 1.10.0
    choco install -y dartium  -version 1.10.0
    

    The Dart Editor package will probably be deprecated after the 1.11 release with the Editor being discontinued (officially at least).

    One other idea I am considering is a non-Chocolatey install/update script. Feedback, comments and suggestions welcome!

    Thursday, 7 May 2015

    Dart POW - ( Package Of The Week) #6 : uix

    Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

    uix is a library to build Web User Interfaces in Dart inspired by React.

    You can play the one the examples Minesweeper.

    Friday, 1 May 2015

    This Week In Dart #26

    Dart Developer Summit 2015

    The Dart Developer Summit 2015 took place at the Googleplex and was streamed online. I only caught some of the content but some great talks and lots of news about Dart in the keynotes.



    Farewell Dart Editor (Soon)

    It appears it is time to bid goodbye to the venerable Dart Editor. Since the code analyzer was externalized, the editor is largely just a shell. The Dart team is putting its weight behind DartPad for beginners and the WebStorm for intermediate to professional. This is just breaking so not all details are available. Plugin support for Eclipse will continue (probably my preferred choice).

    Read more on the Official Blog.

    Dart 1.10.0 Released

    Check out the new release notes on GitHub. This is new format seems to be rolling as there are some 1.11 details on there too. Either auto-update or go to the Downloads page.

    Monday, 27 April 2015

    Dart POW - ( Package Of The Week) #5 : timeago

    Sorry for the lack of posts - April has been busy! A combination of holidays, work deadlines and writing a book has made blogging impossible. The good news is that it is a Dart book - more details as I can share them!

    Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

    timeago is a Dart library for creating fuzzy timestamps, such as "15 minutes ago". Great for human friendly labeling of dynamic interfaces.

    import 'package:timeago/timeago.dart';
    
    main() async {
        TimeAgo time = new TimeAgo();
        int current = new DateTime.now().millisecondsSinceEpoch;
        
        print(time.timeAgo(current - (15 * 60 * 1000))); // 15 minutes ago
        
        //change locale
        await time.changeLocale("es");
        
        print(time.timeAgo(current - (15 * 60 * 1000))); // hace 15 minutos
    }
    

    Try out the live demo here.

    Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

    Friday, 3 April 2015

    Dart POW - (Package Of The Week) #4 dart-reddit

    Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

    reddit is a library for Dart that allows read-only API access to the popular link sharing site Reddit.

    The following example fetches the latest links from the Dart sub-reddit.

    import "package:reddit/reddit.dart";
    import "package:http/http.dart";
    import 'dart:convert';
    
    main() {
      
      Reddit reddit = new Reddit(new Client());
    
      reddit.sub("dartlang").top("month").listen((result) {
    
        Map data = JSON.decode(result.toString());
        List Titles = data["data"]["children"];
        Titles.forEach((headline) => print(headline["data"]["title"]));
    
      });
    }
    
    
    

    Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

    Sunday, 29 March 2015

    This Week In Dart #25 - Dart 1.9 and Chrome Dart VM Special

    Dart 1.9: 'The release you’ve been await-ing for' - was released. This is the biggest release of Dart since 1.0. Highlights include async and await keywords, enums, an isolates API, a new server implentation of the Dart Analyzer, an accelerated regular expression engine and a new source code formatter. For full details see the release notes.

    The significant release of Dart was overshadowed somewhat by the strategic decision not to proceed with merging the Dart VM into Google Chrome. This was covered in the post Dart for the Entire Web. The blog post most significant statement is:

    In order to do what's best for our users and the web, and not just Google Chrome, we will focus our web efforts on compiling Dart to JavaScript.

    Also revealed is that Google Ads, the core of Google's advertising business, is committed to Dart as are other internal customers.

    The Dart VM has a future though, as I tweeted this week:

    The Dart VM story was covered in the major news outlets.

    Reception to this news has been understandably mixed, with a lot of questions being asked. The strategy makes Dart's appeal wider overcoming some of the 'Chrome only' perception. This change will free the VM from the web browser restriction and complexity. If nothing else it frees up a huge amount of effort for other features. With customers like Googe Ads, Dart is clearly a success without the VM in the browser and that compelling story can be pushed further forwards.

    The landscape of web scripting has move forwards since the Dart project was initiated. It has contributed to the debate and was never a replacement for JavaScript which was always going to be part of the web and constantly improving. More plans and information is likely to emerge at next month's Dart Developers Summit.

    Finally, from Damon Douglas, a great example of Dart playing Tic Tac Toe in two browsers using Polymer, and Google Drive Realtime API tictactoe.dart

    Wednesday, 25 March 2015

    Dart POW - ( Package Of The Week) #3 : dnd Drag and Drop

    Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

    dnd is a package for creating Drag and Drop for Dart web apps with mouse and touch support.

    Make sure you check out cool live demos!

    Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

    Sunday, 22 March 2015

    This Week In Dart #24

    Top story this week is the availability of the release candidate for version 1.9 which is available on the DEV Channel. This is closely followed by the opening of registration for the first Dart Developer Summit (April 28-29) - should be a great couple of days of Dart Sessions which will be streamed and recorded.

    A new article appeared on the ACM website, with details of the new async and generator features. This gets quite involved but is a good read!

    The Dart Enhancement Proposals repository has grown already with some great ideas, for example Generic Methods in Dart.

    Jana Moudrá has an interesting post on two Dart packages for sortable lists & drag and drop.

    Finally, Dart Pad gained a very important feature - code completion!

    Friday, 20 March 2015

    Copper Bar Animation Atari/Amiga 16 bit Style

    It has been sooo long since there was a frivilous colourful demo on this blog! Here is a fun throwback to the 16bit era of home computing.

    As usual there is a LIVE DEMO and the code is available on GITHUB. Enjoy!

    Thursday, 19 March 2015

    Dart POW - (Package Of The Week) #2 : wsk_angular - WSK Material Style for Angular + Dart

    Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

    wsk_angular is an implementation of Material Design in AngularDart with Googles Web Starter Kit. The package is in BETA, and there are some interesting samples to try out of controls, themes and layouts.

    Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

    Sunday, 15 March 2015

    This Week In Dart #23

    Dart Pad (Alpha) appeared this week on the DartLang website. It lets you write and run Dart/HTML/CSS on a web page. It is impressively fast and I can see it as a very useful tool for trying things out.

    The DartLang site carried some details from TC52 - which discussed 'discussed a number of additional language features for Dart - including async, tear-offs and null-aware operators'. Also launched this week is the Dart Enhancement Proposals repository - 'A DEP is a detailed, concrete proposal to change part of the core Dart platform. "Platform" usually means the Dart language itself, but DEPs may also apply to core libraries or other tools that ship with the Dart SDK'.

    Google's Anders Sandholm released a set of slides titled 'Speed and programmer productivity' which reviewed Dart in 2014. As well as mentioning internal projects and external projects using, it mentions Dart being targetted for mobile apps. Very exciting news!

    Finally, the Dart 'Game of Life Meme' is still going! Here's and interesting implementation by Jimmy Forrester-Fellowes.

    Thursday, 12 March 2015

    Dart POW - ( Package Of The Week) #1 : modern_charts

    New feature for the blog - Dart POW! A weekly look at an interesting Package on pub.dartlang.org

    modern_charts is a great canvas based graphs package with support for Bar, Gauge, Line, Pie/Donut and Radar graphs.

    The API is nice and straightforward too - didn't take long for me to create a LineChart:
    
    import 'dart:html';
    import 'package:modern_charts/modern_charts.dart';
    
    void main() {
    
      DataTable table = new DataTable(
     [['Categories', 'Bears', 'Giraffes', 'Rabbits'],
      ['Monday', 12, 23, 25], ['Tuesday', 23, 24, 26],
      ['Wednesday', 24, 23, 21], ['Thursday', 44, 25, 21],
      ['Friday', 23, 24, 22], ['Saturday', 25, 10, 24],
      ['Sunday', 24, 12, 28]]);
    
      Map options = {
        'colors': ['#cbcbcb', '#00aa00', '#990000'],
        'series': {
          'labels': {
            'enabled': true
          }
        }
      };
    
      LineChart chart = new LineChart(document.body);
      chart.draw(table, options);
    
    }
    
    

    Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

    Tuesday, 10 March 2015

    Dart Alive! - Part 2 : Google Using Dart

    Last time, we had a look at 10 sites and companies that are using Dart. This time we take a look at Google and how they use Dart. Of course, this will only cover external sites - I (sadly) have no secret inside knowledge of what is going on in the Google-plex and. like most companies, the more interesting ideas will be kept under wraps! So we must assume that this list is actually a lot longer :-)

    Google Internal Tools

    Who Uses Dart gives us a little glimpse of internal use of Dart.

  • Google internal customer support tool Built with Polymer.dart.
  • Google internal tool for marketing Built with AngularDart.
  • Non-Public Websites

  • Adwords for video - Built with AngularDart, this help advertisers manage campaigns.
  • Public Websites

  • Google Express - Built with AngularDart, this app manages driver and courier logistics.
  • Google fiber - High speed internet roll out.
  • Issue Mover for GitHub
  • Dart Lang unsurprisingly Dart is written (partly) in Dart as are many tools.
  • Google Elections used Dart for an Election results application (German and Brazilian elections) but this is not currently online. Hopefully it will reappear for the UK General Election!

    Very interesting to Dart being used on high demand sites such as Election results and Google's core business of advertising.

    Next time we will take a look at notable Open Source projects written with Dart!

    Saturday, 7 March 2015

    This Week In Dart #22

    It has been quite a while since the last TWID! It has been an interesting week for Dart so a good chance to kick it off again. Watch out for more weekly features on the blog.

    The journey to 1.9 continues and it is taking a bit longer than usual - Kevin Moore explains why and the new features. Kevin has also commented on the announcement that the Angular 2.0 project is switching to Typescript in the wonderfully titled post Angular.ts.js.at.dart.wtf.

    You can try out 1.9 now by using the unstable channel for Dart. Two features I am looking forward to hitting stable are the improved analyser and an improved code formatter. It's great when the tools are working WITH you!

    Hacker News has a great discussion thread for Q+A's on the new Dart Enhancement Proposals.

    Finally, catching up with some slightly older news, Dart Designer has been released. - "Graphical tooling based on Eclipse Sirius for the Dart programming language." - Check out the video below.

    Thursday, 5 March 2015

    Procedural Generation : Part Seven : World Data Structure Optimisation

    The next version of Dart (1.9) will have some optimisations for the Map class. A discussion about this on the mailing list made me think of the Map used for the Dungeon demo. Dart currently has no 'real' 2D arrays so a simple map was used with a string key of the x and y co-ordinates. Creating and joining those strings takes a bit of work, so perhaps a List of Lists would be a better way. Let's use the Stopwatch class and see if we get an improvement.

    
    class block{}
    class point{ int x; int y; point(this.x,this.y);}
    
    main() {
      Map testMap = new Map();
      List testLol = new List();
      List dataPoints = new List();
      Stopwatch watch;
    
      print("Set up maps.");
      for(int i=0;i<100;i++)
      for(int j=0;j<100;j++){
        testMap["$j-$i"] = new block();
        dataPoints.add(new point(j,i));
      }
    
      print("Set up list of lists.");
      for(int i=0;i<100;i++){
        List row = new List();
        for(int j=0;j<100;j++){
          row.add(new block());
        }
        testLol.add(row);
      }
    
      dataPoints.shuffle();
    
      print("Run tests.");
      watch = new Stopwatch();
      watch.start();
      for(int j=0;j<8000;j++){
        dataPoints.forEach((p) => testMap["${p.x}-${p.y}"]);
      }
      watch.stop();
      print("${watch.elapsed}");
    
      watch = new Stopwatch();
      watch.start();
      for(int j=0;j<8000;j++){
        dataPoints.forEach((p) => testLol[p.x][p.y]);
      }
      watch.stop();
      print("${watch.elapsed}");
    
    }
    
    

    Results were the Map taking around 26 seconds and the List taking about 1.4 seconds. This was running from the Dart Editor. From the command line, the map was just under 20 seconds (probably debugging overhead) and the List took about the same time. So moving forward with the world generation, List of Lists seems the way to go!

    Monday, 23 February 2015

    Dart Alive! - Part 1 : Top 10 Live Dart Websites

    The most popular post on this blog by far is the 'Top 5 Live Websites Already Using The Dart Language' written all the way from 2013. This is an eternity in the world of computing, therefore it is about time for an update!

    If you are arriving at this blog post a long time after it was published, check out this constantly updated list on the Dart Lang site.

    The 10 chosen are a mix of a direct use of Dart or a company that uses in their products. Without further ado, let's dive in to the list - (no particular order):

    1

    Work Trail - Time tracking application with Web, iOS and Android clients. Includes a developer API and extensive reporting. Their blog often features 'behind the scenes' description of the technologies running the site including Dart.

    2

    Easy Insure - Insurance price comparison site. Quotes generation and Agent directory.

    3

    Montage Book - Montage Automagic photo book design.

    4

    Counties Power - New Zealand Power Company. Dart powered map application.

    5

    DartLab - is a mini-IDE for sharing runnable Dart applications similar to JSFiddle. Currently it compiles Dart client-side into Javascript.

    6

    fxSimulator - Trading simulator for for Forex Market. In live Beta now.

    7

    Anionu - Anionu is a cloud based security and surveillance solution.

    8

    DGLogik - Iot Solutions and data dashboards.

    9

    Soundtrap - Online collaborative music studio including recording and a community.

    10

    iFormBuilder - Cloud-connected custom form based data collection system. Focussed on mobile use.

    In Part Two of this series, we will take a look at the 'Dog Food' situation - How does Google itself use Dart?