Giter VIP home page Giter VIP logo

unity-color-palette's Introduction

About The Project

This is a unity library for generating a color palette from an image ported from Android's Palette API

Installation

Download the Latest release of the unity package and open it while the Unity Editor is open.

Create a palette

A Palette object gives you access to the primary colors in an image, as well as the corresponding colors for overlaid text. Use palettes to design your games's style and to dynamically change your games's color scheme based on a given source image.

Generate a Palette instance

Generate a Palette instance using Palette's Generate(Texture2D texture) function

Palette palette = Palette.Generate(image.sprite.texture);

Based on the standards of material design, the palette library extracts commonly used color profiles from an image. Each profile is defined by a Target, and colors extracted from the texture image are scored against each profile based on saturation, luminance, and population (number of pixels in the texture represented by the color). For each profile, the color with the best score defines that color profile for the given image.

The palette library attempts to extract the following six color profiles:

  • Light Vibrant
  • Vibrant
  • Dark Vibrant
  • Light Muted
  • Muted
  • Dark Muted

Each of Palette's Get<Profile>Color() methods returns the color in the palette associated with that particular profile, where <Profile> is replaced by the name of one of the six color profiles. For example, the method to get the Dark Vibrant color profile is GetDarkVibrantColor(). Since not all images will contain all color profiles, you can also provide a default color to return.

This figure displays a photo and its corresponding color profiles from the Get<Profile>Color() methods.

MutedColor.color = palette.GetMutedColor();
VibrantColor.color = palette.GetVibrantColor();
LightMutedColor.color = palette.GetLightMutedColor();
LightVibrantColor.color = palette.GetLightVibrantColor();
DarkMutedColor.color = palette.GetDarkMutedColor();
DarkVibrantColor.color = palette.GetDarkVibrantColor();

You can aso create more comprehensive color schemes using the GetBodyTextColor() and GetTitleTextColor() extension methods of Unity's Color. These methods return colors appropriate for use over the swatch’s color.

Color vibrantColor = palette.GetVibrantColor();
backgroud.color = vibrantColor;
text.color = vibrantColor.GetTitleTextColor();

An example image with its vibrant-colored toolbar and corresponding title text color.

Preview

These are some preview images from the Unity Editor

unity-color-palette's People

Contributors

ookii-tsuki 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.