The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Colorful Extensions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Colorful Extensions Posted: Jun 9, 2004 6:25 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Colorful Extensions
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
I do lots of custom widgets. Smalltalk is just fun to make new and interesting ways to display data in. So one of the things I've ended up extending is ColorValue. These aren't as novel, but they've been incredibly handy for doing colorful widgets.

cornerContrast

Make a colored region, and then print some text on it. What color is the text? Especially if you're not sure what color to make the region and you're still experimenting, or even more serious your widget colors itself dynamically based on some external resource. This method:

^ColorValue 
		scaledRed: (red < 4096 ifTrue: [MaxValue] ifFalse: [0])
		scaledGreen: (green < 4096 ifTrue: [MaxValue] ifFalse: [0])
		scaledBlue: (blue < 4096 ifTrue: [MaxValue] ifFalse: [0])

works off a receiver color (e.g. your colored region) and returns the color which is one of the RGB color cubes corners, the corner that's furthest from the receiver. Try it, it's kind of fun.

bestContrast

The above said, most viewers cotton to black or white text better then color contrasted text, so nowdays, I tend to use this method:

^self luminance < 0.5 
		ifTrue: [ColorValue white]
		ifFalse: [ColorValue black]

It just uses the luminosity of the receiver (an interesting equation for the interested student) and goes either black or white. Both of these methods nicely couple two colors together where one is intended to be a contrast of the other.

But why not 8 bits?

One thing that always fascinates me when I'm mucking around in the ColorValue objects, is why they use scaled RGB values of 8096 (13 bits). What's the point really? Is it in case someone is doing really high end high precision graphics beyond 8 bits? In Smalltalk? Let's get real. Many years ago, before the world pretty much settled that 8 bits per channel was enough for 99.9999% of all applications, it might have made sense. Changing them to 8 bits would dramatically simplify/expedite the interchange between Smalltalk ColorValues and those that come from the platform. And if someone really needs the high precision version... they can always subclass. And in that event, go with 16 bits per channel. I just can't figure out what was so lucky about 13.

Read: Colorful Extensions

Topic: XP2004 Previous Topic   Next Topic Topic: Why Upgrade?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use