+ Color { test {|bounds(Rect(30,300, 100, 30))| var window; var extent = bounds.extent.asArray; window = GUI.window.new("ColorTest", bounds, false); window.drawHook = { 3.do{|i| GUI.pen.color = Color.gray(i * 0.5); GUI.pen.fillRect(Rect.fromArray([i*(extent.first/3),0] ++ (extent * [1/3, 1]))); }; GUI.pen.color = this; GUI.pen.fillRect(Rect.fromArray(extent*0.1 ++ extent * 0.8)); window.front; } } autoTest {|bounds(Rect(30,300, 100, 30)), dt = 0.5, fullScreen = false| var window, border = true; var extent; bounds = fullScreen.if({ border = false; GUI.window.screenBounds; }, { bounds; }); extent = bounds.extent.asArray; window = GUI.window.new("ColorTest", bounds, false, border); window.drawHook = { 3.do{|i| GUI.pen.color = Color.gray(i * 0.5); GUI.pen.fillRect(Rect.fromArray([i*(extent.first/3),0] ++ (extent * [1/3, 1]))); }; GUI.pen.color = this; GUI.pen.fillRect(Rect.fromArray(extent*0.1 ++ extent * 0.8)); window.front; fullScreen.if{window.fullScreen}; {window.close}.defer(dt); } } // math support + { arg aNumber, adverb; ^aNumber.performBinaryOpOnColor('+', this, adverb) } - { arg aNumber, adverb; ^aNumber.performBinaryOpOnColor('-', this, adverb) } * { arg aNumber, adverb; ^aNumber.performBinaryOpOnColor('*', this, adverb) } / { arg aNumber, adverb; ^aNumber.performBinaryOpOnColor('/', this, adverb) } performBinaryOpOnSeqColl { arg aSelector, anArray; ^this.performBinaryOpOnColor(aSelector, this.class.fromArray(anArray)) } performBinaryOpOnSimpleNumber { arg aSelector, aNumber; ^this.class.fromArray(this.asArray.collect({ arg item; aNumber.perform(aSelector, item) })) } performBinaryOpOnColor {|aSelector, aColor| var that = aColor.asArray; ^this.class.fromArray(this.asArray.collect({ arg item, i; that[i].perform(aSelector, item) })) } multiply { arg that, opacity=1.0; ^this.blend(this * that, opacity) } divide { arg that, opacity=1.0; ^this.blend(this / that, opacity) } subtract { arg that, opacity=1.0; ^this.blend(this - that, opacity) } add { arg that, opacity=1.0; ^this.blend(this + that, opacity) } } + Object { performBinaryOpOnColor {|aSelector, aColor| ^Color.fromArray(this.performBinaryOpOnSeqColl(aSelector, aColor.asArray)) } }
LFSaw.de