Unity Bitmap Drawing API for textures – open source

I just released one of my side-side-projects as open source, Bitmap Drawing API extension methods for Unity 3D’s Texture2D class. This is also coming to the Asset Store early next week.

Get it from GitHub: https://github.com/ProtoTurtle/UnityBitmapDrawing

Get it from the Asset Store: (coming in a few days)
What is it?
By default, Texture2D only provides the methods SetPixel and GetPixel (and SetPixels and GetPixels). This library extends that functionality with useful basic drawing operations. It outputs pixel perfect and not anti-aliased bitmaps.

1
texture.DrawLine(new Vector2(0,0), new Vector2(100,200), Color.red);
texture.DrawLine(new Vector2(0,0), new Vector2(100,200), Color.red);

x = 0, y = 0 is the top left corner
This library uses the convention of having the left top corner of the bitmap be the 0, 0 position. By default, Texture2D uses the bottom left corner convention which can be confusing for bitmap operations.

Extension Methods
ScreenShot
C# Extension Methods work in a way that adds methods to a existing class. To start using this, you only need to include the namespace:

1
using ProtoTurtle.BitmapDrawing;
using ProtoTurtle.BitmapDrawing;

Your Texture2D instances will then have all the new methods available.

Features

  • DrawPixel(position, color) – Draws a pixel but with the top left corner being position (x = 0, y = 0)
  • DrawLine(start, end, color) – Draws a line between two points
  • DrawCircle(position, radius, color) – Draws a circle
  • DrawFilledCircle(position, radius, color) – Draws a circle filled with a color
  • DrawRectangle(rectangle, color) – Draws a rectangle or a square
  • DrawFilledRectangle(rectangle, color) – Draws a rectangle or a square filled with a color
  • FloodFill(position, color) – Starts a flood fill of a certaing at the point

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using ProtoTurtle.BitmapDrawing;
 
// ...
 
Texture2D texture = new Texture2D(1024, 1024, TextureFormat.RGB24, false, true);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.DrawFilledRectangle(new Rect(0, 0, TEXTURE_SIZE, TEXTURE_SIZE), Color.grey);
 
texture.DrawCircle(100, 100, 20, Color.green);
texture.DrawCircle(80, 150, 5, Color.blue);
texture.DrawCircle(300, 300, 200, Color.black);
texture.FloodFill(100, 100, Color.green);
texture.FloodFill(300, 300, Color.white);
texture.DrawLine(new Vector2(10, 10), new Vector2(400, 200), Color.magenta);
texture.DrawLine(new Vector2(400, 200), new Vector2(100, 200), Color.magenta);
texture.Apply();
using ProtoTurtle.BitmapDrawing;

// ...

Texture2D texture = new Texture2D(1024, 1024, TextureFormat.RGB24, false, true);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.DrawFilledRectangle(new Rect(0, 0, TEXTURE_SIZE, TEXTURE_SIZE), Color.grey);

texture.DrawCircle(100, 100, 20, Color.green);
texture.DrawCircle(80, 150, 5, Color.blue);
texture.DrawCircle(300, 300, 200, Color.black);
texture.FloodFill(100, 100, Color.green);
texture.FloodFill(300, 300, Color.white);
texture.DrawLine(new Vector2(10, 10), new Vector2(400, 200), Color.magenta);
texture.DrawLine(new Vector2(400, 200), new Vector2(100, 200), Color.magenta);
texture.Apply();

Output from this example (cropped the image to fit):
ScreenShot

Example project
Here is a ready-to-go Unity project for easy testing.
https://github.com/ProtoTurtle/BitmapDrawingExampleProject

Github: Wooga’s HTML5 Pocket Island

Wooga recently released their first full HTML5 game (experiment) on GitHub. Pocket Island is a pretty classical Facebook Building-Stuff-Game™.

Pocket I5land

It’s very rare to to get a glimpse at a large HTML5-game codebase so I think this is definitely worth a look to see how one of the big Facebook devs did things. To be fair Wooga gave up on HTML5 as a platform for now after this project, but it’s nonetheless an educational project to explore.

There’s solid documentation on how to get started with this.

Check it out on GitHub:
https://github.com/wooga/Pocket-Island

Doodle Paint5 – Open source HTML5 painting app

One of my first HTML5 apps was this Canvas-based painting app for the Pokki platform. Pokki adds these web-apps to the taskbar of your OS and launches them very quickly. Doodle Paint5 is an app for quick doodling and painting.

It got the nth place in the first Pokki contest netting me a sweet t-shirt and is the most popular and top rated “Art and Design” app! Also the only one.

Cool campfire

 

Check out the app here:
http://www.pokki.com/app/Doodle-Paint5

Get the full source from GitHub:
Doodle Paint5 on GitHub