1
1
#!/usr/bin/env jruby
2
2
require 'propane'
3
3
require '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
33
6
34
7
SWATCH_HEIGHT = 40.0
35
8
SWATCH_WIDTH = 5.0
36
9
SWATCH_GAP = 1
37
10
38
11
MAX_SIZE = 150.0
39
12
NUM_DISCS = 300
40
- attr_reader :show_discs , :list
13
+ attr_reader :show_discs
41
14
42
15
def settings
43
16
size ( 1024 , 768 )
17
+ # smooth
44
18
end
45
19
46
20
def setup
@@ -62,7 +36,7 @@ def draw
62
36
# now add another rand hue which is using only bright shades
63
37
t . add_range ( Toxi ::ColorRange ::BRIGHT , TColor . new_random , rand ( 0.02 ..0.05 ) )
64
38
# use the TColor theme to create a list of 160 Colors
65
- @ list = t . get_colors ( 160 )
39
+ list = t . get_colors ( 160 )
66
40
if show_discs
67
41
background ( list . get_lightest . toARGB )
68
42
discs ( list )
@@ -84,29 +58,19 @@ def draw
84
58
list . sort_by_criteria ( Toxi ::AccessCriteria ::HUE , false )
85
59
swatches ( list , 32 , yoff )
86
60
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 )
88
62
swatches ( list , 32 , yoff )
89
63
end
64
+ # save_frame(format('theme-%s%s', timestamp, '_##.png'))
90
65
end
91
66
92
67
def timestamp
93
68
Time . now . strftime ( '%Y%d%m_%H%M%S' )
94
69
end
95
70
96
71
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
110
74
end
111
75
112
76
def swatches ( sorted , x , y )
@@ -130,4 +94,4 @@ def discs(list)
130
94
end
131
95
end
132
96
133
- ColorThemeSketch . new
97
+ ToxicLibsColorTheme . new
0 commit comments