Planet Gamedev

Game AI for Developers

BROADCAST: Grand Strategy AI in Europa Universalis 4 (October 23rd)

by Alex J. Champandard at October 23, 2014 03:00 AM

BROADCAST: Grand Strategy AI in Europa Universalis 4 (October 23rd)

This upcoming broadcast on Thursday, October 23rd at 18:00 UTC will take place online within your browser using streaming audio/video:

“In this interview, join Martin Anward for a peek behind the scenes of the development methodology that drives Paradox games and in particular how the artificial intelligence for Europa Universalis 4 was built — in particular the process of making it more transparent and human-like at the same time. Hear about how iterations are conducted, the importance of Paradox's patching model, their approach for testing and much more!”

To subscribe for email reminders and check the exact time in your current timezone, visit this broadcast's page on AiGameDev.com.

Physics-Based Animation

SPGrid: A Sparse Paged Grid structure applied to adaptive smoke simulation

by christopherbatty at October 22, 2014 08:48 PM

Rajsekhar Setaluri, Mridul Aanjaneya, Sean Bauer, and Eftychios Sifakis

We introduce a new method for fluid simulation on high-resolution adaptive grids which rivals the throughput and parallelism potential of methods based on uniform grids. Our enabling contribution is SPGrid, a new data structure for compact storage and efficient stream processing of sparsely populated uniform Cartesian grids.SPGrid leverages the extensive hardware acceleration mechanisms inherent in the x86 Virtual Memory Management system to deliver sequential and stencil access bandwidth comparable to dense uniform grids. Second, we eschew tree-based adaptive data structures in favor of storing simulation variables in a pyramid of sparsely populated uniform grids, thus avoiding the cost of indirect memory access associated with pointer-based representations. We show how the costliest algorithmic kernels of fluid simulation can be implemented as a composition of two kernel types: (a) stencil operations on a single sparse uniform grid, and (b) structured data transfers between adjacent levels of resolution, even when modeling non-graded octrees. Finally, we demonstrate an adaptive multigridpreconditioned Conjugate Gradient solver that achieves resolutionindependent convergence rates while admitting a lightweight implementation with a modest memory footprint. Our method is complemented by a new interpolation scheme that reduces dissipative effects and simplifies dynamic grid adaptation. We demonstrate the efficacy of our method in end-to-end simulations of smoke flow.

SPGrid: A Sparse Paged Grid structure applied to adaptive smoke simulation

Game From Scratch

Adventures in Phaser with TypeScript–Loading and Using Tiled Maps

by Mike@gamefromscratch.com at October 22, 2014 07:43 PM

 

 

In this tutorial we are going to look at loading and using Tiled TMX maps.  Tiled is a free, open sourced map editor, and TMX is the file format it outputs.  You basically use it to “paint” levels using one or more spritesheets containing tiles, which you then load and use in your game.

 

Here is Tiled in action, creating the simple map I am going to use in this example:

image

 

By the way, I downloaded the tile graphics from here.  Additionally, you can download the generated TMX file we will be using here.

 

I am not going to go into detail on using the Tiled editor.  I actually covered this earlier here.  For Phaser however, just be certain you export as either JSON or CSV format and you should be good to go.

 

Now let’s look at some code to load the tile map.

 

 

/// <reference path="phaser.d.ts"/>
class SimpleGame {
    game: Phaser.Game;
    map: Phaser.Tilemap;
    
    constructor() {
        this.game = new Phaser.Game(640, 480, Phaser.AUTO, 'content', {
            create: this.create, preload:
            this.preload, render: this.render
        });
    }
    preload() {
        this.game.load.tilemap("ItsTheMap", "map.json", null, Phaser.Tilemap.TILED_JSON);
        this.game.load.image("Tiles", "castle_0.png");
    }
    render() {

    }
    create() {
        this.map = this.game.add.tilemap("ItsTheMap", 32, 32, 50, 20);
        this.map.addTilesetImage("castle_0", "Tiles");

        this.map.createLayer("Background").resizeWorld();
        this.map.createLayer("Midground");
        this.map.createLayer("Foreground");
        
        
        this.game.camera.x = this.map.layers[0].widthInPixels / 2;
        this.game.camera.y = 0;

        this.game.add.tween(this.game.camera).to({ x: 0 }, 3000).
to({ x: this.map.layers[0].widthInPixels }, 3000).loop().start(); } } window.onload = () => { var game = new SimpleGame(); };

 

And when you run it… assuming like me you are using Visual Studio 2013 you will probably see:

image

 

Hmmmm, that’s not good.  Is there something wrong with our tilemap?  Did we make a mistake?

 

Nope… welcome to the wonderful world of XHR requests.  This is a common problem you are going to encounter over and over again when dealing with loading assets from a web server.  If we jump into the debugger, we quickly get the root of the problem:

 

image

 

Let’s look closely at the return value in xhr.responseText:

Ohhh. it’s an IIS error message and the key line is:

The appropriate MIME map is not enabled for the Web site or application.

Ah…

 

See, Visual Studio ships with an embedded version of IIS called IIS Express, and frankly, IIS Express doesn’t have a clue what a JSON file is.  Let’s solve that now.  If you created a new TypeScript project in Visual Studio, it should have created a web.config file for you.  If it didn’t create one and enter the following contents:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>
</configuration>

 

Now the code should run without error

I should take a moment to point out that this is an entirely Visual Studio specific solution.  However, this particular problem is by no means limited to IIS Express.  I documented a very similar problem when dealing with WebStorm’s integrated Chrome plugin.  If your loadJson call fails, this is most likely the reason why!  Well that or you typo’ed it. :)

 

Ok, assuming everything is configured right,now we should see:

 

No Iframe for you!

 

By the way, you may have to click on the to get it to start rendering.

 

Most of the loading code should look pretty familiar by now, Phaser is remarkably consistent in its approach.  There are a few things to be aware of though from that code.  First, the order you create layers in is important.  In Tiled I created 3 layers of tiles.  A solid background layer named “background”, a middle layer with most of the tiles in it called “midground” then a detail layer for the topmost tiles named “foreground”.  Think of rendering tiles like putting stickers on a flat surface… the front most stickers will obscure the ones that are behind them.  The same is true for tiles.  There are other options in tiled for creating foreground and background layers, but I stuck with normal tile layers for ease.  Just no that more efficient options exist.

 

The next thing to be aware of is when I called addTilesetImage, that is the same image filename that I provided to Tiled.  It is important that you use the same graphics files and names between Tiled and your code.  The next thing worth noticing is the call to resizeWorld() I made when loading the first tiled layer.  This simply set’s the world’s dimensions to be the same size as the tile layer you specified.  Since all the tile layers are the same size, you could have called it on any of them.  Finally, we made a simple tween that pans the camera from one end of the level to the other and back.

 

There is more to touch on with tiles, but I will have to cover that in later post(s).

 



Game Design Aspect of the Month

Critical Combat Systems in Competitive Gaming

by noreply@blogger.com (Sande Chen) at October 22, 2014 01:43 PM

In this article, retired Dungeon Master Derrick B. Smith delves into the history of Critical Combat Systems and explains why such systems may not be the best choice for competitive games.

Computer game players are finding more games with Critical Combat Systems for entertainment. The inclusion of a random critical system in a non-competitive game can bring a level of excitement. The inclusion in any competitive gaming environment is a mistake. It turns a competitive game from being fair and balanced to one of random dumb luck. Imagine tossing a 6-sided die to decide how many points a touchdown was worth in an American Football game.

The starting point for Critical System being introduced to gaming dates back to the beginning of the RPG genre. Typically seen as “House Rules,” many groups adopted the concept. Dungeons & Dragons (D&D) and similar RPG games have simplified combat systems that lend themselves to the addition of a “Critical Strike”. Many groups would later go on to add a “Critical Fail” mechanic to their existing gameplay.

Photo taken by Davi Silva.

The D&D combat system used a 20-sided die (d20) roll for combat resolution. In its easiest form, any natural d20 roll of a 20 would allow for a “Critical Hit”. This allowed the attacker to double the damage the target suffers. There were many ways to resolve this double damage. Most groups’ double the full damage including any modifiers the player’s character was entitled to utilize. Other groups adopted a doubling of only the weapons base damage die than adding any modifiers unchanged. The main difference in the two systems was the maximum damage. The second reduced the potential significantly.

Other gaming systems added complex “Critical Strike” charts typically broken down into weapon groups and creature body type/armor. Though it allowed for more diversity in the results, they also slowed gameplay down. A talented Dungeon Master could story line the results without relying on any complex charts to add flavor to the game.

The Critical Fail system allowed for comical or tragic failures. The failure was rarely automatic and very dependent on the situation at the time of the failure. This shows why a true RPG requires a Human Game Master. Though computers are great for doing calculations and simplifying some tasks, they are not able to adapt to a changing story line based on game events and player decisions. The fumbling player would in many cases be required to make additional die rolls to reduce the negative result. An example would be to prevent breaking a weapon or hitting an ally or themselves.

As computer-based games developed, it was natural to see RPG-styled games created. A “Critical Strike” component added to non-competitive games can be more exciting than harmful. Within a Player vs Computer game, the effect of this random element does not add a noticeable negative aspect to the game. This is not true when you have games designed to be competitive or built with a Player vs Player (PVP) aspect. The random element that a “Critical Strike” adds could be compared to flipping a coin to determine who goes first in each round of a Chess Match. This random factor removes the development of tactical skills from many games. Players will still develop strategies for gameplay but there will be many who only try to score that Critical to win.

