[F/OS] 🎨 ColorUtilities - Some Tools To Work With Colors

:computer: Introduction

A non-visible extension that provides some tools to work with colors.

:date: Release date: 2022-04-19T11:00:00Z

:clock5: Version: 2

:package: Package name: com.gordonlu.colorutilities

:hammer_and_wrench: Built with: Niotron IDE

An integer color, represented in a number (e.g. 12345678), is the standard color used in App Inventor.

:open_book: Documentation

BlendColors

image

Blends two colors together. The ratio parameter should be a value between 0 and 1.

Returns: color

Parameters: color1 = color, color2 = color, ratio = number (double)

ConvertHexToInt

image

Convert a hex color to a integer color, which is used in the standard App Inventor color system.

Returns: number (int), or color

Parameters: hexColor = text

ConvertIntToHex

image

Convert a integer color to a hex color.

Returns: text

Parameters: number (int), or color

DarkenColor

image

Darkens the color with the given factor. The factor should be a value between 0 and 1.

Returns: color

Parameters: color = color, factor = number (double)

GetLuminance

image

Returns the luminance of a color as a double number between 0 and 1.

Returns: number (double)

Parameters: color = color

IsDarkColor

image

Checks whether the color is a dark color or a light color.

Returns: boolean

Parameters: color = color

LightenColor

image

Lightens the color with the given factor.

Returns: color

Parameters: color = color, factor = number (double)

:books: FAQ

Q1: Please provide the random color / arbitrary color block.

A1: Blocks-only solution:

Q2: Please provide the SetAlphaValue block.

A2: Another blocks only solution:

:+1: Credits

Some snippets taken from https://vimsky.com/zh-tw/examples/detail/java-method-android.graphics.Color.argb.html, and some reference taken from https://docs.kodular.io/components/utilities/color-utilities/. Thank you Kodular!

:inbox_tray: Downloads

AIX:
com.gordonlu.colorutilities.aix (8.1 KB)

JAVA:
ColorUtilities.txt (3.8 KB)


Made with Niotron IDE.

Kindly :email: PM me if you have any questions! Also, if you like my extension, please :heart: like it! It takes some effort for me to make it...

Likes tell me the general user feedback of my extension. If you read this extension, please take 20 seconds to drop by and give a like!

If you have any features that you want to add and you know the code, PM me or directly reply below using the image button.

If you find any :lady_beetle: bugs, please reply below.

P.S. I will release my next extension very soon. Are you ready for it?


Gordon Lu

:speech_balloon: Message :earth_africa: Website

4 Likes

The best color extension i have ever seen thanks @Gordon_Lu

Hi, thanks for a great extensionπŸ™‚
I'm trying to giving my buttons a green scale color, and I thought this would work:


Setting each button 20% lighter than the previous one.
But instead I get all sorts of colors, so what am I doing wrong?
Screenshot 2022-12-11 at 09-38-41 Foto - Google Foto

Ove B-)

It says the factor should be a number between 0 and 1. What if you try 0.2 here? Didn't try it myself.

1/5 = 0.2 :slight_smile:

I know, just thinking with you. :wink:

Trying different factors: 0.2, 0.02, 0.01 and it kind of gives me random colors.

I just tested it. I also get random colors.

Very interesting...I'll see what goes wrong...

1 Like

In Darkening you split the color in r,g,b before darkening. You don't do that with Lighten. Could that be the problem?

Among the colors I tried, only red is working fine.

image

The rest, dark green, dark blue, all returned random colors. I'ma think for a second.