11#!/usr/bin/env jruby
22require 'propane'
33require 'toxiclibs'
4- # ColorTheme demo showing the following:
5- # - construction of TColor themes via textual descriptions of shades and Colors
6- # - adding an rand element to the theme
7- #
8- # Press SPACE to toggle rendering mode, any other key will re-generate a
9- # random variation of the color theme
10- #
11- # @author Karsten Schmidt <info at postspectacular dot com>
12- # Copyright (c) 2009 Karsten Schmidt
13- #
14- # This demo & library is free software you can redistribute it and/or
15- # modify it under the terms of the GNU Lesser General Public
16- # License as published by the Free Software Foundation either
17- # version 2.1 of the License, or (at your option) any later version.
18- #
19- # http://creativecommons.org/licenses/LGPL/2.1/
20- #
21- # This library is distributed in the hope that it will be useful,
22- # but WITHOUT ANY WARRANTY without even the implied warranty of
23- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24- # Lesser General Public License for more details.
25- #
26- # You should have received a copy of the GNU Lesser General Public
27- # License along with this library if not, write to the Free Software
28- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29- class ColorThemeSketch < Propane ::App
30-
31- include_package 'toxi.color'
32- include_package 'toxi.util.datatypes'
4+ # Demo of small part of toxiclibs color utils
5+ class ToxicLibsColorTheme < Propane ::App
336
347 SWATCH_HEIGHT = 40.0
358 SWATCH_WIDTH = 5.0
369 SWATCH_GAP = 1
3710
3811 MAX_SIZE = 150.0
3912 NUM_DISCS = 300
40- attr_reader :show_discs , :list
13+ attr_reader :show_discs
4114
4215 def settings
4316 size ( 1024 , 768 )
17+ # smooth
4418 end
4519
4620 def setup
@@ -62,7 +36,7 @@ def draw
6236 # now add another rand hue which is using only bright shades
6337 t . add_range ( Toxi ::ColorRange ::BRIGHT , TColor . new_random , rand ( 0.02 ..0.05 ) )
6438 # use the TColor theme to create a list of 160 Colors
65- @ list = t . get_colors ( 160 )
39+ list = t . get_colors ( 160 )
6640 if show_discs
6741 background ( list . get_lightest . toARGB )
6842 discs ( list )
@@ -84,29 +58,19 @@ def draw
8458 list . sort_by_criteria ( Toxi ::AccessCriteria ::HUE , false )
8559 swatches ( list , 32 , yoff )
8660 yoff += SWATCH_HEIGHT + 10
87- list . sort_by_proximity_to ( Toxi ::NamedColor ::WHITE , Toxi :: RGBDistanceProxy . new , false )
61+ list . sort_by_proximity_to ( Toxi ::NamedColor ::WHITE , RGBDistanceProxy . new , false )
8862 swatches ( list , 32 , yoff )
8963 end
64+ # save_frame(format('theme-%s%s', timestamp, '_##.png'))
9065 end
9166
9267 def timestamp
9368 Time . now . strftime ( '%Y%d%m_%H%M%S' )
9469 end
9570
9671 def key_pressed
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
72+ @show_discs = !show_discs if key == ' '
73+ redraw
11074 end
11175
11276 def swatches ( sorted , x , y )
@@ -130,4 +94,4 @@ def discs(list)
13094 end
13195end
13296
133- ColorThemeSketch . new
97+ ToxicLibsColorTheme . new
0 commit comments