There are games designed to be competitive and the random luck “Critical Strikes” add diminishes the inherent skill component some games contain. Instead of an evolution of attacks and defenses strategies being developed, players migrate to getting lucky and falsely believe that luck is similar to true skills. Though a Critical Strike system brings uncertainty and a sense of suspense, the thrill does not last long and an enduring game fails to evolve.

Derrick B. Smith is a retired Dungeon Master. He started playing D&D and similar games before it was called 1st edition. He is still waiting for the first real RPG computer game to be developed. Also, Biker, Trucker, Gamer, Seamstress.

GPGPU.org

CUDA finance course Dec 2-5, 2014, New York

by dom at October 22, 2014 08:09 AM

Developed in partnership with NVIDIA, this hands-on four day course will teach you how to write and optimize applications that fully leverage the multi-core processing capabilities of the GPU. This course will have a finance focus. Commonly used algorithms such as random number generation and Monte Carlo simulations will be used and profiled in examples. A background in finance is not necessary. For more information please visit: http://acceleware.com/training/988

Cf4ocl Brings Object-Oriented API to OpenCL C API

by dom at October 22, 2014 08:07 AM

The Cf4ocl project is a GPLv3/LGPLv3 initiative to provide an object-oriented interface to the OpenCL C API with integrated profiling, promoting the rapid development of OpenCL host programs and avoiding boilerplate code. Its main goal is to allow developers to focus on OpenCL device code. After two alpha releases, the first beta is out, and can be tested on Linux, Windows and OS X. The framework is independent of the OpenCL platform version and vendor, and includes utilities to simplify the analysis of the OpenCL environment and of kernel requirements. While the project is making progress, it doesn’t yet offer OpenGL/DirectX interoperability, support for sub-devices, and doesn’t support pipes and SVM.

Cf4ocl can be downloaded from http://fakenmc.github.io/cf4ocl/.

iPhone Development Tutorials and Programming Tips

Open Source Component For Creating Great Looking Iconized Grid Menus Using iOS 8’s Blur Effects

by Johann at October 22, 2014 06:10 AM

Post Category    Featured iPhone Development Resources

Last month I mentioned a tutorial on using the new visual effect styles in iOS 8 including UIBlurEffectStyle and the BTSimpleSideMenu library for creating blurred slide-in side menus.

Here’s an open source component submitted by Carson Perrotti for creating customizable blurred Mailbox app inspired grid menus using iOS 8’s blur effects called CNPGridMenu.

CNPGridMenu allows you to easily specify icons, and titles for the individual menu selections, and you can also choose between different blur styles for the menu using UIBlurEffect.

Here’s an image from the readme showing CNPGridMenu in action:

CNPGridMenu

You can find CNPGridMenu on Github here.

A great looking easily customizable component for creating iconized grids.


Be the first to comment...

Related Posts:

FacebookTwitterDiggStumbleUponGoogle Plus

Original article: Open Source Component For Creating Great Looking Iconized Grid Menus Using iOS 8’s Blur Effects

©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

iPhone Development Tutorials and Programming Tips

Open Source iOS Library Allowing You To Easily Slide Views Automatically Away From The Keyboard

by Johann at October 21, 2014 06:18 AM

Post Category    Featured iPhone Development Resources,iOS Development Libraries,Objective-C,Open Source iOS Libraries And Tools

Here’s a library called IHKeyboardAvoiding that works differently from previously mentioned libraries allowing you to automatically slide any view out of the way of the keyboard (not just text fields) submitted by Fraser Scott.

I mentioned a few libraries for solving the issue of text fields being covered by the keyboard, most recently IQKeyboardManager that provides an approach not requiring any code.

IHKeyboardAvoiding allows you to register a target view and when that keyboard intersects with the bottom of the target view it slides the view (and views contained within) upwards out-of-the-way of the view.  This view can be any view, and use of a UIScrollView is not required.  The library works with all orientations, auto layout and different keyboard setups (dock, undocked, normal, split).

Here’s an animation showing IHKeyboardAvoiding in action – notice the button and text fields sliding out-of-the-way:

IHKeyboardAvoiding-Small

You can find IHKeyboardAvoiding on Github here.

A nice library for solving the issue of views being covered by the keyboard.


Be the first to comment...

Related Posts:

FacebookTwitterDiggStumbleUponGoogle Plus

Original article: Open Source iOS Library Allowing You To Easily Slide Views Automatically Away From The Keyboard

©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

tooNormal

PHP Mad Notebook

by Mike K at October 21, 2014 05:51 AM

This isn’t a blog. It’s a notebook.

APCu Functions

Arguments in []’s are optional. Cross reference with APC docs. PECL Page. Github.

function apcu_cache_info([$type [, $limited]]);
function apcu_clear_cache([$cache]);
function apcu_sma_info([$limited]);
function apcu_key_info($key);
function apcu_enabled();
function apcu_store($key, $var [, $ttl]);
function apcu_fetch($key [, &$success]);
function apcu_delete($keys);
function apcu_add($key, $var [, $ttl]);
function apcu_inc($key [, $step [, &$success]]);
function apcu_dec($key [, $step [, &$success]]);
function apcu_cas($key, $old, $new);
function apcu_exists($keys);
function apcu_bin_dump([$user_vars]);
function apcu_bin_load($data [, $flags]);
function apcu_bin_dumpfile($user_vars, $filename [, $flags [, $context]]);
function apcu_bin_loadfile($filename [, $context [, $flags]]);

Iterator functions are omitted, but also available.

The above is a cleaned up version of what’s output by "php --re apcu".

Perl-like ?: Operator

$a = TRUE ?: FALSE;       // true
$b = FALSE ?: TRUE;       // true
$c = NULL ?: "DeathRope"; // "DeathRope"

From Tips.

Data Format: Raw PHP variables (var_export)

To serialize something to disk in the fastest way PHP can read it, you make it source code by calling var_export. Whenever the file changes, it should cause a cache miss with OPcache.

mixed var_export ( mixed $expression [, bool $return = false ] );

$php_array = Array( 2,5,6,14 );
$export = var_export($php_array, true); // true = return the value (else echo)
file_put_contents('export.php', '<?php $php_array = ' . $export . '; ?>');

To use it:

include 'export.php';

Alternatively, if you store it a different way:

eval( $php_array );

But this will cause OPcache to miss every time.

Data Format: JSON (decode, encode)

Apparently this is the fastest encoder, as of PHP 5.3. Benchmarks.

mixed json_decode ( string $json [, bool $assoc = false 
    [, int $depth = 512 [, int $options = 0 ]]] );

string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512 ]] );

int json_last_error ( void );

$json_in = '{ "money":200, "love":false }'; // json uses "", not ''
$array_out = json_decode( $json_in, true ); // true = output an array (else object)
$json_out = json_encode( $array_out );

var_dump( $array_out );
// array(2) { ["money"]=> int(200) ["love"]=> bool(false) }
var_dump( $json_out );
// string(26) "{"money":200,"love":false}"

json_decode, json_encode, json_last_error

Data Format: Serialize, Unserialize

A faster decoder (slower encoder), and types/classes persist.

string serialize ( mixed $value );
mixed unserialize ( string $str );

$data = Array( 'fox'=>true, 'zippy'=>13 );
$out = serialize( $data );
$new_data = unserialize( $out );

var_dump( $out );
// string(37) "a:2:{s:3:"fox";b:1;s:5:"zippy";i:13;}"
var_dump( $new_data );
// array(2) { ["fox"]=> bool(true) ["zippy"]=> int(13) }

serialize, unserialize

Data Format: IGbinary

An alternative, external binary encoder/decoder. According to benchmarks, the fastest.

https://github.com/igbinary/igbinary (PECL)

// Drop in replacement for serialize/unserialize //
string igbinary_serialize ( mixed $value );
mixed igbinary_unserialize ( string $str );

$data = Array( 'fox'=>true, 'zippy'=>13 );
$out = igbinary_serialize( $data );
$new_data = igbinary_unserialize( $out );

// TODO: VarDump

Smaller too.

Tips and Tricks:http://ilia.ws/files/zendcon_2010_hidden_features.pdf

Data Format: CSV

Reading Only.

http://php.net/manual/en/function.str-getcsv.php

array str_getcsv ( string $input [, string $delimiter = "," 
    [, string $enclosure = '"' [, string $escape = "\\" ]]] )

$arr = str_getcsv($data);

// TODO: output

Data Format: XML

Reading Only (there is writing, but it seems more difficult).

SimpleXMLElement simplexml_load_file ( string $filename 
    [, string $class_name = "SimpleXMLElement" 
    [, int $options = 0 [, string $ns = "" 
    [, bool $is_prefix = false ]]]] )

SimpleXMLElement simplexml_load_string ( string $data 
    [, string $class_name = "SimpleXMLElement" 
    [, int $options = 0 [, string $ns = "" 
    [, bool $is_prefix = false ]]]] )

$string = "<thing>It Happened</thing>";
$xml = simplexml_load_string( $string );

// TODO: Output

If you prefer Array format (like me), here’s a function.

