Changeset 2639 in lmdz_wrf
- Timestamp:
- Jun 25, 2019, 3:21:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2602 r2639 174 174 # mindist: Function to provide the minimum distance toa pair of lon,lat 175 175 # minmax_range: Function to provide a range for a given pair of minimum and maximum 176 # modify_color: Function to modify a given color 176 177 # multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix 177 178 # multi_index_string: Function to provide the indeces of every repetition of a group of characters within a string … … 16846 16847 return plon, plat 16847 16848 16849 def modify_color(color, coltype, modval, action): 16850 """ Function to modify a given color 16851 color: color to modify 16852 coltype: type of color 16853 'hex': color must be ASCII '#[RR][GG][BB]' in heximal mode 16854 'dec': color must be list [[R], [G], [B]] with [0,1] values 16855 '256': color must be list [[R], [G], [B]] with [0,255] values 16856 modval: value to use to modify in [0,255] values 16857 action: action of the modification 16858 'light': increase all values by modval 16859 'darken': decrease (above zero) all values by modval 16860 >>> modify_color('#AA0000', 'hex', 32, 'light') 16861 CA2020 16862 >>> modify_color([0.2,0.8,0.6], 'dec', 32, 'darken') 16863 [ 0.0745098 0.6745098 0.4745098] 16864 >>> modify_color([255, 255, 0], '256', 32, 'light') 16865 [ 255. 255. 32.] 16866 """ 16867 fname = 'modify_color' 16868 availtype = ['hex', 'dec', '256'] 16869 availaction = ['light', 'darken'] 16870 16871 if coltype == 'hex': 16872 deccol = np.array(colhex_dec(color)) 16873 elif coltype == 'dec': 16874 deccol = np.array(color) 16875 elif coltype == '256': 16876 deccol = np.array(color)/255. 16877 else: 16878 print errormsg 16879 print ' ' + fname + ": color type '" + coltype + "' not ready !!" 16880 print ' available ones:', availtype 16881 quit(-1) 16882 16883 modv = modval/255. 16884 if action == 'darken': 16885 newcol = np.where(deccol < modv, 0., deccol - modv) 16886 elif action == 'light': 16887 newcol = np.where(deccol > 1.-modv, 1., deccol + modv) 16888 else: 16889 print errormsg 16890 print ' ' + fname + ": action '" + action + "' not ready !!" 16891 print ' available ones:', availaction 16892 quit(-1) 16893 16894 if coltype == 'hex': 16895 finalcol = np.array(coldec_hex(newcol)) 16896 elif coltype == 'dec': 16897 finalcol = newcol 16898 elif coltype == '256': 16899 finalcol = newcol*255. 16900 16901 return finalcol 16902 16903 print modify_color('#AA0000', 'hex', 32, 'light') 16904 16905 print modify_color([0.2,0.8,0.6], 'dec', 32, 'darken') 16906 16907 print modify_color([255, 255, 0], '256', 32, 'light') 16908 16848 16909 #quit() 16849 16910 16850 16911 16851
Note: See TracChangeset
for help on using the changeset viewer.