@@ -37,7 +37,7 @@ class ColorThemeSketch < Propane::App
3737
3838 MAX_SIZE = 150.0
3939 NUM_DISCS = 300
40- attr_reader :show_discs
40+ attr_reader :show_discs , :list
4141
4242 def settings
4343 size ( 1024 , 768 )
@@ -52,17 +52,17 @@ def setup
5252
5353 def draw
5454 # first define our new theme
55- t = ColorTheme . new ( 'test' )
55+ t = Toxi :: ColorTheme . new ( 'test' )
5656 # add different color options, each with their own weight
5757 t . add_range ( 'soft ivory' , 0.5 )
5858 t . add_range ( 'intense goldenrod' , 0.25 )
5959 t . add_range ( 'warm saddlebrown' , 0.15 )
6060 t . add_range ( 'fresh teal' , 0.05 )
6161 t . add_range ( 'bright yellowgreen' , 0.05 )
6262 # now add another rand hue which is using only bright shades
63- t . add_range ( ColorRange ::BRIGHT , TColor . new_random , rand ( 0.02 ..0.05 ) )
63+ t . add_range ( Toxi :: ColorRange ::BRIGHT , TColor . new_random , rand ( 0.02 ..0.05 ) )
6464 # use the TColor theme to create a list of 160 Colors
65- list = t . get_colors ( 160 )
65+ @ list = t . get_colors ( 160 )
6666 if show_discs
6767 background ( list . get_lightest . toARGB )
6868 discs ( list )
@@ -72,31 +72,41 @@ def draw
7272 list . sort_by_distance ( false )
7373 swatches ( list , 32 , yoff )
7474 yoff += SWATCH_HEIGHT + 10
75- list . sort_by_criteria ( AccessCriteria ::LUMINANCE , false )
75+ list . sort_by_criteria ( Toxi :: AccessCriteria ::LUMINANCE , false )
7676 swatches ( list , 32 , yoff )
7777 yoff += SWATCH_HEIGHT + 10
78- list . sort_by_criteria ( AccessCriteria ::BRIGHTNESS , false )
78+ list . sort_by_criteria ( Toxi :: AccessCriteria ::BRIGHTNESS , false )
7979 swatches ( list , 32 , yoff )
8080 yoff += SWATCH_HEIGHT + 10
81- list . sort_by_criteria ( AccessCriteria ::SATURATION , false )
81+ list . sort_by_criteria ( Toxi :: AccessCriteria ::SATURATION , false )
8282 swatches ( list , 32 , yoff )
8383 yoff += SWATCH_HEIGHT + 10
84- list . sort_by_criteria ( AccessCriteria ::HUE , false )
84+ list . sort_by_criteria ( Toxi :: AccessCriteria ::HUE , false )
8585 swatches ( list , 32 , yoff )
8686 yoff += SWATCH_HEIGHT + 10
87- list . sort_by_proximity_to ( NamedColor ::WHITE , RGBDistanceProxy . new , false )
87+ list . sort_by_proximity_to ( Toxi :: NamedColor ::WHITE , Toxi :: RGBDistanceProxy . new , false )
8888 swatches ( list , 32 , yoff )
8989 end
90- # save_frame(format('theme-%s%s', timestamp, '_##.png'))
9190 end
9291
9392 def timestamp
9493 Time . now . strftime ( '%Y%d%m_%H%M%S' )
9594 end
9695
9796 def key_pressed
98- @show_discs = !show_discs if key == ' '
99- redraw
97+ case key
98+ when 's' , 'S'
99+ save_frame ( data_path ( format ( 'theme-%s%s' , timestamp , '_##.png' ) ) )
100+ redraw
101+ when 'd' , 'D'
102+ @show_discs = !show_discs
103+ redraw
104+ when 'p' , 'P'
105+ File . open ( data_path ( 'color_theme.rb' ) , 'w' ) do |file |
106+ file . write ( "# Test Theme\n " )
107+ file . write ( list . to_ruby_string )
108+ end
109+ end
100110 end
101111
102112 def swatches ( sorted , x , y )
0 commit comments