// http://upskill.co.in/content/how-convert-simplexml-object-array-php
function __xml2array($xml) {
	$arr = array();

	foreach ($xml->children() as $r) {
		$t = array();

		if (count($r->children()) == 0) {
			$arr[$r->getName()] = strval($r);
		}
		else {
			$arr[$r->getName()][] = __xml2array($r);
		} 
	}
	return $arr;
}

Then simply

$string = "<thing>It Happened</thing>";
$xml = simplexml_load_string( $string );
$array = __xml2array($xml);

Data Format: HTML

Use Simple HTML DOM parser.

http://simplehtmldom.sourceforge.net/ (Manual)

// $html = file_get_html('http://www.google.com/');
// $html = str_get_html('<div id="hello">Hello</div><div id="world">World</div>');

$text = '<html><body><div id="me" class="president">cant touch this</div></body></html>';
$html = str_get_html( $text );

// TODO: Output

Data Format: String Delimiter

array explode ( string $delimiter , string $string [, int $limit ] );
string implode ( string $glue , array $pieces )

$in_data = "Frank|Donald|Scott|Wrenchy";
$out = explode("|",$in_data);
$csv = implode(",",$out);

var_dump( $out );
// array(4) { 
//  [0]=> string(5) "Frank" 
//  [1]=> string(6) "Donald" 
//  [2]=> string(5) "Scott" 
//  [3]=> string(7) "Wrenchy"
// } 
var_dump( $csv );
// string(26) "Frank,Donald,Scott,Wrenchy"

explode, implode

unset

$myvar = "hello";
unset( $myvar ); // Deleted. See documentation for notes on Globals and references

val and type juggling

echo boolval(2);                 // true
echo intval("14") + 1;           // 15
echo floatval("12.5") * 2;       // 25 (NOTE: doubleval is an alias for floatval)
echo strval(true);               // "true"
echo settype("5bars","integer"); // 5 (explicit casting)
echo (boolean)10;                // true (typecasting)



Game From Scratch

Guide to Creating a Game on an iPad–Raster (pixel) and Vector Art Programs

by Mike@gamefromscratch.com at October 20, 2014 07:12 PM

 

Now we are going to look at available raster graphics programs available on iPad.  While this post is part of an over all series about creating a game using only an iPad, this post should be of use to anyone looking to create art in general.  The iPad ( and other tablets ) are becoming increasingly viable ways of creating art, especially 2D art.  One major reason for this is cost.  An iPad is generally cheaper than a PC/Mac + graphics tablet, but it’s software costs where this really becomes obvious.  For example, the desktop version of Photoshop ( before it went subscription ) used to cost about $800.  The tablet version of Photoshop… $10!  Another desktop/tablet example is ArtRage, which ( although vastly cheaper ) is available at $50 on Desktop, it is only $5 on iPad.  Granted, they aren’t identical products, and often the iPad version has less functionality, but I tend to find it has all the functionality I generally need.  You mileage may vary.

 

So we are going to take a look at some of the Raster and Vector packages available on iPad.  Raster and Pixel mean basically the same thing, although “Pixel Art” has often come to represent a very specific style, with fat chunky pixels like from the 8 and 16bit era.  We will also look at two options aimed specifically at this style.  We will also look at Vector graphics packages, which allow you to define brush strokes mathematically, making for nice scalable graphics. 

 

I have also done a video quickly showing each application running, so you can have a better idea what the experience is like.  I only spend a couple minutes with each, but a few minutes is often all you need to decide if something is right for you or not!  All testing was done on a iPad Air, so if your device is slower, your experience may not be as good.

 

This video is a quick demonstration of every application mentioned below.  You can view it directly here.

 

 

Ok, let’s jump right in:

 

Photoshop Touch

iTunes Link

Cost: $9.99

Screenshot(s):

Photoshop

 

Comments:

Be careful when it comes to the Photoshop products, Adobe have released a number of Photoshop branded iOS projects and most of them are focused on photo manipulation and most useless to you.  The version you want is Photoshop Touch.  This is the mobile version of the venerable desktop Photoshop application.  While certainly stripped from it’s desktop counterpart, it is still impressively capable.

One immediately useful feature is the allowed canvas size.  Earlier versions where limited in canvas size, while now you can successfully create a 4096x4096 texture, which is the reasonable upper limit of what you will ever want to create.  I will admit though, at this size things can get a bit sluggish at times, although the painting experience is just fine, running tools like magic wand select or applying fx can bring up a wait logo.  Speaking of which, that is two areas where Photoshop really shines compared to it’s peers.  The selection tools are great, including a magic wand, scribble selection, polygon, lasso, etc select and deselect tools.

Tools are solid but not exceptional.  Feedback is great, there is no lag even on large files.  Navigation takes a bit to get used to, but is quick once you know what you are doing.  It has a few standout tools, such as the clone and heal brushes, which are somewhat rare.  Otherwise you are left with paint, burn, smudge, spray and erase as your primary art tools.  You do however have a ton of fine control over each tool, such as brush patterns, angle, scatter, size, flow and transparency.  You have to set it up yourself, but you can emulate basically any brush type you desire.

Of less use to game art, but still occasionally valuable, Photoshop Touch has 16 built in adjustments like Black&White, Shadow/Highlight, etc.  There are also 30+ filters built in, such as Sharpen, Drop Shadow, Blur, Glass, Comic, Watercolor, Sephia, etc.  There are also an impressive number of manipulation tools tucked away in here for cropping, scaling, rotating, transforming(warping) and fairly solid text tools as well.

Where Photoshop Touch really shines is layers.  You can have several layers, either new, cloned or imported from existing media.  Layer control is solid making it easy to move layers up, down, merge and delete as well as altering the opacity.  Additionally layers can be normal, darken, multiply, lighten, overly, subtracted, etc.  Fx can be limited to an individual layer. 

While Photoshop Touch may not be the program you create your art in, it should probably be in your toolbox for the sheer amount of flexibility it gives you.  In terms of alterations and manipulation of images, it can’t really be touched.  The selection, copy/paste, import and layering tools are easily the best out of any tool I look at.

In terms of getting your work out at the end of the day, unfortunately there is no direct Dropbox integration, but that isn’t really surprising given Adobe have their own cloud storage system, Creative Cloud.  In addition to their cloud offering, you can also save to the local photo roll.  There is however a Share option, allowing you to export the file ( as JPG, PSD, PSDX or PNG ) to just about any iPad application ( including dropbox ) or to email, printers, etc.  However the process is remarkably slow and sometimes simply doesn’t work.  At the end of the day, you can get just about anything in and out of Photoshop Touch that you would expect, but it can be awfully slow at times.

I suppose it’s fair to point out, it’s actually Photoshop Touch I used to resize and export the screenshots from my iPad to my Mac while creating this post.  It’s just a handy tool to have.

 


 

Autodesk Sketchbook Pro

iTunes Link

Cost: $3.99 for Pro Tools

Screenshot(s):

AutodeskSketchbook

 

Comments:

This product is a bit difficult for me to cover, as the version I have doesn’t actually seem to exist anymore.  At some point they moved from a premium iPad only product (Sketchbook Pro) to an freemium model, where you can download the base (Sketchbook Express), then for $3.99 unlock the premium tools.  I believe at the end of the day, they become the same product, but if there are minor differences, I apologize now.  As I am not entirely certain what is in the free vs pro edition, the below will be describing the complete purchased product.

