Section Colors

Color utility functions.

Summary

Return typeFunction and summary
string, string, intChooseColor(string object, table suggestedColors, selected)
Ask the user to choose one color in a menu.
booleanCropSurface(Surface surface, int red, int green, int blue, int opacity, string operand, boolean left, boolean top, boolean right, boolean bottom)
Crop a Surface for a given color.
intcolor_brightness(int red, int green, int blue, int opacity)
Get the brightness of a color A brightness between 0 and 127 is considered as dark, a brightness between 127 and 255 is considered as bright.

Functions

ChooseColor(string object, table suggestedColors, selected)

Ask the user to choose one color in a menu.

Choose staff line color, there are 5 favorites
If available, the list starts by a list of favorites colors, saved by previous choices for the same object (e.g. "Staff background").
Then, a list of suggested colors (e.g. found in score).
Then, the ability to pick a new color from the Color Picker, and save it to favorites for faster use next times.

ParameterTypeDefaultDescription
objectstring The name you want, e.g. "Staff background", "Staff lines"...
suggestedColorstablenilA table of string in [#]RRGGBB format (recommanded), or number color index
selected  A string in [#]RRGGBB format or number color index
Returns
string: Choosen color, in RRGGBB format, or nil if user canceled the choice.
string: Choosen color, in #RRGGBB format, or nil if user canceled the choice.
int: Color index, or nearest in 256 colors palette, or nil if user canceled the choice.

color_brightness(int red, int green, int blue, int opacity)

Get the brightness of a color A brightness between 0 and 127 is considered as dark, a brightness between 127 and 255 is considered as bright.

Without opacity, the formula is brightness = 0.2126*red + 0.7152*green + 0.0722*blue

ParameterTypeDefaultDescription
redint red
greenint green
blueint blue
opacityint255 
Return
int: brightness value, between 0 and 255

CropSurface(Surface surface, int red, int green, int blue, int opacity, string operand, boolean left, boolean top, boolean right, boolean bottom)

Crop a Surface for a given color.

For example, CropSurface(mySurface, 255, 255, 255, 255) crops surface to remove white areas on 4 sides of a drawn image/text/staff.

ParameterTypeDefaultDescription
surfaceSurface The surface to crop
redint Red value from 0 to 255
greenint Green value from 0 to 255
blueint Blue value from 0 to 255
opacityint255Opacity value from 0 to 255
operandstring"=="Operand for color to crop:
  • "==" to crop when pixel is arguments RGB+opacity
  • "~=" to crop when pixel is not arguments RGB+opacity
  • "<", "<=" to crop when all components of pixel are darker/more transparent (or equal) than argument RGB and opacity.
  • ">", ">=" to crop when all components of pixel are lighter/more opaque (or equal) than argument RGB and opacity.
leftbooleantrueCrop left side
topbooleantrueCrop top side
rightbooleantrueCrop right side
bottombooleantrueCrop bottom side
Return
boolean: true if crop was needed and succeed, return by Surface.Crop(...) MyrScript function.