Tech Tip: Inverted 4D color palette in SVG
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: May 8, 2015
The command SVG_Color_from_index returns the SVG color matching the 4D color specified in the index parameter. The documentation gives a sample code to show a 4D color palette in SVG. Here is a modified method based on that code to shows both the color palette and the inverted version using the INVERT_LONGINT tech tip:
// ----------------------------------------------------------------- // Name: Disp_4D_Color_Palette_Inverted // Description: Draws a 4D Color palette based on SVG_Color_from_index // command of 1 to 256 as well as the inverted value in SVG Viewer. // ------------------------------------------------------------------ C_LONGINT($Lon_i;$Lon_ii;$Lon_column;$Lon_line;$offset;$color_number;$inverted_number) $Dom_svg:=SVG_New $Lon_line:=0 $offset:=38 //Draw the color palette For ($Lon_ii;0;15) $Lon_column:=0 For ($Lon_i;1;16) $color_number:=($Lon_ii*16)+$Lon_i $Txt_color:=SVG_Color_from_index ($color_number) $Dom_rect:=SVG_New_rect ($Dom_svg;$Lon_column;$Lon_line;$offset;$offset;0;0;"white";$Txt_color) // Show Text of the color number Case of : (($color_number=6) | ($color_number=12) | ($color_number=16)) $textID:=SVG_New_text ($Dom_svg;String(($Lon_ii*16)+$Lon_i-1);$Lon_column;$Lon_line;"";22;-1;-1;"white";0) : (($color_number>=101) & ($color_number<=114)) $textID:=SVG_New_text ($Dom_svg;String(($Lon_ii*16)+$Lon_i-1);$Lon_column;$Lon_line;"";22;-1;-1;"white";0) : (($color_number>=214) & ($color_number<=224)) $textID:=SVG_New_text ($Dom_svg;String(($Lon_ii*16)+$Lon_i-1);$Lon_column;$Lon_line;"";22;-1;-1;"white";0) : (($color_number>=251) & ($color_number<=256)) $textID:=SVG_New_text ($Dom_svg;String(($Lon_ii*16)+$Lon_i-1);$Lon_column;$Lon_line;"";22;-1;-1;"white";0) Else $textID:=SVG_New_text ($Dom_svg;String(($Lon_ii*16)+$Lon_i-1);$Lon_column;$Lon_line;"";22;-1;-1;"black";0) End case $Lon_column:=$Lon_column+$offset End for $Lon_line:=$Lon_line+$offset End for // Creating a space for Displaying Text $Lon_column:=0 For ($Lon_i;1;16) $Txt_color:=SVG_Color_from_index (1) $Dom_rect:=SVG_New_rect ($Dom_svg;$Lon_column;$Lon_line;$offset;$offset;0;0;"white";$Txt_color) $Lon_column:=$Lon_column+38 End for // Text to diplay "Inverted Color" $textID:=SVG_New_text ($Dom_svg;"Inverted Color"+"(Inverted|Original)";0;$Lon_line;"";22;-1;-1;"black";0) $Lon_line:=$Lon_line+$offset For ($Lon_ii;0;15) $Lon_column:=0 For ($Lon_i;0;15) $color_number:=(($Lon_ii*16)+$Lon_i)-1 $inverted_number:=INVERT_LONGINT ($color_number) $Txt_color:=SVG_Color_from_index ($inverted_number) $Dom_rect:=SVG_New_rect ($Dom_svg;$Lon_column;$Lon_line;$offset;$offset;0;0;"white";$Txt_color) Case of : ($inverted_number=16777215) $textID:=SVG_New_text ($Dom_svg;" "+String(254)+"|"+String(1);$Lon_column;$Lon_line;"";12;-1;-1;"white";0) : ($inverted_number=-16777216) $textID:=SVG_New_text ($Dom_svg;" "+String(255)+"|"+String(0);$Lon_column;$Lon_line;"";12;-1;-1;"white";0) : ($inverted_number=16) $textID:=SVG_New_text ($Dom_svg;" "+String($inverted_number-1)+"|"+String($color_number+1);$Lon_column;$Lon_line;"";12;-1;-1;"white";0) else $textID:=SVG_New_text ($Dom_svg;" "+String($inverted_number-1)+"|"+String($color_number+1);$Lon_column;$Lon_line;"";12;-1;-1;"black";0) end case $Lon_column:=$Lon_column+$offset End for $Lon_line:=$Lon_line+$offset End for SVGTool_SHOW_IN_VIEWER ($Dom_svg) |
The method Disp_4D_Color_Palette_Inverted will display color palette with the associated number:
Below shows the inverted version:
See Also: