Skip to content

Commit adb3e34

Browse files
committed
palette
1 parent 5c73016 commit adb3e34

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed
File renamed without changes.

external_library/gem/toxiclibs/color_utils/color_theme.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'toxiclibs'
4+
5+
class PaletteGenerator < Propane::App
6+
7+
attr_reader :mono, :complement
8+
9+
def settings
10+
size 500, 400
11+
end
12+
13+
def setup
14+
sketch_title 'Monochrome and Complementary Blue Swatches'
15+
@mono = Toxi::MonochromeTheoryStrategy.new.create_list_from_color(TColor::BLUE)
16+
@complement = Toxi::ComplementaryStrategy.new.create_list_from_color(TColor::BLUE)
17+
render_palette(mono)
18+
render_palette(complement, 200)
19+
end
20+
21+
def draw
22+
end
23+
24+
def key_pressed
25+
File.open(data_path('palette.rb'), 'w') do |file|
26+
file.write("# Monochrome Blue\n")
27+
file.write(mono.to_ruby_string)
28+
file.write("# Complement Blue\n")
29+
file.write(complement.to_ruby_string)
30+
end
31+
end
32+
33+
def render_palette(palette, ypos = 0)
34+
x = 0
35+
palette.each do |col|
36+
fill col.toARGB
37+
rect x, ypos, x + 100, 100
38+
x += 100
39+
end
40+
end
41+
end
42+
43+
PaletteGenerator.new

0 commit comments

Comments
 (0)