62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/color/coloryze.rb', line 62
def initialize(args, outio = $stdout, errio = $stderr)
info "args: #{args}"
@exit_status = 0
@scheme_options = Array.new
_add_option("monochromatic", "display one hue", Color::Monochromatic, :hue)
_add_option("split-complementary", "display hue and two complements near 180 degrees", Color::SplitComplementary, :hue, :deg)
_add_option("double-complementary", "display two hues and their two complements", Color::DoubleComplementary, :hue, :hue)
_add_option("complementary", "display hues at 180 degrees from each other", Color::Complementary, :hue)
_add_option("analogous", "display three hues near each other", Color::Analogous, :hue, :deg)
_add_option("triadic", "display three equidistant hues", Color::Triadic, :hue)
_add_option("hues", "display colors for the generated hues (no scheme applied)", Color::Hues, :start, :end, :int)
output_type = :html
sample = nil
total_sample = nil
@scheme_options.each do |sopt|
end
sopt = nil
scheme_args = Array.new
params = {
:background => nil,
:saturation_start => nil,
:saturation_end => nil,
:saturation_step => nil,
:brightness_start => nil,
:brightness_end => nil,
:brightness_step => nil,
}
args.each do |arg|
info "arg: #{arg}"
case arg
when %r{--(saturation|brightness)=(\d+),(\d+),(\d+)}
md = Regexp.last_match
fieldname = md[1]
%w{ _start _end _step }.each_with_index do |fieldsuffix, idx|
field = (fieldname + fieldsuffix).intern
params[field] = md[idx + 2].to_i
end
when %r{--output=(\w+)}
md = Regexp.last_match
output_type = md[1].intern
when "--version"
show_version(outio)
@exit_status = 0
return
when "--verbose"
Log.level = Log::DEBUG
when %r{--sample=(\d+)}
md = Regexp.last_match
sample = md[1].to_i
when %r{--total-sample=(\d+)}
md = Regexp.last_match
total_sample = md[1].to_i
when "--help", "--usage"
show_usage(outio)
@exit_status = 0
return
else
md = nil
if sopt
$stderr.puts "error: invalid argument: #{arg}"
@sxit_status = 1
elsif sopt = @scheme_options.detect { |so| md = so.re.match(arg) }
sopt.set_args(md[1 .. -1])
scheme_args.concat(md[1 .. -1])
end
end
end
unless sopt
args.each do |arg|
@scheme_options.each do |so|
if arg.index("--" + so.stype)
info "matched #{so}"
errio.puts "error: scheme '#{so.stype}' requires " + so.params.collect { |p| p.to_s }.join(",")
@exit_status = 1
return
end
end
end
end
unless sopt
show_usage(outio)
@exit_status = 1
return
end
info "sopt: #{sopt}"
info "scheme_args: #{scheme_args}"
hues = sopt.cls.new(*sopt.args).hues
info "hues: #{hues}"
info "params: #{params}"
info "sample: #{sample}"
info "total_sample: #{total_sample}"
palette_cls = if sample || total_sample
params[:samples] = sample
params[:total_samples] = total_sample
Color::SamplePalette
else
Color::FullPalette
end
palette = palette_cls.new(hues, params)
info "palette: #{palette}"
if output_type == :html
palette.print_as_html(outio)
else
palette.print_as_text(outio)
end
end
|