Sketchbook is exactly what the name suggests, a virtual sketchpad.  It’s an impressive one at that.  It’s got a minimal interface that get’s out of your way ( all of the things you see in the above screenshot are brought up by pressing the circular icon.  Let go and it’s just you and your drawing. Drawing tools are pretty typical with pen, pencil, market, highlighter, erase, smudge and airbrush available, plus the ability to choose custom brushes/stamps from probably 100+ presets, including common pencil type (2H, 8B, etc) and oddly enough, so clip art.  Responsiveness while drawing is instant.  Using a quick pop up tool you are able to alter your brushes dimensions and opacity with a single touch.  One nice feature, lacking from many similar products, is the ability to draw lines and shapes, although curves didn’t seem to work.

There are a couple unique to Sketchbook features, of varying levels of usefulness.  There is a symmetry draw mode, enabling you to draw mirrored about a centre point.  You can also do time lapsed recording and collaborative sketching with someone else with their own copy of Sketchbook.  Sketchbook also has decent text creation abilities built in.  Most importantly (to me), Sketchbook also has layer support, although nowhere near that of Photoshop Touch.  Even just a single layer to enable tracing for animation is invaluable. 

You can export from your gallery directly to the local photo gallery, to iTunes, email, etc… as well as directly to Dropbox.  You can create images up to 1800x2400 in size, although the size of image limits the number of layers.  A 1800x2400 image can for example have 4 layers, while a 768x1024 image can have up to 18 layers.  The largest image you are able to create is 2830x2830.  No idea why it stops there…  Even at that size, performance remains smooth.

Sketchbook is a great product for creating sketches, the brushes are natural, performance is good and tools are complete enough to recreate most anything.  The interface is faster to navigate than Photoshop Touch, but it has a great deal less functionality, with absolutely no filters, effects, selection tools and minimal layer functionality.  For drawing however, I would take it over Photoshop Touch every day.


 

Art Rage

iTunes Link

Cost: $4.99

Screenshot(s):

ArtRage

 

Comments:

This is the most applicably named application I have ever encountered!  It’s an amazing application for creating digital art, and it is horrifically rage inspiring!  ArtRage attempts to recreate real world art process digital, and does an incredibly good job of it.  You can choose your paper type (grain), metallic-ness then go to town using tools like paint, roller, trowel, crayons, markers, pens, erasers, pencils, airbrush and a couple different paint brushes.  For each brush you can set a number of settings specific to each tool such as pressure, thinning etc.  You really can recreate a very “painterly” feel.  So why the rage?

Well that part is simple.  This application lags.  Always lags and I absolutely cannot use it for that reason.  Regardless to the complexity of your scene, your paint brush will always been a half a second behind where you are touching.  Of all the applications I looked at, this one had by far the worst performance.  If you can handle the delay while drawing, this application is certainly worth checking out, especially if you are looking for a natural media look.  I personally cannot get over the lag.

From a technical perspective, Art rage allows a maximum canvas size of 2048x2048.  It supports layers with an absolute ton of blending modes.  There is no manipulation tools for selection, transformation nor any filters or effects.  This is a painting program focused on painting and nothing more.  It however probably does the best job of recreating brushes and paper in the digital world.  It has the ability to export to Dropbox as well as save locally, but not to send to other applications on your iPad.


 

Bamboo Paper

iTunes Link

Cost: Free for Base + up to $3.99 to add tools

Screenshot(s):

BambooPaper

 

Comments:

Made by Wacom, famous for the titular Bamboo tablets.  The free version ships with a pen, then for 99 cents each, or $3.99 for all, you can add tools such as Brush, Crayon, Pencil etc.  It’s got a slick package, good export support (including Dropbox) and does feel like working in a notebook.

That said, it’s simply too limited to be used for much more than sketching.  Lack of layer support, minimal dimension options, no selection tools, filters or advanced brushes.

 


 

Paper

iTunes Link

Cost: Free then up to $6.99 for all tools

Screenshot(s):

Paper

Comments:

Paper is a somewhat famous application, as it has been used in Apple promotional materials.  It is also incredibly basic, basically just trying to mimic the drawing on paper experience.  As you can see from the screenshot above, I only have the free version installed.  For up to $6.99 you can add other art tools like a pencil, marker, paint brush, colour mixer, etc.  Export abilities are limited to save to camera roll and send to app.

The drawing is nice and natural, but it’s too limited to be of much use for game development.  Additionally, it’s price is hard justified compared to similar applications.  Can’t really recommend paper other than for sketching if the minimal interface floats your boat.


 

Skeches

iTunes Link

Cost: Free to start, up to $4.99 for all tools, plus text and layers

Screenshot(s):

Sketches

 

Comments:

Sketches is very similar to Paper and  Bamboo Paper, in that it emulates a classic sketchbook.  However the major exception is, with the premium purchase of $4.99 you gain among other things, layer support.  Additionally the free version includes a complete set of tools, but limits the customizability of each.  It contains all of the same tools as the previous two applications.  The interface can be minimized by swiping aside panels.  Navigation is multitouch based and to be honest is confusing as hell until you get used to it.

You are able to export to a number of formats, including Dropbox.  You can select from a number of paper types, but unfortunately have very little control of resolution of the image, maxing out at that of a Retina iPad.

Of all the sketch based drawing applications, this one was easily my favourite, even with it’s somewhat unnatural navigation interface. 


 

Concepts

iTunes Link

Cost: Free to $6.99 for full toolset

Screenshot(s):

Concepts 

 

Comments:

Of all the applications I’ve covered yet, Concepts is probably the most unique, and in some ways, the most powerful.  Designed for creating sketches for concept art, it comes with several tools you haven’t seen yet.  For example, there is a tool for tracing lines and arcs.  There are snapping tools for snapping to the grid.  Speaking of which, the grid can be turned off, on, and set to a number of different densities and formats, including isometric, which can be invaluable if that is the art style you are going for.  There is full layering support, but they are intended for organization/tracing/layering and not artistic effects.  Beyond transparency, there are no blending options for layers.

Artistic tools are somewhat limited to pens, pencils and markers.  More natural art style would be hard to achieve in this program as a result.  That said, the color system is amazing and emulates COPIC markers, allowing you to create pretty much the same tools that concept artists use.

For precision works, this is hands down the best choice out there.  For drawing striaght edges, lines and curves, only the next option comes close.  For more painterly effects, this is a poor choice.  There is no filter or fx support.  Export support is robust, and actually capable of exporting to DXF ( Autocad ), SVG ( Vector ) and PSD formats.  You can also export as an image to the local camera roll, as well as export to Dropbox and others ( including somewhat shockingly, Adobe’s Creative Cloud ).

If you are doing concept art, or going for a technical look, this is hands down your best choice.

 


 

Adobe Illustrator Draw

iTunes Link

Cost: Free!

Screenshot(s):

 AdobeDraw

Comments:

Adobe make a number of products of a very similar nature, Adobe Ideas, Adobe Lines and Adobe Sketch.  Adobe Draw however ties together the best of each of them and has some very interesting abilities.  By far and away the most important feature is the ability to use an angle or french curve ( like shown above ) to draw straight lines and curves.  The actual drawing features are somewhat limited, mostly pen/pencil style drawing implements.  You can control the brush tip size, colour and opacity and that’s it. There is layer support buts it’s tied to each tool somewhat oddly.  The response is quick, the interface is nice and clean and though limited, the brushes are different enough to be useful.

All that said, this application is free.  It’s good and it’s free.  In some ways the drawing tools are amongst the best available.  The angle/french curve functionality is exceedingly well implemented, much better than the curve support in Concepts, which is the only other program that offers similar functionality.  Export functionality is fairly traditional, you can save to the local camera roll, upload to creative cloud and hit the standard share with targets, including Dropbox.  Unfortunately it seems you have little (no?) control over the canvas size.

I don’t really understand the business model here, but free is a wonderful price.  Be sure to check this one out.

 


 

Inkist

iTunes Link

Cost: Free *for a limited time, seemingly forever

Screenshot(s):

Inkist 

 

Comments:

I will be honest, I had a great deal of trouble navigating my way around this application.  Even saving a file was somewhat perplexing.  In many ways it has an interface like many desktop art packages like GIMP or Paintshop.  That interface doesn’t necessarily work on a touch device.

There is actually a LOT of functionality packed in here, more so than most of the packages listed here, except perhaps Photoshop Touch. There is full layering support, but limited to 3 layers ( I think, who knows whats behind that interface that I couldn’t figure out! ), and all kinds of blending functionality between layers.  Art tools are somewhat limited.  I think everything you need is in here, but accessing it is somewhat of a trick.

That said, it’s listed as free for a limited time, and that was over a year ago.  It doesn’t seem like this application is still being developed, so it’s a completely free option.  For that reason alone you should check it out, the interface might click for you better than it did me.  If nothing else, the price is right!

 


 

Pixel Art Packages

 

Sprite Something

iTunes Link

Cost: $4.99

Screenshot(s):

SpriteSomething

 

Comments:

This application is unique in the list as it is specifically aimed at low resolution ( 8/16bit ) pixel art.  At it’s core it’s a fat bit grid editor.  You draw pixel by pixel, although it does have some handy tools like fill, line drawing, etc. There is also layering ability, but there is no blending between layers, it’s literally just stacked pixels. You work in a massively zoomed in window, but you can preview the end result as you work.  There are also tools for doing frame by frame animation sequences, including onion skinning functionality.  This part of the interface can be a bit clunky.

One very unique thing about sprite something is, it has a simple level editor built in as well.  See the video for more details.  Export is limited to email and local camera roll.  If you are working in fat bit pixel style, this is your best ( and almost only ) option. 

 


Codea

iTunes Link

Cost: $9.99

Screenshot(s):

Codea 

 

Comments:

I’m just mentioning this one for thoroughness.  If you are reading this as part of the overarching iPad game creation tutorial, there is a simple pixel art example “Spritely” built into Codea.  Its another fat bit grid editor for pixel art.  It’s very simple but may be enough for you if you have simple requirements.

Obviously not recommended to non-Codea users.

 


Vector Graphics Packages

 

Vector graphics applications work a bit differently than raster packages we described above ( except perhaps Concepts which is a cross between Raster and Vector graphics ).  Raster applications work on a pixel by pixel basis.  Vector graphics on the other hand work on mathematic formulas representing each brush stroke.  This gives you a bit less fine control over the end results, but allows you to scale up or down to any graphic resolution you want.

 

Inkpad

iTunes Link

Cost: Free and Open Source

Screenshot(s):

 Inkpad

Comments:

Completely free and open source, Inkpad is a powerful vector graphics package.  If you’ve ever used Inkscape on a PC, you know what you are in for.  You draw using paths, manipulate curves either straight line or bezier for curved edges and using simple geographic shapes, build, color and layer them to create more complex images. 

Inkpad has full layer support, although they don’t really effect each other like in raster packages.  You can however bring in a standard graphic as a background or to trace over.  Inkscape supports saving as an image locally or exporting as PDF or SVG.

Once again, it’s completely free.  Free is nice.

 

iDraw

iTunes Link

Cost: $8.99

Screenshot(s):

IDraw

 

Comments:

iDraw has one of those iNames iAbsolutely iHate, but don’t judge the package by it’s name.  I absolutely love this package and strongly recommend it to anybody reading this that wants to work with vector graphics.  This application works very similar to Inkpad, except with more functionality, more polish and a higher price tag.  I have struggled in the past with vector graphics applications such as Inkscape ( unwieldy ) and Illustrator ( overwhelming ) and iDraw is the first one that just “clicked” for me.  Once again, the basic concept remains the same, you draw shapes using lines (paths), fill those paths with colors or gradiants, and layer them to make more complex shapes.  One major difference between this and Inkpad is the free form drawing tools, that allow you to use it much more similar to a traditional drawing package.

iDraw is also available as a complete application on Mac and files are interchangeable.  This page has full layer support and is capable of saving directly to Dropbox.  Files can be exported as iDraw, PDF ( very very very useful with Codea as we will soon see ), SVG, PSD, PNG and JPEG, with resolutions of 72, 144 or 300dpi.

 

 

Summary

 

This is only a small subset of graphics packages available on iPad, but does represent a large cross section of them, as well as featuring most of the “big names”.

 

Myself, if I were to only be able to keep a couple applications, my personal choices would be:

  • Photoshop Touch — for image manipulation, modification, effects and some creation
  • iDraw — Vector graphics made easy
  • Adobe Draw — Great sketching app, excellent line and curve support, completely free
  • Sketches — Most versatile drawing app with different brushes like watercolour, paint, etc
  • Concepts — Perfect for technical drawings, similar to Adobe Draw but much more technical, Copic integration
 
If I had absolutely no budget available, I would most certainly recommend people download:
 
  • Sketches — For all your sketching needs, I’d pay for it, so free is awesome
  • Inkpad — Powerful vector graphics, completely free
  • Inkist — The interface is rather awful, but it gives you a lot of editing functionality, completely free
 
All told, that represents under 20$ worth of purchases and provides a level of power way taken together that exceeds any desktop application at many times the price.  Even for a total spend of $0, you can end up with a remarkably complete 2D art package.

Geeks3D Forums

(PR) OpenVX 1.0 Specification 
for Computer Vision Acceleration

October 20, 2014 06:51 PM

Quote
October 20th, 2014, – The Khronos™ Group today announced the ratification and public release of the finalized OpenVX™ 1.0 specification, an open, royalty-free standard for cross platform acceleration of computer vision applications. Open...

OpenGL

Khronos Group releases OpenVX 1.0 specification 
for Computer Vision Acceleration

October 20, 2014 01:21 PM

The Khronos Group announced the ratification and public release of the finalized OpenVX 1.0 specification, an open, royalty-free standard for cross platform acceleration of computer vision applications. OpenVX enables performance and power-optimized computer vision processing, especially important in embedded and real-time uses cases such as face, body and gesture tracking, smart video surveillance, advanced driver assistance systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics and more. In addition to the OpenVX specification, Khronos has developed a full set of conformance tests and an Adopters Program, that enables implementers to test their implementations and use the OpenVX trademark if conformant. Khronos plans to ship an open source, fully-conformant CPU-based implementation of OpenVX 1.0 before the end of 2014.



c0de517e Rendering et alter

Scientific Python 101

by DEADC0DE (noreply@blogger.com) at October 20, 2014 01:30 PM

As for the Mathematica 101, after the (long) introduction I'll be talking with code...

Introduction to "Scientific Python"

In this I'll assume a basic knowledge of Python, if you need to get up to speed, learnXinYminute is the best resource for a programmer.

With "Scientific Python" I refer to an ecosystem of python packages built around NumPy/SciPy/IPython. I recommend installing a scientific python distribution, I think Anaconda is by far the best (PythonXY is an alternative), you could grab the packages from pypi/pip from any Python distribution, but it's more of a hassle.

NumPy is the building block for most other packages. It provides a matlab-like n-dimensional array class that provides fast computation via Blas/Lapack. It can be compiled with a variety of Blas implementations (Intel's MKL, Atlas, Netlib's, OpenBlas...), a perk of using a good distribution is that it usually comes with the fastest option for your system (which usually is multithreaded MKL). SciPy adds more numerical analysis routines on top of the basic operations provided by NumPy.

IPython is a notebook-like interface similar to Mathematica's (really, it's a client-server infrastructure with different clients, but the only one that really matters is the HTML-based notebook one). 
An alternative environment is Spyder, which is more akin to Matlab's or Mathematica Workbench (a classic IDE) and also embeds IPython consoles for immediate code execution.
Especially when learning, it's probably best to start with IPython.

