[Thread Prev][Thread Next][Index]

[ferret_users] Fancy line/label colors



Hi All,
         If you want have a fancy color for your line plot or label in
Ferret, always you have to search for its RGB values and then define a 
new "ppl color". I wrote one GO file (rgb_colors.jnl) to make this 
process easy. Its usage is similar to "ppl color" but instead of last 
3 arguments you can use a color name (sounds interesting ?) :

  For maroon color, the "ppl color" usage is like

      yes? ppl color 5, 0.6902,0.1882,0.3765
  
  With the new GO file rgb_colors, it is as simple as

      yes? go rgb_colors 5, "maroon"

Color name should be in double quotes and there is absolutely no problem
with blank spaces or case (ie. "medium violet red", " Sandy  Brown " are
just fine). One constraint is that the command "showrgb" should be 
available on your computer. Also the grep command should support the -w 
argument. Other details are given in the header part of the go file (see 
the attachment). Few examples are given below. Hope this will be useful...

Let us make Ferret more colorful !!!!

Regards,

Jaison

!----------rgb_colors Examples--------------------------------
   go rgb_colors 6 "salmon" 
   plot/color=12 SIN(i[i=1:100]/10)
   label 50,0.4,0,0,0.14 @C018 My Fancy Color\!\!
   go rgb_colors 6 "mediumpurple1"
   plot/color=12 SIN(i[i=1:100]/10)
   label 50,0.4,0,0,0.14 @C018 My Fancy Color\!\!
   go rgb_colors 6 "pink3"
   plot/color=12 SIN(i[i=1:100]/10)
   go rgb_colors 6 "LightSalmon4"
   plot/color=12 SIN(i[i=1:100]/10)
   go rgb_colors 6 "wheat3"
   plot/color=12 SIN(i[i=1:100]/10)
   go rgb_colors 6 "PaleTurquoise4"
   plot/color=12 SIN(i[i=1:100]/10)
   go rgb_colors 6 "blue4"
   plot/color=12 SIN(i[i=1:100]/10)
   go rgb_colors 6 "maroon"
   plot/color=12 SIN(i[i=1:100]/10)
   go rgb_colors 6 "chocolate"
   plot/color=12 SIN(i[i=1:100]/10)
!---------end of examples--------------------------------------
\ cancel mode verify
!
! Description: To define RGB Ferret/PPL colors, using system X11 color entries.
! ------------
! RGB colors available on your computer can be used to create fancy line/
!      label colors in Ferret. To have a look at color names and colors...
! 
!   1.  http://www.math.utah.edu/faq/color/rgb-chart.pdf
!   2.  http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html
!
! Arguments : (all are optional)
! ---------
!    $1  : Ferret color number; should be between 1 & 6 ; default is 5
!    $2  : RGB Color Name, in double quotes : "" ; case insensitive ; 
!            trailing/preceeding blank characters are fine provided
!            the color exists.
!            use showrgb or sites mentioned above for color names.
!
! Usage   :
! ---------
!        GO rgb_colors  [ferret_color_number] [rgb color name]
!     
! Examples 
! --------
!   1.   go rgb_colors     ! without any arguments 5 will be defined as SALMON
!        plot/color=5 SIN(i[i=1:100]/10)
!
!   2.   go rgb_colors 5, "dark red" ; plot/color=11 SIN(i[i=1:100]/10)
!
!   3.   go rgb_colors 5, "Pale Violet Red" ; plot/color=5 SIN(i[i=1:100]/10)
!
! Notes : Default Ferret color can be restored by calling rgb_colors again
! ------    with proper color_number and color_name.
!         Machine should have the commands "showrgb" & "grep" (with options like
!           -w and [[:space:]]]   
!         To know more about Ferret line/label colors have a look at the user manual, 
!            Ch6 Sec5.1.2.  PPLUS text and line color commands &
!            Appendix C Sec2.3  COLOR n, red, green, blue
!         Internal variables have the prefix "rlc_" --> rgb_line/label_color_
!
!-----------------------------------------------------------------------------
! Created By : Jaison Kurian
! Created On : 18/Nov/2006
!
! Modifications Planned :
!
!   1. Add a check for the existence of showrgb/grep command
!   2. Try to replace grep command with more reputed one like awk.
!
!--------------------------------------------------------------------------------

   ! set the input parameters

   define symbol rlc_numb    = $1"5"       ! Ferret Color Number
   define symbol rlc_name    = $2"salmon"  ! RGB Color Name        

   ! do a check for specified color number

   IF `($rlc_numb) LT 0 OR ($rlc_numb) GT 6` THEN 
     say 
     say "  ERROR (rgb_colors) : 1st Argument (Ferret color No.) should be in the range 1-6." 
     say ; EXIT/SCRIPT
   ENDIF

   ! check whether the defined color exists, if not exit from current script

   define symbol rlc_color   = `{spawn:"echo ($rlc_name) | sed 's/ //g'"}`

   let rlc_all   = {spawn:"showrgb | grep -i -w '[[:space:]]($rlc_color)'"}
   let rlc_ok    = STRLEN(rlc_all[i=1])
   IF  `rlc_ok LE 0` THEN
     say
     say "    SORRY (rgb_colors) : Requested color ($rlc_name) does NOT exist."
     say "                              The DEFAULT color will be used." ; say
     EXIT/SCRIPT 
   ENDIF
   let rlc_all_x = XSEQUENCE(rlc_all)
   let rlc_ncols = SUBSTRING(rlc_all_x,12,100)
   let rlc_ncol  = `rlc_all_x,r=iend`
   IF `rlc_ncol GT 1` THEN
     say ; say "    WARNING (rgb_colors) : More than 1 color found. Using the 1st one."
           say "                                  `rlc_ncols[i=1]`" ; say
   ENDIF

   ! If color exists, convert RGB values to %, as required by Ferret.

   let rlc_r = SUBSTRING(rlc_all_x[i=1],1,3) 
   let rlc_g = SUBSTRING(rlc_all_x[i=1],5,3) 
   let rlc_b = SUBSTRING(rlc_all_x[i=1],9,3) 

   let rlc_red   = (`rlc_r`/255) * 100
   let rlc_green = (`rlc_g`/255) * 100
   let rlc_blue  = (`rlc_b`/255) * 100

   ! Define requested color, using the specified color number

   ppl color `($rlc_numb)`, `rlc_red`, `rlc_green`, `rlc_blue`

   ! clean up

   cancel symbol rlc_* ; cancel var rlc_*

   set mode/last verify

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement