Examples :: Make a palette clip with all Avisynth named colors

This script demonstrates the array facilities of AVSLib (Stack is also implemented with arrays). The example creates a color palette (ie a 2D matrix with colored rectangles) from all Avisynth's named colors

The result of running the script is presented below.

 

Figure 1: Clip produced by example script

example script's output clip

 

Now the script:

LoadModule("avslib", "array", "core")
LoadModule("avslib", "array", "operators")
LoadModule("avslib", "array", "slices")
LoadModule("avslib", "filters", "stack")

# make an array with all named Avisynth colors (colors_rgb.avsi); white, gray, black first

colors1 = ArrayCreate( \
	color_white, color_gray10, color_gray20, color_gray30, color_gray40, \
	color_gray50, color_gray60, color_gray70, color_gray80, color_gray90, \
	color_black, color_aliceblue, color_antiquewhite, color_aqua, color_aquamarine, \
	color_azure, color_beige, color_bisque, color_blanchedalmond, color_blue, \
	color_blueviolet, color_brown, color_burlywood, color_cadetblue, color_chartreuse, \
	color_chocolate, color_coral, color_cornflowerblue, color_cornsilk, color_crimson, \
	color_cyan, color_darkblue, color_darkcyan, color_darkgoldenrod, color_darkgray, \
	color_darkgreen, color_darkkhaki, color_darkmagenta, color_darkoliveGreen, \
	color_darkorange, color_darkorchid, color_darkred, color_darksalmon, \
	color_darkseaGreen, color_darkslateBlue, color_darkslateGray, color_darkturquoise, \
	color_darkviolet, color_deeppink, color_deepskyblue)

colors2 = ArrayCreate( \
	color_dimgray, color_dodgerblue, color_firebrick, color_floralwhite, \
	color_forestgreen, color_fuchsia, color_gainsboro, color_ghostwhite, color_gold, \
	color_goldenrod, color_gray, color_green, color_greenyellow, color_honeydew, \
	color_hotpink, color_indianred, color_indigo, color_ivory, color_khaki, \
	color_lavender, color_lavenderblush, color_lawngreen, color_lemonchiffon, \
	color_lightblue, color_lightcoral, color_lightcyan, color_lightgoldenrodyellow, \
	color_lightgreen, color_lightgrey, color_lightpink, color_lightsalmon, \
	color_lightseagreen, color_lightskyblue, color_lightslategray, color_lightsteelblue, \
	color_lightyellow, color_lime, color_limegreen, color_linen, color_magenta, \
	color_maroon, color_mediumaquamarine, color_mediumblue, color_mediumorchid, \
	color_mediumpurple, color_mediumseagreen, color_mediumslatenlue, \
	color_mediumspringgreen, color_mediumturquoise, color_mediumvioletred)

colors3 = ArrayCreate( \
	color_midnightblue, color_mintcream, color_mistyrose, color_moccasin, \
	color_navajowhite, color_navy, color_oldlace, color_olive, color_olivedrab, \
	color_orange, color_orangered, color_orchid, color_palegoldenrod, \
	color_palegoldenrod, color_palegreen, color_paleturquoise, color_palevioletred, \
	color_papayawhip, color_peachpuff, color_peru, color_pink, color_plum, \
	color_powderblue, color_purple, color_red, color_rosybrown, color_royalblue, \
	color_saddlebrown, color_salmon, color_sandybrown, color_seagreen, color_seashell, \
	color_sienna, color_silver, color_skyblue, color_slateblue, color_slategray, \
	color_snow, color_springgreen, color_steelblue, color_tan, color_teal, color_thistle, \
	color_tomato, color_turquoise, color_violet, color_wheat, color_whitesmoke, \
	color_yellow, color_yellowgreen)

colors = ArrayJoin(colors1, colors2, colors3)

# Create a custom function that returns a clip with the color passed in

Function PaletteCell(int palette_color) {
	global color_num = color_num + 1
	return BlankClip(color=palette_color, width=60, height=40, length=1 \
		).SubTitle(String(color_num), size=12, text_color=color_black, \
		halo_color=color_gray50)
}

# use colors and custom function to make an array with palette cells clips

global color_num = 0
palette = colors.ArrayOpFunc("PaletteCell")

# Since we have 150 colors we will stack them in a 12x13 = 154 cell grid
# Last 4 cells will be black (empty).
# This will result in a 780x480 clip taking into account the w,h values in custom function

return Stack(palette, 12, 13)

The script creates an array with all named Avisynth colors (using a combination of the ArrayCreate and ArrayJoin functions to overcome the 60 arguments limit of Avisynth) and then applies a user-defined function in each color which returns a clip colored with that color.Finally it calls Stack to stack the colored clips in a 2D matrix.