Why I looked into SciPy

While I really like Mathematica for exploratory programming and scientific computation, there are a few reasons that compelled me to look for an alternative (other than Wolfram being an ass that I hate having to feed).

First of all, Mathematica is commercial -and- expensive (same as Matlab btw). Which really doesn't matter when I use it as a tool to explore ideas and make results that will be used somewhere else, but it's really bad as a programming language.

I wouldn't really want to redistribute the code I write in it, and even deploying "executables" is not free. Not to mention not many people know Mathematica to begin with. 
Python, in comparison, is very well known, free, and integrated pretty much everywhere. I can drop my code directly in Maya (or any other package really, python is everywhere) for artists to use, for example.

Another big advantage is that Python is familiar, even for people that don't know it, it's a simple imperative scripting language.
Mathematica is in contrast a very odd Lisp, which will look strange at first even to people who know other Lisps. Also, it's mostly about symbolic computation, and the way it evaluate can be quite mysterious. CPython internals on the other hand, can be quite easily understood.

How does it fare?

It's free. It's integrated everywhere. It's familiar. It has lots of libraries. It works. It -can- be used as a Mathematica or Matlab replacement, while being free, so every time you need to redistribute your work (research!) it should be considered.

But it has still (many) weaknesses.

As a tool for exploratory programming, Mathematica is miles aheadIts documentation is great, it comes with a larger wealth of great tools and its visualization options are probably the best bar none.
Experimentation is an order of magnitude better if you have good visualization and interactivity support, and Mathematica, right now, kills the competition on that front.

Python has IPython and Matplotlib. IPython can't display output if assignments are made, and displays only the last evaluated expression. Matplotlib is really slow, really ugly, and uses a ton of memory. Also you can either get it integrated in IPython, but with zero interactivity, or in a separate window, with just very bare-bones support for plot rotation/translation/scale.

As a CAS I also expect Mathematica to be the best, you can do CAS in Python via SymPy/Sage/Mathics but I don't rely too much on that, personally, so I'm not in a position to evaluate.

Overall, I'll still be using Mathematica for many tasks, it's a great tool.

As a tool for numerical computation it fares better. Its main rival would be Matlab, whose strength really lies in the great toolboxes Mathworks provides. 
Even if the SciPy ecosystem is large with a good community, there are many areas where its packages are lacking, not well supported or immature.

Sadly though for the most Matlab is not that popular because of the unique functionality it provides, but because MathWorks markets well to the academia and it became the language of choice for many researchers and courses.
Also, researchers don't care about redistributing source nearly as much as they really should, this day and age it's all still about printed publications...

So, is Matlab dead? Not even close, and to be honest, there are many issues Python has to solve. Overall though, things are shifting already, and I really can't see a bright future for Matlab or its clones, as fundamentally Python is a much better language, and for research being open is probably the most important feature. We'll see.

A note on performance and exploration

For some reason, most of the languages for scientific exploratory programming are really slow. Python, Matlab, Mathematica, they are all fairly slow languages. 
The usual argument is that it doesn't matter at all, because these are scripting languages used to glue very high-performance numerical routines. And I would totally agree. If it didn't matter.

A language for exploratory programming has to be expressive and high-level, but also fast enough for the abstractions not to fall on their knees. Sadly, Python isn't.

Even with simple code, if you're processing a modicum amount of data, you'll need to know its internals, and the variety of options available for optimization. It's similar in this regard to Mathematica, where using functions like Compile often requires planning the code up-front to fit in the restrictions of such optimizers.

Empirically though it seems that the amount of time I had to spend minding performance patterns in Python is even higher than what I do in Mathematica. I suspect it's because many packages are pure python.
It's true that you can do all the optimization staying inside the interactive environment, not needing to change languages. That's not bad. But if you start having to spend a significant amount of time thinking about performance, instead of transforming data, it's a problem.

Also, it's a mystery to me why most scientific languages are not built for multithreading, at all. All of them, Python, Matlab and Mathematica, execute only some underlying C code in parallel (e.g. blas routines). But not anything else (all the routines not written in native code, often things such as plots, optimizers, integrators).

Even Julia, which was built specifically for performance, doesn't really do multithreading so far, just "green" threads (one at a time, like python) and multiprocessing.

Multiprocessing in Python is great, IPython makes it a breeze to configure a cluster of machines or even many processes on a local machine. But it still requires order of magnitudes more effort than threading, killing interactivity (push global objects, imports, functions, all manually across instances).

Mathematica at least does the multiprocessing data distribution automatically, detecting dependencies and input data that need to be transferred.

Finally, code: NumPy by example. 
Execute each section in an IPython cell (copy and paste, then shift-enter)

# First, we'll have to import NumPy and SciPy packages.
# IPython has "magics" (macros) to help common tasks like this:
%pylab

# This will avoid scientific notation when printing, see also %precision

