Git Product home page Git Product logo

paleta's Introduction

Paleta PyPI version

Paleta Preview Game Sprite

Paleta is a Color Pallet Extraction and Management Tool that is focused on enhancing Visual Game Assets. It supports pallet conversion, mixing, minimizing, and matching in any way possible.

Quick Guide

from paleta.color import Color
from paleta.palette import Palette
from paleta.image import export_palette, extract_convert_palette

# Initializing Colors
red = Color.from_hex("#F00")
green = Color.from_hex("#0F0")
blue = Color.from_hex("#00F")

# Operations on Color
magenta = red + blue
yellow = red + green
cyan = green + blue

print(magenta.rgba)  # Get RGBA value
print(yellow.to_lightness())  # To 0...255 Value
print(cyan.to_hsl())  # Get HSL Value

magenta += 10  # Add 10 across values of RGB
cyan -= (10, 0, 10)  # Subtract 10 across R and B value

twilight_5 = Palette(
    Color.from_hex("fbbbad"),
    Color.from_hex("ee8695"),
    Color.from_hex("4a7a96"),
    Color.from_hex("333f58"),
    Color.from_hex("292831")
)  # Create a Palette Class

tw = Palette.from_lospec("twilight-5")  # Or use the Lospec API

assert (twilight_5.colors == tw.colors)  # They're the same

twilight_5.add(yellow)  # Add yellow to the palette
twilight_5.remove(yellow)  # And Remove it

warm_ochre = Palette.from_lospec("warm-ochre")
the_after = Palette.from_lospec("the-after")

twilight_5.union(warm_ochre)  # Combine Palette Sets
twilight_5.intersection(the_after)  # Or find where they intersect

extract_convert_palette("ref.png", "palette.png", f_out="new_ref.png")  # Map a Palette to an Image
export_palette(warm_ochre, f="warm-ochre.png")  # Export a Created or Imported Palette

The script above shows the basics for simple use of this package. Simply, it treats Colors as a Vector(R, G, B, Alpha[Optional=255]) and a Palette as a Set of Colors with all basic set operations.


Going Deeper

Mapping Palettes

from paleta.palette import Palette
from paleta.palette import ConversionPalette
from paleta.metric import euclidean_distance, cosine_distance, cosine_similarity

warm_ochre = Palette.from_lospec("warm-ochre")
the_after = Palette.from_lospec("the-after")

# Will create a Dictionary of how Palette (Warm Ochre) be mapped with Palette (The After)
# Using a Euclidean Distance Function and the Metric of Minimum Distance
cmap = ConversionPalette.map(warm_ochre, the_after, algo=euclidean_distance, metric=min)
print(cmap.to_dict())


# Making your own function works
def some_distance_function() -> float:
    # Map by distance
    return float()


def some_metric_function() -> object:
    # Find Max Value
    return max()


cmap2 = ConversionPalette.map(warm_ochre, the_after, algo=some_distance_function, metric=some_metric_function)
print(cmap2.to_dict())

# Randomize the Mapping
cmap3 = ConversionPalette.random(warm_ochre, the_after)
print(cmap3.to_dict())

Minimize or Maximize Palette

from paleta.palette import Palette
from paleta.palette import minimize_by_average, maximize_by_average

warm_ochre = Palette.from_lospec("warm-ochre")
the_after = Palette.from_lospec("the-after")

# Reduce the Palette by Averaging Neighboring Colors
min_warm_ochre = minimize_by_average(warm_ochre)
print(warm_ochre.color_set)
print(minimize_by_average(warm_ochre).color_set)
print(len(min_warm_ochre))

# Increase the Palette by Adding the Averaging of Neighboring Colors
max_the_after = minimize_by_average(the_after)
print(the_after.color_set)
print(minimize_by_average(the_after).color_set)
print(len(max_the_after))

paleta's People

Contributors

abhishtagatya avatar

Watchers

 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.