Color Object
Various color globals (+colors2, +colors2/hex, +colors2/xterm256, +colors2 <name>, +colors2/xterm256 <name>, +palette, +xcolors) based upon the new color features in PennMUSH.
Functions:
abs(),
add(),
align(),
ansi(),
baseconv(),
chr(),
dec(),
div(),
elements(),
extract(),
fdiv(),
first(),
floordiv(),
fmod(),
graball(),
gte(),
if(),
inc(),
isint(),
iter(),
letq(),
lmath(),
lnum(),
lpos(),
matchall(),
min(),
mul(),
munge(),
regeditall(),
regmatch(),
rjust(),
round(),
setinter(),
setq(),
setr(),
sort(),
space(),
strinsert(),
strlen(),
sub(),
switch(),
table(),
u(),
unique(),
v(),
vmag(),
vsub(),
words().
Compatibility:
PennMUSH.
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for Color Object
@create ColorObj
@link ColorObj = #0
@set ColorObj=!NO_COMMAND
&CMD ColorObj=
&CMD`PRINT_COLORS0 ColorObj=$+colors2:@dolist setq(a,u(Fun`Color_Alignment)) [lnum(97,122)]=@nspemit %#=u(Fun`Print_Colors,chr(%i0)*)
&CMD`PRINT_COLORS0_HEX ColorObj=$+colors2/hex:@dolist lnum(1,setr(w,words(setr(c,unique(sort(iter(colors(),colors(+%i0,hex)),a),a)))),%b,50)=@nspemit %#=iter(lnum(%i0,min(add(%i0,49),%qw),%b,2), align(8 29 8 29, ansi(setr(0,elements(%qc,%i0)),%q0):,colors(%q0,name), ansi(setr(0,elements(%qc,inc(%i0))),%q0):,colors(%q0,name)), %b,%r)
&CMD`PRINT_COLORS0_XTERM ColorObj=$+colors2/xterm256:@dolist lnum(1,words(setr(g,unique(sort(setr(c,iter(colors(),colors(+%i0,xterm256))),n),n))),%b,50)=@nspemit %#=iter(extract(%qg,%i0,50), align(>3 1 72,ansi(+xterm%i0,%i0),:,sort(elements(colors(),matchall(%qc,%i0)),a)), %b,%r)
&CMD`PRINT_COLORS1 ColorObj=$+colors2 *:@assert strlen(colors(%0))={@nspemit %#=No Color Names Match [ansi(h,%0)]};think setq(a,u(Fun`Color_Alignment));@assert regmatch(%0,^\[\\?\\*\]*\\*\[\\?\\*\]*$)={@nspemit %#=u(Fun`Print_Colors,%0)};@dolist lnum(97,122)=@nspemit %#=u(Fun`Print_Colors,chr(%i0)*)
&CMD`PRINT_COLORS1_HEX ColorObj=$+colors2/hex *:@assert strlen(colors(%0))={@nspemit %#=No Color Names Match [ansi(h,%0)]};@dolist lnum(1,setr(w,words(setr(c,unique(sort(iter(colors(%0),colors(+%i0,hex)),a),a)))),%b,50)=@nspemit %#=iter(lnum(%i0,min(add(%i0,49),%qw),%b,2), align(8 29 8 29, ansi(setr(0,elements(%qc,%i0)),%q0):,graball(colors(%q0,name),%0), ansi(setr(0,elements(%qc,inc(%i0))),%q0):,graball(colors(%q0,name),%0)), %b,%r)
&CMD`PRINT_COLORS1_XTERM ColorObj=$+colors2/xterm256 *:@assert strlen(colors(%0))={@nspemit %#=No Color Names Match [ansi(h,%0)]};@dolist lnum(1,words(setr(g,unique(sort(setr(c,iter(colors(%0),colors(+%i0,xterm256))),n),n))),%b,50)=@nspemit %#=iter(extract(%qg,%i0,50), align(>3 1 72,ansi(+xterm%i0,%i0),:,sort(elements(colors(%0),matchall(%qc,%i0)),a)), %b,%r)
&CMD`PRINT_COLOR_TABLE ColorObj=$+palette:@dolist setq(c,colors()) [setq(l,inc(lmath(max,vsub(lpos(%qc%b,%b),lpos(%b%qc,%b)))))] [setq(m,mul(div(8192,mul(div(78,%ql),add(%ql,16))),div(78,%ql)))] [lnum(1,words(%qc),%b,%qm)]=@pemit %#=[table(iter(extract(%qc,%i0,%qm),ansi(+%i0,%i0)),dec(%ql))]
&CMD`PRINT_XTERM_TABLE ColorObj=$+xcolors:@pemit %#=[table(iter(lnum(0,255),ansi(+xterm##,##:[colors(+xterm##,hex)])),>14,61)]
&DAT ColorObj=
&DAT`C16_ANSI ColorObj=x r g y b m c w hx hr hg hy hb hm hc hw
&DAT`C16_HEX ColorObj=000000 cd2200 00cd22 cdcd00 2200cd cd00cd 00cdcd e5e5e5 7f7f7f ff0000 00ff00 ffff00 0000ff ff00ff 00ffff ffffff
&DAT`C16_HSV ColorObj=0 0 0|0 1 0.805|120 1 0.805|60 1 0.805|240 1 0.935|300 1 0.805|180 1 0.805|0 0 0.898|0 0 0.497|0 1 1|120 1 1|60 1 1|240 0.64 1|300 1 1|180 1 1|0 0 1
&DAT`C16_VEC ColorObj=0 0 0|205 34 0|0 205 34|205 205 0|34 0 205|205 0 205|0 205 205|229 229 229|127 127 127|255 0 0|0 255 0|255 255 0|0 0 255|255 0 255|0 255 255|255 255 255
&DESCRIBE ColorObj=Color Functions Object
@set ColorObj/DESCRIBE=no_command visual prefixmatch public nearby
&FUN ColorObj=
&FUN`COLOR_ALIGNMENT ColorObj=letq(c,regeditall(colors(),\\d+\\b,), letq(l,lmath(max,vsub(lpos(%qc%b,%b),lpos(%b%qc,%b))), %ql 1 [sub(75,%ql)]))
&FUN`FIND_COLORS ColorObj=switch(%0, #*,colors(%0,name), +*,colors(%0,name), if(isint(%0), elements(colors(),matchall(iter(colors(),colors(+%i0,xterm256)),%0)), elements(colors(),matchall(iter(colors(),colors(+%i0,16color)),%0))))
&FUN`HCM_TO_RGB ColorObj=iter(extract(u(Fun`Hue_RGB_Table, %1, mul(%1,sub(1,abs(sub(fmod(fdiv(%0,60),2),1))))), add(1,floordiv(%0,60)), 1, |), add(%i0,%2))
&FUN`HCM_TO_VEC ColorObj=iter(extract(u(Fun`Hue_RGB_Table, %1, mul(%1,sub(1,abs(sub(fmod(fdiv(%0,60),2),1))))), add(1,floordiv(%0,60)), 1, |), round(mul(add(%i0,%2),255),0))
&FUN`HEX_DIST ColorObj=vmag(vsub(u(Fun`Hex_To_Vec,%0,%b),u(Fun`Hex_To_Vec,%1,%b)))
&FUN`HEX_TO_C16 ColorObj=setq(0,u(Fun`Hex_To_Vec,%0,%b))[first(munge(Fun`Sort_F, iter(v(Dat`C16_Vec),vmag(vsub(%q0,%i0)),|), v(Dat`C16_Ansi)))]
&FUN`HEX_TO_RGB ColorObj=iter(strinsert(strinsert(%0,4,%1),2,%1),fdiv(baseconv(%i0,16,10),255),%1)
&FUN`HEX_TO_VEC ColorObj=iter(strinsert(strinsert(%0,4,%1),2,%1),baseconv(%i0,16,10),%1)
&FUN`HEX_TO_XTERM ColorObj=setq(0,u(Fun`Hex_To_Vec,%0,%b))[first(munge(Fun`Sort_F, iter(v(Dat`CT`Xterm_Vec),vmag(vsub(%q0,%i0)),|), lnum(0,255)))]
&FUN`HSL_TO_HEX ColorObj=u(Fun`RGB_To_Hex,u(fun`HCM_To_RGB, %0, setq(C,mul(sub(1,abs(sub(mul(%2,2),1))),%1)), sub(%2,mul(0.5,%qC))),%b)
&FUN`HSL_TO_VEC ColorObj=u(fun`HCM_To_Vec, %0, setq(C,mul(sub(1,abs(sub(mul(%2,2),1))),%1)),sub(%2,mul(0.5,%qC)))
&FUN`HSV_TO_HEX ColorObj=u(Fun`RGB_To_Hex,u(Fun`HCM_To_RGB, %0, mul(%1,%2), sub(%2,mul(%1,%2))),%b)
&FUN`HSV_TO_VEC ColorObj=u(Fun`HCM_To_Vec, %0, mul(%1,%2), sub(%2,mul(%1,%2)))
&FUN`HUE_RGB_TABLE ColorObj=%0 %1 0|%1 %0 0|0 %0 %1|0 %1 %0|%1 0 %0|%0 0 %1
&FUN`HUE_X_VALUE ColorObj=mul(%1,sub(1,abs(sub(fmod(fdiv(%0,60),2),1))))
&FUN`MUX_ALIGN ColorObj=setq(L,%0)[iter(%2,if(gte(setr(L,add(%qL,inc(strlen(##)))),%1),setq(L,add(%0,inc(strlen(##))))%r[space(%0)])##%b,%b,@@)]
&FUN`PRINT_COLORS ColorObj=letq(c,colors(%0), letq(g,regeditall(%qc,\\d+\\b,), iter(setinter(%qg,%qg), align(%qa,%i0,:,iter(elements(%qc,matchall(%qg,%i0)),ansi(+%i0,%i0))), %b,%r)))
&FUN`RGB_TO_HEX ColorObj=iter(%0,rjust(baseconv(round(mul(%i0,255),0),10,16),2,0),%1,)
&FUN`SORT_F ColorObj=sort(%0,f)
&FUN`VEC_TO_HEX ColorObj=iter(%0,rjust(baseconv(%i0,10,16),2,0),%1,)
think Commands: +colors2, +colors2/hex, +colors2/xterm256, +colors2 <name>, +colors2/xterm256 <name>, +palette, +xcolors
@link ColorObj = #0
@set ColorObj=!NO_COMMAND
&CMD ColorObj=
&CMD`PRINT_COLORS0 ColorObj=$+colors2:@dolist setq(a,u(Fun`Color_Alignment)) [lnum(97,122)]=@nspemit %#=u(Fun`Print_Colors,chr(%i0)*)
&CMD`PRINT_COLORS0_HEX ColorObj=$+colors2/hex:@dolist lnum(1,setr(w,words(setr(c,unique(sort(iter(colors(),colors(+%i0,hex)),a),a)))),%b,50)=@nspemit %#=iter(lnum(%i0,min(add(%i0,49),%qw),%b,2), align(8 29 8 29, ansi(setr(0,elements(%qc,%i0)),%q0):,colors(%q0,name), ansi(setr(0,elements(%qc,inc(%i0))),%q0):,colors(%q0,name)), %b,%r)
&CMD`PRINT_COLORS0_XTERM ColorObj=$+colors2/xterm256:@dolist lnum(1,words(setr(g,unique(sort(setr(c,iter(colors(),colors(+%i0,xterm256))),n),n))),%b,50)=@nspemit %#=iter(extract(%qg,%i0,50), align(>3 1 72,ansi(+xterm%i0,%i0),:,sort(elements(colors(),matchall(%qc,%i0)),a)), %b,%r)
&CMD`PRINT_COLORS1 ColorObj=$+colors2 *:@assert strlen(colors(%0))={@nspemit %#=No Color Names Match [ansi(h,%0)]};think setq(a,u(Fun`Color_Alignment));@assert regmatch(%0,^\[\\?\\*\]*\\*\[\\?\\*\]*$)={@nspemit %#=u(Fun`Print_Colors,%0)};@dolist lnum(97,122)=@nspemit %#=u(Fun`Print_Colors,chr(%i0)*)
&CMD`PRINT_COLORS1_HEX ColorObj=$+colors2/hex *:@assert strlen(colors(%0))={@nspemit %#=No Color Names Match [ansi(h,%0)]};@dolist lnum(1,setr(w,words(setr(c,unique(sort(iter(colors(%0),colors(+%i0,hex)),a),a)))),%b,50)=@nspemit %#=iter(lnum(%i0,min(add(%i0,49),%qw),%b,2), align(8 29 8 29, ansi(setr(0,elements(%qc,%i0)),%q0):,graball(colors(%q0,name),%0), ansi(setr(0,elements(%qc,inc(%i0))),%q0):,graball(colors(%q0,name),%0)), %b,%r)
&CMD`PRINT_COLORS1_XTERM ColorObj=$+colors2/xterm256 *:@assert strlen(colors(%0))={@nspemit %#=No Color Names Match [ansi(h,%0)]};@dolist lnum(1,words(setr(g,unique(sort(setr(c,iter(colors(%0),colors(+%i0,xterm256))),n),n))),%b,50)=@nspemit %#=iter(extract(%qg,%i0,50), align(>3 1 72,ansi(+xterm%i0,%i0),:,sort(elements(colors(%0),matchall(%qc,%i0)),a)), %b,%r)
&CMD`PRINT_COLOR_TABLE ColorObj=$+palette:@dolist setq(c,colors()) [setq(l,inc(lmath(max,vsub(lpos(%qc%b,%b),lpos(%b%qc,%b)))))] [setq(m,mul(div(8192,mul(div(78,%ql),add(%ql,16))),div(78,%ql)))] [lnum(1,words(%qc),%b,%qm)]=@pemit %#=[table(iter(extract(%qc,%i0,%qm),ansi(+%i0,%i0)),dec(%ql))]
&CMD`PRINT_XTERM_TABLE ColorObj=$+xcolors:@pemit %#=[table(iter(lnum(0,255),ansi(+xterm##,##:[colors(+xterm##,hex)])),>14,61)]
&DAT ColorObj=
&DAT`C16_ANSI ColorObj=x r g y b m c w hx hr hg hy hb hm hc hw
&DAT`C16_HEX ColorObj=000000 cd2200 00cd22 cdcd00 2200cd cd00cd 00cdcd e5e5e5 7f7f7f ff0000 00ff00 ffff00 0000ff ff00ff 00ffff ffffff
&DAT`C16_HSV ColorObj=0 0 0|0 1 0.805|120 1 0.805|60 1 0.805|240 1 0.935|300 1 0.805|180 1 0.805|0 0 0.898|0 0 0.497|0 1 1|120 1 1|60 1 1|240 0.64 1|300 1 1|180 1 1|0 0 1
&DAT`C16_VEC ColorObj=0 0 0|205 34 0|0 205 34|205 205 0|34 0 205|205 0 205|0 205 205|229 229 229|127 127 127|255 0 0|0 255 0|255 255 0|0 0 255|255 0 255|0 255 255|255 255 255
&DESCRIBE ColorObj=Color Functions Object
@set ColorObj/DESCRIBE=no_command visual prefixmatch public nearby
&FUN ColorObj=
&FUN`COLOR_ALIGNMENT ColorObj=letq(c,regeditall(colors(),\\d+\\b,), letq(l,lmath(max,vsub(lpos(%qc%b,%b),lpos(%b%qc,%b))), %ql 1 [sub(75,%ql)]))
&FUN`FIND_COLORS ColorObj=switch(%0, #*,colors(%0,name), +*,colors(%0,name), if(isint(%0), elements(colors(),matchall(iter(colors(),colors(+%i0,xterm256)),%0)), elements(colors(),matchall(iter(colors(),colors(+%i0,16color)),%0))))
&FUN`HCM_TO_RGB ColorObj=iter(extract(u(Fun`Hue_RGB_Table, %1, mul(%1,sub(1,abs(sub(fmod(fdiv(%0,60),2),1))))), add(1,floordiv(%0,60)), 1, |), add(%i0,%2))
&FUN`HCM_TO_VEC ColorObj=iter(extract(u(Fun`Hue_RGB_Table, %1, mul(%1,sub(1,abs(sub(fmod(fdiv(%0,60),2),1))))), add(1,floordiv(%0,60)), 1, |), round(mul(add(%i0,%2),255),0))
&FUN`HEX_DIST ColorObj=vmag(vsub(u(Fun`Hex_To_Vec,%0,%b),u(Fun`Hex_To_Vec,%1,%b)))
&FUN`HEX_TO_C16 ColorObj=setq(0,u(Fun`Hex_To_Vec,%0,%b))[first(munge(Fun`Sort_F, iter(v(Dat`C16_Vec),vmag(vsub(%q0,%i0)),|), v(Dat`C16_Ansi)))]
&FUN`HEX_TO_RGB ColorObj=iter(strinsert(strinsert(%0,4,%1),2,%1),fdiv(baseconv(%i0,16,10),255),%1)
&FUN`HEX_TO_VEC ColorObj=iter(strinsert(strinsert(%0,4,%1),2,%1),baseconv(%i0,16,10),%1)
&FUN`HEX_TO_XTERM ColorObj=setq(0,u(Fun`Hex_To_Vec,%0,%b))[first(munge(Fun`Sort_F, iter(v(Dat`CT`Xterm_Vec),vmag(vsub(%q0,%i0)),|), lnum(0,255)))]
&FUN`HSL_TO_HEX ColorObj=u(Fun`RGB_To_Hex,u(fun`HCM_To_RGB, %0, setq(C,mul(sub(1,abs(sub(mul(%2,2),1))),%1)), sub(%2,mul(0.5,%qC))),%b)
&FUN`HSL_TO_VEC ColorObj=u(fun`HCM_To_Vec, %0, setq(C,mul(sub(1,abs(sub(mul(%2,2),1))),%1)),sub(%2,mul(0.5,%qC)))
&FUN`HSV_TO_HEX ColorObj=u(Fun`RGB_To_Hex,u(Fun`HCM_To_RGB, %0, mul(%1,%2), sub(%2,mul(%1,%2))),%b)
&FUN`HSV_TO_VEC ColorObj=u(Fun`HCM_To_Vec, %0, mul(%1,%2), sub(%2,mul(%1,%2)))
&FUN`HUE_RGB_TABLE ColorObj=%0 %1 0|%1 %0 0|0 %0 %1|0 %1 %0|%1 0 %0|%0 0 %1
&FUN`HUE_X_VALUE ColorObj=mul(%1,sub(1,abs(sub(fmod(fdiv(%0,60),2),1))))
&FUN`MUX_ALIGN ColorObj=setq(L,%0)[iter(%2,if(gte(setr(L,add(%qL,inc(strlen(##)))),%1),setq(L,add(%0,inc(strlen(##))))%r[space(%0)])##%b,%b,@@)]
&FUN`PRINT_COLORS ColorObj=letq(c,colors(%0), letq(g,regeditall(%qc,\\d+\\b,), iter(setinter(%qg,%qg), align(%qa,%i0,:,iter(elements(%qc,matchall(%qg,%i0)),ansi(+%i0,%i0))), %b,%r)))
&FUN`RGB_TO_HEX ColorObj=iter(%0,rjust(baseconv(round(mul(%i0,255),0),10,16),2,0),%1,)
&FUN`SORT_F ColorObj=sort(%0,f)
&FUN`VEC_TO_HEX ColorObj=iter(%0,rjust(baseconv(%i0,10,16),2,0),%1,)
think Commands: +colors2, +colors2/hex, +colors2/xterm256, +colors2 <name>, +colors2/xterm256 <name>, +palette, +xcolors