np.set_printoptions(suppress = True) 
#from __future__ import division # 1/2 = 0.5 instead of integer division... problem is that then 2/2 is float as well...

# In IPython notebook, cell execution is shift-enter
# In IPython-QT enter evaluates and control-enter is used for multiline input
# Tab is used for completion, shift-tab after a function name shows its help

# Note that IPython will display the output of the LAST expression in a cell
# but variable assignments in Python are NOT expressions, so they will
# suppress output, unlike Matlab or Mathematica. You will need to add print
# statements after the assignments in the following examples to see the output
data = [[1,2],[3,4],[5,6]]
# if you want to suppress output in the rare cases it's generated, use ;
data;

# There is a magic for help as well
%quickref
# Important magics are: %reset, %reset_selective, %whos
# %prun (profile), %pdb (debug), %run, %edit

# And you can use ? and ?? for details on a symbol
get_ipython().magic(u'pinfo %pylab')
# Other than the Python built in help() and dir(symbol)

1*3 # evaluate this in a cell

_*3 # _ refers to the output of last evaluated cell
# again, not that useful because you can't refer to the previous expression
# evaluated inside a cell, just to the previous evaluation of an entire cell

# A numpy array can be created from a homogeneous list-like object
arr = np.array(data)
# Or an uninitialized one can be created by specifying its shape
arr = np.ndarray((3,3))
# There are also many other "constructors"
arr = np.identity(5)
arr = np.zeros((4,5))
arr = np.ones((4,))
arr = np.linspace(2,3) # see also arange and logspace
arr = np.random.random((4,4))

# Arrays can also be created from functions
arr = np.fromfunction((lambda x: x*x), shape = (10,))
# ...or by parsing a string
arr = np.fromstring('1, 2', dtype=int, sep=',')

# Arrays are assigned by reference
arr2 = arr
# To create a copy, use copy
arr2 = arr.copy()

# An array shape is a descriptor, it can be changed with no copy
arr = np.zeros((4,4))
arr = arr.reshape((2,8)) # returns the same data in a new view
# numpy also supports matrices, which are arrays contrained to be 2d
mat = np.asmatrix(arr)
# Not all operations avoid copies, flatten creates a copy
arr.flatten()
# While ravel doesn't
arr = np.zeros((4,4))
arr.ravel()


# By default numpy arrays are created in C order (row-major), but 

# you can arrange them in fortran order as well on creation,
# or make a fortran-order copy of an existing array
arr = np.asfortranarray(arr)
# Data is always contiguously packed in memory

# Arrays can be indexed as with python lists/tuples
arr = np.zeros((4,4))
arr[0][0]
# Or with a multidimensional index
arr[0,0]
# Negative indices start from the end
arr[-1,-1] # same as arr[3,3] for this array

# Or, like matlab, via splicing of a range: start:end
arr = arange(10)
arr[1:3] # elements 1,2
arr[:3] # 0,1,2
arr[5:] # 5,6,7,8,9
arr[5:-1] # 5,6,7,8
arr[0:4:2] # step 2: 0,3
arr = arr.reshape(2,5)
arr[0,:] # first row
arr[:,0] # first column

# Also, splicing works on a list of indices (see also choose)
arr = arr.reshape(10)
arr[[1,3,5]]

# and with a numpy array of bools (see also where)
arr=np.array([1,2,3])
arr2=np.array([0,3,2])
arr[arr > arr2]

# flat returns an 1D-iterator
arr = arr.reshape(2,5)
arr.flat[3] # same as arr.reshape(arr.size)[3]

# Core operations on arrays are "ufunc"tions, element-wise
# vectorized operations
arr = arange(0,5)
arr2 = arange(5,10)
arr + arr2

# Operations on arrays of different shapes follow "broadcasting rules"
arr = np.array([[0,1],[2,3]]) # shape (2,2)
arr2 = np.array([1,1]) # shape (1,)
# If we do arr+arr2 arr2.ndim
# an input can be used if shape in all dimensions sizes, or if 
# the dimensions that don't match have size 1 in its shape
arr + arr2 # arr2 added to each row of arr!


# Broadcasting also works for assignment:
arr[...] = arr2 # [[1,1],[1,1]] note the [...] to access all contents
arr2 = arr # without [...] we just say arr2 refers to the same object as arr
arr[1,:] = 0 # This now is [[1,1],[0,0]]
# flat can be used with broadcasting too
arr.flat = 3 # [[3,3],[3,3]]
arr.flat[[1,3]] = 2 # [[3,2],[2,3]]

# broadcast "previews" broadcasting results
np.broadcast(np.array([1,2]), np.array([[1,2],[3,4]])).shape


# It's possible to manually add ones in the shape using newaxis

# See also: expand_dims
print(arr[np.newaxis(),:,:].shape) # (1,2,2)
print(arr[:,np.newaxis(),:].shape) # (2,1,2)

# There are many ways to generate list of indices as well
arr = arange(5) # 0,1,2,3,4
arr[np.nonzero(arr)] += 2 # 0,3,4,5,6
arr = np.identity(3)
arr[np.diag_indices(3)] = 0 # diagonal elements, same as np.diag(arg.shape[0])
arr[np.tril_indices(3)] = 1 # lower triangle elements
arr[np.unravel_index(5,(3,3))] = 2 # returns an index given the flattened index and a shape

# Iteration over arrays can be done with for loops and indices
# Oterating over single elements is of course slower than native
# numpy operators. Prefer vector operations with splicing and masking
# Cython, Numba, Weave or Numexpr can be used when performance matters.
arr = np.arange(10)
for idx in range(arr.size):
    print idx
# For multidimensiona arrays there are indices and iterators
arr = np.identity(3)
for idx in np.ndindex(arr.shape):
    print arr[idx]
for idx, val in np.ndenumerate(arr):
    print idx, val # assigning to val won't change arr
for val in arr.flat:
    print val # assigning to val won't change arr
for val in np.nditer(arr):
    print val # same as before
for val in np.nditer(arr, op_flags=['readwrite']):
    val[...] += 1 # this changes arr

# Vector and Matrix multiplication are done with dot
arr = np.array([1,2,3])
arr2 = np.identity(3)
np.dot(arr2, arr)
# Or by using the matrix object, note that 1d vectors
# are interpreted as rows when "seen" by a matrix object
np.asmatrix(arr2) * np.asmatrix(arr).transpose()

# Comparisons are also element-wise and generate masks
arr2 = np.array([2,0,0])
print (arr2 > arr)
# Branching can be done checking predicates for any true or all true
if (arr2 > arr).any():
    print "at least one greater"

# Mapping a function over an array should NOT be done w/comprehensions
arr = np.arange(5)
[x*2 for x in arr] # this will return a list, not an array
# Instead use apply_along_axis, axis 0 is rows
np.apply_along_axis((lambda x: x*2), 0, arr)
# apply_along_axis is equivalent to a python loop, for simple expressions like the above, it's much slower than broadcasting
# It's also possible to vectorize python functions, but they won't execute faster
def test(x):
    return x*2
testV = np.vectorize(test)
testV(arr)

# Scipy adds a wealth of numerical analysis functions, it's simple
# so I won't write about it.
# Matplotlib (replicates Matlab plotting) is worth having a quick look.
# IPython supports matplotlib integration and can display plots inline
%matplotlib inline
# Unfortunately if you chose the inline backend you will lose the ability
# of interacting with the plots (zooming, panning...)
# Use a separate backend like %matplotlib qt if interaction is needed

# Simple plots are simple
test = np.linspace(0, 2*pi)
plt.plot(test, np.sin(test)) # %pylab imports matplotib too
plt.show() # IPython will show automatically a plot in a cell, show() starts a new plot
plt.plot(test, np.cos(test)) # a separate plot
plt.plot(test, test) # this will be part of the cos plot
#plt.show()

# Multiple plots can also be done directly with a single plot statement
test = np.arange(0., 5., 0.1)
# Notes that ** is exponentiation. 
# Styles in strings: red squares and blue triangles
plt.plot(test, test**2, 'rs', test, test**3, 'b^')
plt.show()
# It's also possible to do multiple plots in a grid with subplot
plt.subplot(211)
plt.plot(test, np.sin(test))
plt.subplot(212)
plt.plot(test, np.cos(test), 'r--')
#plt.show()

# Matplotlib plots use a hierarchy of objects you can edit to
# craft the final image. There are also global objects that are
# used if you don't specify any. This is the same as before
# using separate objects instead of the global ones
fig = plt.figure()
axes1 = fig.add_subplot(211)
plt.plot(test, np.sin(test), axes = axes1)
axes2 = fig.add_subplot(212)
plt.plot(test, np.cos(test), 'r--', axes = axes2)
#fig.show()

# All components that do rendering are called artists
# Figure and Axes are container artists
# Line2D, Rectangle, Text, AxesImage and so on are primitive artists
# Top-level commands like plot generate primitives to create a graphic

# Matplotlib is extensible via toolkits. Toolkits are very important.
# For example mplot3d is a toolkit that enables 3d drawing:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
points = np.random.random((100,3))
# note that scatter wants separate x,y,z arrays
ax.scatter(points[:,0], points[:,1], points[:,2])
#fig.show()

# Matplotlib is quite extensive (and ugly) and can do much more
# It can do animations, but it's very painful, by changing the
# data artists use after having generated them. Not advised.
# What I end up doing is to generate a sequence on PNG from
# matplotlib and play them in sequence. In general MPL is very slow.

