[ENH]Color>>darker etc. preserves transparency

Karl Ramberg karl.ramberg at chello.se
Sat Jun 24 19:36:56 UTC 2000


Here is a enhancement to the Color>>darker etc. which detects if the
color one tries to darken has a alpha value smaller than 1 (then it's transparent)
and if, the darker color will get a treated as deserved.

Karl
-------------- next part --------------
'From Squeak2.9alpha of 13 June 2000 [latest update: #2424] on 24 June 2000 at 9:28:26 pm'!

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:26'!
darker
	"Answer a darker shade of this color."
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.8333 with: Color black].
	^ self mixed: 0.8333 with: Color black
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:19'!
lighter
	"Answer a lighter shade of this color."
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.8333 with: Color white].
	^ self mixed: 0.8333 with: Color white
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:19'!
muchLighter
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.2333 with: Color white].
	^ self mixed: 0.233 with: Color white
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:20'!
slightlyDarker
	"Answer a slightly darker shade of this color."
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.93 with: Color black].
	^ self mixed: 0.93 with: Color black
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:20'!
slightlyLighter
	"Answer a slightly lighter shade of this color."
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.93 with: Color white].
	^ self mixed: 0.93 with: Color white
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:20'!
twiceDarker
	"Answer a significantly darker shade of this color."
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.5 with: Color black].
	^ self mixed: 0.5 with: Color black
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:21'!
twiceLighter
	"Answer a significantly lighter shade of this color."
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.5 with: Color white].
	^ self mixed: 0.5 with: Color white
! !

!Color methodsFor: 'transformations' stamp: 'kfr 6/24/2000 21:21'!
veryMuchLighter
(self alpha = 1)
		ifFalse:[^self alphaMixed: 0.1165 with: Color white].
	^ self mixed: 0.1165 with: Color white
! !



More information about the Squeak-dev mailing list