Color Class has a bug
Peter Osburg
peter.osburg at gmail.com
Thu Nov 9 08:22:40 UTC 2006
hello there,
i don't know it the problem is still known but the following i figured
yesterday:
when using the class method
Color>>fromString: 'yellow'
or also
Color>>fromString: 'orange'
you will always get the hex-value of black. so i figured the following
mistake
aString first = $#
> ifTrue: [aColorHex := aString copyFrom: 2 to: aString size]
> ifFalse: [aColorHex := aString].
> [aColorHex size = 6
> ifTrue:
> [aColorHex := aColorHex asUppercase.
> red := ('16r', (aColorHex copyFrom: 1 to: 2)) asNumber/255.
> green := ('16r', (aColorHex copyFrom: 3 to: 4)) asNumber/255.
> blue := ('16r', (aColorHex copyFrom: 5 to: 6)) asNumber/255.
> ^ self r: red g: green b: blue]]
u see: aColorHex will be aString when there is no '#' within the string. but
when the string has just the size of 6 (like it is given with 'yellow' or
'orange' then the statement will also be true. in fact of that you get a
wrong hex for the right color :)
i just tried the following
aString first = $#
> ifTrue: [aColorHex := (aString copyFrom: 2 to: aString size)
> asNumber]
> ifFalse: [aColorHex := aString].
> [(aColorHex isNumber)
> ifTrue:
> [aColorHex := aColorHex asUppercase.
> red := ('16r', (aColorHex copyFrom: 1 to: 2)) asNumber/255.
> green := ('16r', (aColorHex copyFrom: 3 to: 4)) asNumber/255.
> blue := ('16r', (aColorHex copyFrom: 5 to: 6)) asNumber/255.
> ^ self r: red g: green b: blue]]
but in fact i couldn't test it very deeply i don't know if it still serves
well when using hex-colors higher then 10 (e.g. A1 or FF)
there is also the problem that asHex is deprecated - so i can't use it
instead.
thx for your patience :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20061109/7fa84b0a/attachment.htm
More information about the Squeak-dev
mailing list
|