Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] New Color Chart

From: larry:ecotope at: 29-Apr-2001 22:27

Hi all I finally got around to rewriting my X-11 color chart in VID. The original was one of the very first few View scripts published and was written using the basic view objects. It only required a few changes as the View betas progressed to View 1.1. The new script is on the Ecotope rebsite or directly at The new version is written entirely with VID. I took the opportunity to improve the script in several ways: 1) The window size is greatly reduced, so that it will fit on a 640x480 display. 2) I added the 42 named REBOL colors alongside 140 X-11 named colors and added a large sample display box. 3) The mouse interface is more sophisticated. 4) The HTML hexadecimal form of the colors is now displayed along with the color name and the REBOL tuple form. 5) You can tune or edit a selected color with the REBOL color requestor. All of this in about 50 lines (about 1500 bytes) of actual REBOL code (not counting pretty-print whitespace, the header, or the color database which accounts for most of the script size). It took me about 2 hours of actual coding time including figuring out how to code the effects I wanted. I spent several additional hours tuning the appearance of the interface (trying different fonts, and different styles for the color boxes, edges, frames, etc. Notes on the code It would be very tedious to explicitly write out the code for each of the 182 color boxes. The solution I used is to write REBOL code which generates a specification block for the LAYOUT function. This is essentially the same technique as using JavaScript in a web page to generate the HTML code for large tables on the fly. In this case, we write a block in the VID dialect which the LAYOUT function converts to nested REBOL objects suitable for the VIEW or SHOW functions. As with JavaScript the code is a mix of literal sections and dynamic generation, in this case by the add-color function. The three main sections of the layout are controlled by 3 AT and GUIDE commands. The layout of the grids of small color boxes is done with RETURN which uses the guide to locate the return point. The small color boxes have a custom FEEL to provide the mouse-over, freeze and unfreeze effects. The large sample box has both an action and an alt-action. The code is wrapped in an object, so the only global variable assigned is ctx-colorchart. If you want to use it as a libary function, just delete the last line of code. Run the script to load the object and then call it on demand with view/ctx-colorchart/lo. Comments welcome -Larry