Coder Social home page Coder Social logo

kristoisberg / pawn-colour-manipulation Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 2.0 16 KB

Library providing numerous colour manipulation functions for the PAWN language.

Pawn 100.00%
pawn pawn-package sa-mp sa-mp-library color colours colour colors color-manipulation colour-manipulation

pawn-colour-manipulation's Introduction

PAWN Colour Manipulation

sampctl

Notice: This repository is not being actively maintained anymore. If anyone wishes to continue the development of the project, please create a fork of the repository and release future versions there.

This library provides a number of easy-to-use colour manipulation functions for PAWN.

Installation

Simply install to your project:

sampctl package install kristoisberg/pawn-colour-manipulation

Include in your code and begin using the library:

#include <colour-manipulation>

Testing

To test, simply run the package:

sampctl package run

There is also a separate test script (samp-grayscale-bitmap) that unfortunately doesn't work yet due to a bug in samp-bitmapper.

Functions

GetColourComponents(colour, &Float:r, &Float:g, &Float:b, &Float:a = 1.0, ColourMode:mode = COLOUR_MODE_RGBA)

Extracts the RGB(A) components from a colour code.

Float:GetColourComponent(colour, ColourComponent:component, ColourMode:mode = COLOUR_MODE_RGBA)

Extracts an individual colour component from a colour code and returns it.

SetColourComponent(colour, ColourComponent:component, Float:value, ColourMode:mode = COLOUR_MODE_RGBA)

Modifies an individual component of an existing colour and returns the new colour.

GetColourCode(Float:r, Float:g, Float:b, Float:a = 1.0, ColourMode:mode = COLOUR_MODE_RGBA)

Creates a colour code from RGB(A) components.

ConvertColour(colour, ColourMode:from, ColourMode:to, Float:alpha = 1.0)

Converts a colour from one colour mode to another. Alpha should be specified when converting from RGB, otherwise 0xFF (fully non-transparent) is used.

InterpolateColours(colour1, colour2, Float:amount, ColourMode:mode = COLOUR_MODE_RGBA)

Interpolates two colours. amount must be in the range 0.0 - 1.0. The larger amount is, the closer the returned colour is to colour2.

Float:GetColourBrightness(colour, ColourMode:mode = COLOUR_MODE_RGBA)

Returns the brightness of a colour.

DarkenColour(colour, Float:amount, ColourMode:mode = COLOUR_MODE_RGBA)

Darkens a colour by interpolating it with the black colour.

LightenColour(colour, Float:amount, ColourMode:mode = COLOUR_MODE_RGBA)

Lightens a colour by interpolating it with the white colour.

GrayscaleColour(colour, ColourMode:mode = COLOUR_MODE_RGBA)

Returns the grayscale equivalent of a colour.

Float:GetColourComponentFractValue(value)

Converts a binary colour component value to a fractional value.

GetColourComponentBinaryValue(Float:value)

Converts a fractional colour component value to a binary value.

Float:AddColourComponentGammaCor(Float:value)

Adds sRGB gamma correction to a colour component.

Float:RemoveColourComponentGammaCor(Float:value)

Removes the sRGB gamma correction from a colour component.

Definitions

Colour modes

COLOUR_MODE_RGBA - The most common colour format in SA-MP: used by SendClientMessage, textdraws, etc.

COLOUR_MODE_ARGB- Colour format used by SetObjectMaterial, SetObjectMaterialText and SetPlayerAttachedObject.

COLOUR_MODE_RGB - Colour format used by embedded colours, probably the most common colour format outside of SA-MP, most notably in webpages.

Colour components

COLOUR_COMPONENT_R - Red

COLOUR_COMPONENT_G - Green

COLOUR_COMPONENT_B - Blue

COLOUR_COMPONENT_A - Alpha

Notes

Both British and American spellings (color/colour, gray/grey) are supported for everything noted above.

pawn-colour-manipulation's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vasily-x r4sheed

pawn-colour-manipulation's Issues

Future updates

  • Move gamma correction and its reversal into separate functions.
  • Change the gamma correction formula to the one stated in the sRGB specification.
  • Change the usage of gamma correction in the interpolation function.
  • Add a function to get the brightness of a colour.
  • Add a function to get the equivalent grey colour of a colour.

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.