# If you want to just plot functions, instead of discrete data,
# sympy plots are a usable alternative to manual sampling:
from sympy import symbols as sym
from sympy import plotting as splt
from sympy import sin
x = sym('x')
splt.plot(sin(x), (x, 0, 2*pi))

Resources:

Tutorials
Packages
  • Scipy: numpy, scipy, matplotlib, sympy, pandas
  • Optimization and learning
  • PyGTS, Gnu Triangulated Surface Library
  • Performance
    • SciPy Weave, inlines C code in Python code, compiles and links to python on demand.
    • Numba, a numpy "aware" compiler, targets LLVM, compiles in runtime (annotated functions)
    • Cython, compiles annotated python to C. Bottleneck uses it to accelerate some NumPy functions. (see also ShedskinPythran and ocl)
    • JobLib, makes multiprocessing easier (see IPython.Parallel too) but still not great as you can't have multithreading, multiprocessing means you'll have to send data around independent python interpreters :/
    • Parakeet, compiles annotated numpy functions to CPU and GPU code, similar to Numba
    • NumExpr, a fast interpreter of numerical expressions on arrays. Faster than numpy by aggregating operations (instead of doing one at at time)
    • Theano, targets cpu and gpu, numpy aware, automatic differentiation. Clumsy...
    • Nuikta, offline compiles python to C++, should support all extensions
    • PyPy, a JIT, with a tracing interpreter written in python. Doesn't support all extensions (the CPython C library interface)
    • Python/Cuda links
  • Non-homogeneous data
    • Blaze, like numpy but for non-homogeneous, incomplete data
    • PyTables, hierarchical data
  • Graphics/Plotting
    • For 3d animations, VisVis seems the only tool that is capable of achieving decent speed, quality, and has a good interface and support. It has a matlab-like interface, but actually creating objects (Line() instead of plot...) is muuuuch better/faster. Its successor is VisPy, still very experimental.
    • Bokeh, nice plotting library, 2d only, outputs HTML5/JS so it can be interacted with in IPython Notebook
    • Matplotlib toolkits (MPL is SLOW and rather ugly, but it's the most supported):
    • PyProcessing, not really a "scipy package" but useful, especially considering how bad the options for 3d plotting are right now. See also NodeBox OpenGL
    • Point Cloud Library
    • Chaco, another 2d plot/gui library, very OO, not useful for quickly graphing
    • mpld3, a matplotlib compatible library that emits HTML5/JS using d3.js
      • Others:
    # For anaconda windows distribution, to use mayavi you need to install
    # mayavi and wxpython, use from command line binstar search -t conda mayavi
    %gui wx
    %pylab wx
    %matplotlib inline
    # In Ipython Notebook %matplotlib has to come after pylab, it seems. 

    # "inline" is cool but "qt" and "wx" allows interactivity

    # qt is faster than wx, but mayavi requires wx

        • PyQwt 2d/3d library, faster than matplotlib but even uglier. PyQtGraph is another similar project. Good if interactivity is needed. Also provide GUI components to code interactive graphs.
        • DisLin, 2d/3d graphs. Does not seem to support animations
    Other

    iPhone Development Tutorials and Programming Tips

    Top iOS Development Resources For Week Ended October 19th, 2014

    by Johann at October 20, 2014 06:20 AM

    Post Category    Featured iPhone Development Resources,News

    Welcome back to our feature of the most popular new and updated iOS developer resources mentioned on the site from the last two weeks.

    The top resource this week is a project bootstrap  making a great starting point for your Xcode projects with many useful features for organization, debugging, and easier project setup.

    Here are the resources:

    1. KZBootstrap – An Xcode project bootstrap providing an excellent setup and adding features for extra warnings, easier debugging and more.  (share on twitter) (featured here)

    2. CacheKit – An easy to use flexible caching library providing database, disk, and memory caching.  (share on twitter) (featured here)

    3. AsyncDisplayKit – A library for creating high performance asynchronous user interfaces. (share on twitter) (featured here)

    Thanks for reading!


    Be the first to comment...

    Related Posts:

    FacebookTwitterDiggStumbleUponGoogle Plus

    Original article: Top iOS Development Resources For Week Ended October 19th, 2014

    ©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

    GameDev.Net Articles

    Dijkstra's Algorithm - Shortest Path

    October 19, 2014 06:14 PM

    Note - This is not my area of expertise but I am very much interested in it and I welcome any corrections

    Outline


    This post will cover the basics of Dijksta's shortest path algorithm and how it can apply to path finding for game development. It is my opinion that understanding this algorithm will aid in understanding more complex AI algorithms, such as A*. This post is aimed more towards developers starting out in game development or those curious about Dijkstra's algorithm, but this will be a somewhat simplification of it and discuss mainly the concepts.

    Introduction


    What’s an algorithm?


    An algorithm is basically a system for solving a problem. For us humans, looking at a 2D grid with many objects we can easily tell which path the character should take to reach his or her goal without thinking much about it. What we want to try to do is translate those semi-subconscious mental steps to a list of steps that anyone (or a computer) can repeat to get the same answer every time.

    Finding the shortest route from one object to another when developing game AI is a very common problem and many solutions exist. At least in 2D grid / tile based games, perhaps the most common one is A*, with Dijkstra's being also quite good. Depending on the complexity of the game, Dijkstra's algorithm can be nearly as fast as A*, with some tweaking. A* is generally a better implementation, but can be slightly more complex, so I'm going to discuss the fundamentals of Dijkstra's algorithm and in later posts talk about others, such as A*.

    I'll be using the word graph here a lot, and it may not be immediately obvious how this translates to game dev, but you can easily translate this to 2D grid or tile based maps.

    Dijkstra’s Algorithm


    Let's first define what exactly the problem is. Take this graph, for instance.


    Attached Image: shortest_path1.png


    For the purposes of this post, the blue circles represent "nodes" or "vertices" and the black lines are "edges" or "node paths". Each edge has a cost associated with it. For this image, the number in each node is simply a label for the node, not the individual node cost.

    Our problem is to find the most cost efficient route from Node1 to Node4. The numbers on the node paths represent the "cost" of going between nodes. The shortest path from Node1 to Node4 is to take Node1 to Node3 to Node4, as that is the path where the least cost is incurred.

    Specifically, the cost to go from Node1 to Node3 is (2), plus the cost of Node3 to Node4 (5) is 7 (2 + 5).

    Now, we can see that the alternative (Node1 to Node2 to Node4) is much more costly (it costs 11, versus our 7).

    An important note - greedy algorithms aren't really effective here. A greedy algorithim would bascially find the cheapest local costs as it traverses the graph with the hopes that it would be globally optimum when it's done. Meaning, a greedy algorithm would basically just take the first low value it sees. In this case, the lower value is 1 but the next value is 10. If we were to simply just apply a greedy algorithm, we end up taking the more costly route from Node1 to Node4.

    Figuring out the best path to take with this graph is pretty easy for us to do mentally, as if you can add small numbers you can figure out the best path to take. The goal is translate the steps we take in our mind to steps a computer can follow.

    Dijkstra's algorithm is an algorithm that will determine the best route to take, given a number of vertices (nodes) and edges (node paths). So, if we have a graph, if we follow Dijkstra's algorithm we can efficiently figure out the shortest route no matter how large the graph is.

    Dijkstra's algorithm provides for us the shortest path from NodeA to NodeB.

    This high level concept (not this algorithm specifically) is essentially how Google maps provides you directions. There are many thousands of vertices and edges, and when you ask for directions you typically want the shortest or least expensive route to and from your destinations.

    So, how does this apply to game AI? Well, the correlation is quite strong. In a 2D grid or tile based map, there are many nodes (or tiles) and each tile can have a value associated with it (perhaps it is less expensive to walk across grass than it is to walk across broken bottles or lava).

    You can set up your tiles so that each tile has a node path value associated with it, so if you put an non player character (NPC) in the map you can use Dijkstra's algorithm to compute the shortest path for the NPC to take to any tile in your map.

    How it works


    First we'll describe Dijsksta's algorithm in a few steps, and then expound on them further:

    Step 0


    Temporarily assign C(A) = 0 and C(x) = infinity for all other x.
    C(A) means the Cost of A
    C(x) means the current cost of getting to node x


    Step 1


    Find the node x with the smallest temporary value of c(x).
    If there are no temporary nodes or if c(x) = infinity, then stop.
    Node x is now labeled as permanent. Node x is now labeled as the current node. C(x) and parent of x will not change again.


    Step 2


    For each temporary node labeled vertex y adjacent to x, make the following comparison:
    if c(x) + Wxy < c(y), then c(y) is changed to c(x) + Wxy
    assign y to have parent x


    Step 3


    Return to step 1.


    Before diving into a little more tricky graph, we'll stick with the original graph introduced above. Let's get started.

    Step 0.


    Temporarily assign C(A) = 0 and C(x) = infinity for all other x. C(A) means the Cost of A C(x) means the current cost of getting to node x.

    The following graph has changed a little from the one shown above. The nodes no longer have labels, apart from our starting point NodeA and our goal NodeB.


    Attached Image: sp_1_1.png


    Legend


    Orange line – path to parent node
    Yellow arrow – points to the node’s parent
    Green node cost text – node cost is permanent
    White node cost test – node is temporary
    Yellow highlight – Current node


    We assign a cost of 0 to Node A and infinty to everything else. We're done with this step now.

    Step 1


    Find the node x with the smallest temporary value of c(x).
    If there are no temporary nodes or if c(x) = infinity, then stop.
    Node x is now labeled as permanent. Node x is now labeled as the current node. C(x) and parent of x will not change again.
    Since 0 is the lowest value, we set A as the current node and make it permanent.

    Step 2


    For each temporary node labeled vertex y adjacent to x, make the following comparison:
    if c(x) + Wxy < c(y), then
    c(y) is changed to c(x) + Wxy
    assign y to have parent x

    There are two temporary nodes adjacent to our current node, so calcuate their cost values based on the current node's value + the cost of the adjacent node. Assign that value to the temporary node only if it's less than the value that's already there. So, to clarify:

    The top node is adjacent to the current node and has a cost of infinity. 0 (the current node's value) + 1 (the cost associated with the temporary node) = 1, which is less than infinity, so we change its value from infinity to 1. This value is not yet permanent.

    Now, do the same calucation for the next adjacent node. which is the bottom node. The value is 0 + 2 = 2, which is also less than infinity.

    To illustrate:


    Attached Image: sp_1_2.png
    </center>
    So we now have looked at each temporary node adjacent to the current node, so we're done with this step.

    Step 3


    Return to step 1.


    So, let's go back to step 1. From this point forward, I'll be using the term iteration to describe our progression through the graph via Dijkstra's algorithm. The steps we previously took I'll refer to as iteration 0, so now when we return to step 1 we'll be at iteration 1.

    Iteration 1


    We’re back at the first step. It says look for the smallest temporary cost value and set it as permanent. We have two nodes to look at, the top node with cost 1 and the bottom node with cost 2.

    The top node has a cost of 1, which is less than 2, so we set it as permanent and set it as our current node. We designate this by a yellow shadow in the image. Now, it is important to keep in mind that the bottom node still has a temporary cost assigned to it. This temporary cost is what allows the algorithm to find actual cheapest route – you’ll see in a second.

    Step 1


    Find the cheapest node. Done, it’s set as permanent and our current node is this one. This node value will not change.


    Attached Image: sp_2_1.png
    </center>
    The yellow highlight indictates the node we are currently on, and the green text means the node cost is permanent. The nodes with white text for their costs are temporary nodes.

    Step 2


    Assign cost values. There is only one adjacent node to our current node. Its current value is infinity, which is less than 1 + 10, so we assign 11 to its temporary cost value.


    Attached Image: sp_2_2.png
    </center>
    This is not the shortest path from NodeA to NodeB, but that's fine. The algorithm traverses all nodes in the graph, so you get the shortest path from a node to any other node. You can see that the shortest path from NodeA to the top node is the line between NodeA and the top node - well, of course, you say, because that's the only possible path from NodeA to the top node. And you are right to say that, because it's true. But let's say we have a node above the top node (we'll call it Top2). The shortest path to that would from NodeA to the top node to node Top2. Even though our goal is to go from A to B, as a side effect we also get the shortest route to every other node. If that's a bit unclear, it should clear up after we go through the next iteration.

    Done with step 2, let's continue to step 3.

    Step 3


    Return to step 1.


    Iteration 2


    Ok, so now we look again at the temporary nodes to see which has the lowest value. Even though we calculated the temporary value of B as 11, we are not done because that value might change (in this case, it will definitely change).

    Step 1


    Pick the cheapest node from the remaining temporary nodes. Set it as the current node, make it permanent, and then assign the parent.

    Let’s take a look at the graph to elucidate a bit. We have two remaining temporary nodes. Out of the costs 11 and 2, pick the cheaper node (2). We set this node’s value to be permanent and assign its parent is NodeA, demonstrated by the arrow.


    Attached Image: sp_3_1.png
    </center>


    Step 2


    Assign cost values to temporary nodes adjacent to the current node. Again, like in the previous iteration, there is only one node to do a cost calculation on, as there is only one temporary node adjacent to the current node. This adjacent node is NodeB. So, we check to see if 2 + 5 < Node B’s temporary cost of 11. It is, so we change Node B from 11 to 7.


    Attached Image: sp_3_2.png
    </center>


    Step 3


    Return to step 1


    Iteration 3


    Almost done.

    Step 1


    Choose the cheapest temporary node value. There is only one temporary node remaining, so we pick it and set it as permanent, set it as our current node, and set its parent.


    Attached Image: sp_4_1.png
    </center>


    Step 2


    Assign costs. There are no temporary nodes adjacent to Node B (there –are- permanent nodes, but we don’t check them).

    Step 3


    Return to step 1.


    Iteration 4


    Step 1


    Choose the cheapest temporary node. If none exists or c(x) = infinity, then stop. There are no more temporary nodes and no nodes have values of infinity, so we’re done. Algorithm has finished, and we have our shortest path from A to B, but also from that node to every other node in the graph. With such a small graph as this, it's not immediately obvious how powerful and useful this algorithim is.


    Another Example


    So, on to a more complicated graph now.


    A is our starting point, and B is the ending point. Now, we could just as well apply this to a 2D tile based game where A could represent an NPC and B could represent the NPC's desired destination.

    If you take a minute, you can probably find the least expensive route yourself. As mentioned earlier, it's fairly trivial for us to come up with the answer, what we need to do is figure out how to convey the steps we take to more extensible steps that can be repeated by a computer for any graph. For this graph, I won't be as thorough explaining every step, but the exact same process is applied. Instead, I'll just provide an example of a slightly more complex graph and what it would look like using Dijkstra's algorithm.


    Step 0


    Temporarily assign C(A) = 0 and C(x) = infinity for all other x.
    C(A) means the Cost of A
    C(x) means the current cost of getting to node x
    So what's this mean? Well, our start point is A so c(A) = 0 means assign A a cost of 0 and set the cost of x for every other node to infinity. Like the following


    Attached Image: shortest_path2_1.PNG
    </center>
    We assign a cost of 0 to our starting node A and a cost of infinity to every other node. As before, none of these costs are permanent yet.


    Step 1


    The node with the smallest temporary value is node A with a cost of 0. Therefore, we're going to make it permanent - meaning c(x) and the parent will not change.


    Attached Image: shortest_path2_1_a_selected.png
    </center>
    The 0 will not change now. If there are no temporary nodes, or if c(x) is infinity, the algorithm stops. Now, step 2.


    Step 2


    Basically, we're going to look at all the nodes that are connected to the currently selected node and calculate the cost to get to them. If the cost of y is less than what it previously was, it will change - this will be discussed soon.

    So, let's first calculate the cost to get to the adjacent nodes. The cost is based on the value of the current node code plus the edge (node path) cost. Right now, since this our first go, the cost of our current node is at 0 since we haven't done any traversals.

    So, let's start to figure out the c(x), the node costs.


    Attached Image: shortest_path2_1_a_selected_3.png
    </center>
    Notice the yellow arrows. I'm using them to designate what node it got its cost from. Here, since there is only one possible parent node, they all point to the same place.

    For the three nodes adjacent to A, we add the values of the edge and our current node (value of 0). So, the top node is 0 + 3 = 3, which is less than the current value (which is infinity), so we apply the value of 3 to the node. Then, the middle node 0 + 7 = 7, also less than infinity. Finally the bottom node has a value of 0 + 5 = 5, which is less than infinity. Therefore, the top node has a c(x) of 3, the middle a c(x) of 7, and the bottom a c(x) of 5.

    Step 3.


    Return to step 1

    As before, we just iteratively go through graph applying the same steps.

    So, walking through this - as step 1 says:

    We find node x with the smallest temporary value of c(x). So, out of the three temporary nodes with values 3, 5, and 7 that we just worked out, the smallest value is 3. We then make this node permanent.


    Attached Image: shortest_path3_2.png


    Now, this entire process just repeats itself over and over until there are no more temporary nodes.


    Attached Image: shortest_path_final.png


    And we're done. We have the shortest path from nodeA to any other node (or vice versa). Pretty convenient.

    Conclusion


    Hopefully that explains a bit about how Dijkstra's Algorithm works. For game development, in particular overhead 2D tile based games, it is usually easier to implement Dijkstra's than A*, and not much worse performance wise.

    Performance


    How well does Dijsktra's algorithm perform? Well, in terms of big O notion it is O(n^2), which is efficient. Specifically, suppose G has n vertices and m edges. Going through the steps, Step 0 has time n. Step 1 is called, at the very most, n times. Finding the cheapest vertex takes at most n steps, so step 1 has an upper bound time of n^2. In Step 2, each edge / node path is examined, at most, twice. There, the upper bound time is 2m. So, putting it all together, it's no worse than n^2 + 2m. Again, in computer science terms, it is O(n^2) efficient; or: on the order of at most n^2 steps times a constant.

    Better algorithms for NPC path finding certainly exist, but in general Dijkstra's is pretty good, and fairly easy to implement yourself.

    A good explanation of implementation in python can be found at https://gist.github.com/econchick/4666413 and a javascript implementation can be found here.

    Article Update Log

    21 October 2014: Adds clarifications to Iteration 2, Step 1 paragraph
    19 October 2014: Initial release