[Newbies] Color>>hex doesn't work ...

Stephen Davies stephen.l.davies at gmail.com
Sat May 6 13:41:47 UTC 2006


On 06/05/06, Benjamin Schroeder <benschroeder at acm.org> wrote:
> What is an example that causes the error?
>
> And - are you talking about Color's class method hex:? e.g.
>
>         Color hex: 0.43
>
> I ask in case you have a package loaded I don't, or something of that
> nature. (I don't see a "hex" instance method on Color in my base 3.8
> image, but I did note that the hex: class method eventually calls the
> kinds of things you're talking about.)

Hi Ben,

Yes - sorry.  hex instance method is added by seaside.  Looks like so:

hex
	^ ((self red * 255) asInteger printPaddedWith: $0 to: 2 base: 16) ,
	  ((self green * 255) asInteger printPaddedWith: $0 to: 2 base: 16) ,
	  ((self blue * 255) asInteger printPaddedWith: $0 to: 2 base: 16).

Then Integer#printPaddedWith:to:base::

printPaddedWith: aCharacter to: anInteger base: aRadix
	"Answer the string containing the ASCII representation of the receiver
	padded on the left with aCharacter to be at least anInteger characters."
	| aStream padding digits |
	#Numeric.
	"2000/03/04  Harmon R. Added Date and Time support"
	aStream := WriteStream on: (String new: 10).
	self
		printOn: aStream
		base: aRadix
		showRadix: false.
	digits := aStream contents.
	padding := anInteger - digits size.
	padding > 0 ifFalse: [^ digits].
	^ ((String new: padding) atAllPut: aCharacter;
	 yourself) , digits

Which is how we get to printOn:base:showRadix, which calls printStringRadix:

Steve


More information about the Beginners mailing list