Giter Site home page Giter Site logo

kyapp69 / unitybitmapdrawing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prototurtle/unitybitmapdrawing

0.0 0.0 0.0 230 KB

Bitmap Drawing API extension methods for Unity 3D's Texture2D class

Home Page: http://prototurtle.com/unitybitmapdrawing/

License: MIT License

C# 100.00%

unitybitmapdrawing's Introduction

UnityBitmapDrawing

http://prototurtle.com

Bitmap Drawing API extension methods for Unity 3D's Texture2D class.

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.

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:

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

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

unitybitmapdrawing's People

Contributors

prototurtle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.