Skip to content

Commit 48cc55d

Browse files
committed
to rubystring
1 parent 698305d commit 48cc55d

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

external_library/gem/toxiclibs/color_utils/color_theme.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
MAX_SIZE = 150.0
3636
NUM_DISCS = 300
37-
attr_reader :show_discs
37+
attr_reader :show_discs, :list
3838

3939
def settings
4040
size(1024, 768)
@@ -60,7 +60,7 @@ def draw
6060
# now add another rand hue which is using only bright shades
6161
t.add_range(ColorRange::BRIGHT, TColor.new_random, rand(0.02..0.05))
6262
# use the TColor theme to create a list of 160 Colors
63-
list = t.get_colors(160)
63+
@list = t.get_colors(160)
6464
if show_discs
6565
background(list.get_lightest.toARGB)
6666
discs(list)
@@ -85,16 +85,27 @@ def draw
8585
list.sort_by_proximity_to(NamedColor::WHITE, RGBDistanceProxy.new, false)
8686
swatches(list, 32, yoff)
8787
end
88-
# save_frame(format('theme-%s%s', timestamp, '_##.png'))
88+
#
8989
end
9090

9191
def timestamp
9292
Time.now.strftime('%Y%d%m_%H%M%S')
9393
end
9494

9595
def key_pressed
96-
@show_discs = !show_discs if key == ' '
97-
redraw
96+
case key
97+
when 's', 'S'
98+
save_frame(data_path(format('theme-%s%s', timestamp, '_##.png')))
99+
redraw
100+
when 'd', 'D'
101+
@show_discs = !show_discs
102+
redraw
103+
when 'p', 'P'
104+
File.open(data_path('color.rb'), 'w') do |file|
105+
file.write("# Test Theme\n")
106+
file.write(list.to_ruby_string)
107+
end
108+
end
98109
end
99110

100111
def swatches(sorted, x, y)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'toxiclibs'
2+
include_package 'toxi.color'
3+
include_package 'toxi.color.theory'
4+
5+
attr_reader :list
6+
7+
def settings
8+
size 500, 100
9+
end
10+
11+
def setup
12+
sketch_title 'blues'
13+
@list = MonochromeTheoryStrategy.new.create_list_from_color(TColor::BLUE)
14+
x = 0
15+
list.each do |col|
16+
fill col.toARGB
17+
rect x, 0, x + 100, 100
18+
x += 100
19+
end
20+
end
21+
22+
def draw
23+
end
24+
25+
def key_pressed
26+
File.open(data_path('color.rb'), 'w') do |file|
27+
file.write("# Monochrome Blue\n")
28+
file.write(list.to_ruby_string)
29+
end
30+
end

0 commit comments

Comments
 (0)