turtlezero-colormapper_2009


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


INFORMATION


-------
Aside from producing a color chart, this model contains code to report a name for a color number, and code to convert number from 0 - 256 to hexidecimal 00 to FF.
This model was used to determine the 3-byte RGB color codes needed to color the buttons on the turtle-zero web site, so the turtlezero color scheme coordinates with the colors available in NetLogo models.

Procedures

NetLogo Version: NetLogo 4.0.4

;;;; SUMMARY
;; An attractive color table for buttons using NetLogo colors
;;;; COPYRIGHT
;; Copyright (C) 2006 James P. Steiner
;; Some Rights Reserved
;;
;;
to startup
   setup
end   

to setup
   ca
   
   ask patches with [ pxcor = max-pxcor ]
   [ ifelse py2pc >= 0 
     [  
     set pcolor py2pc

     set [plabel-color] of patch-at -2 0 black
     set [plabel] of patch-at  -2 0 (word  hexcolor ( pcolor + 3 ) " " )
     ask patches at-points [ [-2 0][-3 0] [-4 0 ]] [ set pcolor [pcolor] of myself + 3 ]

     set [plabel] of patch-at  -6 0 (word  hexcolor ( pcolor + 0 ) " " )
     ask patches at-points [ [-6 0][-7 0][-8 0]] [ set pcolor [pcolor] of myself + 0 ]
   
     set [plabel] of patch-at  -10 0 (word  hexcolor ( pcolor - 3 ) " " )
     ask patches at-points [ [-10 0][-11 0] [-12 0]] [ set pcolor [pcolor] of myself - 3 ]
     
     set [plabel] of patch-at -13 0 (word (color-name pcolor) " " (int pcolor) ":" )
     set [pcolor] of patch min-pxcor pycor pcolor
     ]
     [ if pycor = max-pycor
       [ set [plabel] of patch-at -2 0  "Highlight(+3)"
         set [plabel] of patch-at -6 0  "Normal        "
         set [plabel] of patch-at -10 0 "Shadow(-3)  "
       ]
     ]
   ]
    
end

to go
   if mouse-down?
   [ ask patches with [ round mouse-ycor = pycor and pxcor = 0 and py2pc >= 0 ]
     [ let c py2pc
       clear-output
       output-print (word "a._____     /* " (color-name c) " */" )
       output-print (word "{ color: " (hexcolor ( c + 3 ) ) " ;   background: " (hexcolor ( c      ) )" ;"  " }" )
       output-print (word "a:hover._____     /* reversed " (color-name c) " */" )
       output-print (word "{ color: " (hexcolor ( c - 3 ) ) " ;   background: " (hexcolor ( c + 2  ) )" ; }" )
       output-print ""        
     ]
     wait .25 
   ]
end
   
to-report py2pc
   ;; convert a pycor to a color
   let c (world-height - (pycor + max-pycor) - 2) * 10 + 5
   ifelse c >= 0 and c < 140
   [ report c ]
   [ report -1 ]
end

to-report color-name [ c ]
   let clist [ "gray" "red" "orange" "brown" "yellow" "green" "lime" "turquoise" "cyan" "sky" "blue" "violet" "magenta" "pink" ]
   report (item (int(c - c mod 10) / 10) clist)
end   

   
to color-table-rgb
    ;; quick conversion of the set of netlogo colors
    ;; to their 3-byte decimal RGB equivalent
    clear-output
    output-print "NetLogo Colors as 1-byte  RGB"
    foreach (n-values 14 [ (? * 10) + 5])
    [ let as-decimal extract-rgb ?
      let as-hex (map [ dec2hex ? ] as-decimal )
      output-print (word as-hex " " as-decimal " ;; " (color-name ?) )
    ]
    
end

to-report dec2hex [ d ]
   let a d mod 16
   let b int ((d - a ) / 16)
   let hex [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ]   
   report (word (item b hex) (item a hex))
end

to-report rgb2hex [ rgb-list ]
   let a "#"
   foreach rgb-list
   [ let b ? 
     let h dec2hex b
     set a (word a h)
   ]
   report a
end

to-report hexcolor [ c ]
   report (rgb2hex extract-rgb c)
end
  

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download turtlezero-colormapper_2009 --