color-japanese 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ ##alias target red
2
+
3
+ % include Color::RGB::JP::ERBUtil
4
+ % include ERB::Util
5
+
6
+ <html>
7
+ <head>
8
+ <title><%=h pallet %>::<%=h lookup("target").name.const_name %></title>
9
+ <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
10
+ <style>
11
+ table {
12
+ width: 100%;
13
+ }
14
+ table, tr, th, td {
15
+ border: 1px solid black;
16
+ border-collapse: collapse;
17
+ }
18
+ th, td {
19
+ padding: 4px;
20
+ width: 20%;
21
+ }
22
+ span {
23
+ font-size: 3px;
24
+ width: 100%; display: block;
25
+ }
26
+ </style>
27
+ </head>
28
+ <body>
29
+
30
+ <h1><%=h pallet %>::<%=h lookup("target").name.const_name %></h1>
31
+
32
+ % filters = [:lighten_by, :darken_by, :adjust_brightness, :adjust_saturation, :adjust_hue]
33
+
34
+ <table>
35
+ <tr>
36
+ % filters.each do |filter|
37
+ <th><%= filter %></th>
38
+ % end
39
+ </tr>
40
+
41
+ <tr>
42
+ % filters.each do |filter|
43
+ <td>
44
+ % 100.times do |i|
45
+ % v = ##target.__send__(filter, i)
46
+ <span title="<%= filter %>(<%= i %>) = <%=h v %>"
47
+ style="background-color: <%= v %>">
48
+ &nbsp;
49
+ </span>
50
+ % end
51
+ </td>
52
+ % end
53
+ </tr>
54
+ </table>
55
+
56
+ </body>
57
+ </html>
@@ -0,0 +1,173 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require "erb"
4
+ require "optparse"
5
+ require "rubygems"
6
+
7
+ libdir = File.join(File.dirname(__FILE__), "../lib")
8
+ $LOAD_PATH << libdir
9
+ require "color/rgb/jp"
10
+
11
+ def with_output_stream(output)
12
+ if output == $stdout or output == "-"
13
+ yield $stdout
14
+ else
15
+ open(output, "w"){|out| yield out }
16
+ end
17
+ end
18
+
19
+
20
+ name = nil
21
+ output = $stdout
22
+ ARGV.options do |opt|
23
+ opt.on("-p=PALLET"){|v| name = v}
24
+ opt.on("-o=OUTPUT"){|v| output = v}
25
+ opt.parse!
26
+ end
27
+
28
+ pallet = Color::RGB::JP.pallets.find{|e| e.name.split(/::/).last == name }
29
+ raise "unknown pallet `#{name}'" unless pallet
30
+
31
+ colors = pallet.colors
32
+ with_output_stream(output) do |out|
33
+ out.puts ERB.new(DATA.read, 0, "%<>").result(binding)
34
+ end
35
+
36
+
37
+ __END__
38
+ % def trad(name)
39
+ % Color::RGB::JP::Trad[name].rgb.html
40
+ % end
41
+ <html>
42
+ <head>
43
+ <title>color-japanese: <%= pallet %></title>
44
+ <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
45
+ <style type="text/css">
46
+ <!--
47
+ body {
48
+ color: <%= trad("暗黒色") %>;
49
+ background: <%= trad("胡粉色") %>;
50
+ }
51
+ input {
52
+ width: 10em;
53
+ }
54
+ table, th, td {
55
+ border-collapse: collapse;
56
+ border: 1px solid <%= trad("桜鼠") %>
57
+ }
58
+ th, td {
59
+ padding: 4px;
60
+ }
61
+ #search {
62
+ color: <%= trad("藍鉄") %>;
63
+ width: 100%;
64
+ }
65
+ -->
66
+ </style>
67
+ <script type="text/javascript">
68
+ <!--
69
+ var cache = {};
70
+ var colors = {};
71
+ <% colors.each_with_index do |c,i| %>
72
+ colors["c<%= i %>"] = ["<%= c.name.const_name.downcase %>", "<%= c.name.kanji %>", "<%= c.name.hiragana %>", "<%= c.name.katakana %>", "<%= c.name.romaji.downcase %>"];
73
+ <% end %>
74
+
75
+ function lookup(names, q) {
76
+ var queries = q.toLowerCase().split(/\s+/);
77
+ for (var i = 0; i < queries.length; i++) {
78
+ if (!lookup1(names, queries[i])) {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ }
84
+
85
+ function lookup1(names, query) {
86
+ for (var i = 0; i < names.length; i++) {
87
+ if (names[i].indexOf(query) > -1) {
88
+ return true;
89
+ }
90
+ }
91
+ return false;
92
+ }
93
+
94
+ function do_search(q) {
95
+ for (var key in colors) {
96
+ var names = colors[key];
97
+ var e = cache[key] = cache[key] || document.getElementById(key);
98
+ if (e != undefined && lookup(names, q)) {
99
+ e.style.display = "";
100
+ } else {
101
+ e.style.display = "none";
102
+ }
103
+ }
104
+ }
105
+
106
+ function setup_event() {
107
+ var input = document.getElementById("search");
108
+ input.onfocus = function() {
109
+ if (input.value == "search") {
110
+ input.value = "";
111
+ input.style.color = "black";
112
+ }
113
+ };
114
+ input.onblur = function() {
115
+ if (input.value == "") {
116
+ input.value = "search";
117
+ input.style.color = "<%= trad("藍鉄") %>";
118
+ }
119
+ };
120
+
121
+ var form = document.getElementById("search_box");
122
+ form.onsubmit = function() {
123
+ var q = input.value;
124
+ input.style.backgroundColor = "<%= trad("虹色") %>";
125
+ window.setTimeout(function () {
126
+ do_search(q);
127
+ input.style.backgroundColor = "";
128
+ input.focus();
129
+ }, 100);
130
+
131
+ return false;
132
+ };
133
+ }
134
+ -->
135
+ </script>
136
+
137
+ </head>
138
+ <body onload="setup_event();">
139
+ <h1><%= pallet %></h1>
140
+
141
+ <form id="search_box">
142
+ <input accesskey="a" id="search" value="search"/>
143
+ </form>
144
+
145
+ <table style="width: 100%">
146
+ <tr>
147
+ <th style="width: 12%">const</th>
148
+ <th style="width: 12%">color name (kanji/hiragana)</th>
149
+ <th style="width: 12%">color name (romaji)</th>
150
+ <th>RGB</th>
151
+ </tr>
152
+ % colors.each_with_index do |c,i|
153
+ <tr id="c<%= i %>">
154
+ <td><%= c.name.const_name %></td>
155
+ <td>
156
+ % if c.name.kanji.nil?
157
+ <%= c.name.katakana %>
158
+ % else
159
+ <ruby>
160
+ <rb><%= c.name.kanji %></rb><rp>(</rp><rt><%= c.name.hiragana %></rt><rp>)</rp>
161
+ </ruby>
162
+ % end
163
+ </td>
164
+ <td><%= c.name.romaji %></td>
165
+ <td style="background: <%= c.rgb.html %>">
166
+ <input onclick="this.select()" value="<%= c.rgb.html %>"/><br>
167
+ <input onclick="this.select()" value="rgb(<%= (c.rgb.r * 255).round %>, <%= (c.rgb.g * 255).round %>, <%= (c.rgb.b * 255).round %>)"/>
168
+ </td>
169
+ </tr>
170
+ % end
171
+ </table>
172
+ </body>
173
+ </html>
@@ -0,0 +1,66 @@
1
+ @charset "Shift_JIS";
2
+
3
+ ##alias myblue �I���F
4
+ ##alias mypink ���[�Y
5
+ ##alias myborder �X�m�[�z���C�g
6
+
7
+ h1 {
8
+ color: ##myblue;
9
+ }
10
+
11
+ h1 span {
12
+ color: ##mypink;
13
+ }
14
+
15
+ .link {
16
+ color: ##myblue;
17
+ }
18
+
19
+ .active {
20
+ color: ##mypink;
21
+ }
22
+
23
+ .comment h4 {
24
+ color: ##mypink;
25
+ }
26
+
27
+ a {
28
+ text-decoration: none;
29
+ }
30
+
31
+ a:link,
32
+ a:visited, {
33
+ color: ##myblue;
34
+ }
35
+
36
+ a:over,
37
+ a:active {
38
+ colro: white;
39
+ background-color: ##myblue;
40
+ }
41
+
42
+ body {
43
+ margin: 0;
44
+ padding: 0;
45
+ }
46
+
47
+ #header {
48
+ padding: 0 100px 1em 100px;
49
+ margin-bottom: 2em;
50
+ border-bottom: 1px dotted ##myborder;
51
+ }
52
+
53
+ #body {
54
+ padding: 0 100px 1em 100px;
55
+ }
56
+
57
+ #footer {
58
+ padding: 0 100px 1em 100px;
59
+ margin-top: 2em;
60
+ border-top: 1px dotted ##myborder;
61
+ }
62
+
63
+ address {
64
+ color: gray;
65
+ font-style: normal;
66
+ }
@@ -0,0 +1,60 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
6
+ <head>
7
+ <title>color-japanese example</title>
8
+ <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
9
+ <link href="default.css" type="text/css" rel="stylesheet" />
10
+ </head>
11
+ <body>
12
+
13
+ <div id="header">
14
+ <h1>colo<span>r</span>-japanese</h1>
15
+
16
+ <a href="#">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;
17
+ <a href="#">Traditional</a>&nbsp;&nbsp;&nbsp;&nbsp;
18
+ <a href="#">JISZ8102</a>
19
+ </div>
20
+
21
+ <div id="body">
22
+ <h2>
23
+ <span class="link">Color</span> /
24
+ <span class="link">RGB</span> /
25
+ <span class="link">JP</span> /
26
+ <span class="active">Traditional</span>
27
+ </h2>
28
+
29
+ <h3>foobar</h3>
30
+
31
+ <p>
32
+ The quick brown fox jumps over the lazy dog.<br/>
33
+ The quick brown fox jumps over the lazy dog.<br/>
34
+ The quick brown fox jumps over the lazy dog.<br/>
35
+ The quick brown fox jumps over the lazy dog.<br/>
36
+ The quick brown fox jumps over the lazy dog.<br/>
37
+ The quick brown fox jumps over the lazy dog.<br/>
38
+ The quick brown fox jumps over the lazy dog.<br/>
39
+ The quick brown fox jumps over the lazy dog.<br/>
40
+ The quick brown fox jumps over the lazy dog.<br/>
41
+ The quick brown fox jumps over the lazy dog.<br/>
42
+ The quick brown fox jumps over the lazy dog.<br/>
43
+ </p>
44
+
45
+ <div class="comment">
46
+ <h4>Would you like to comment?</h4>
47
+ <p>
48
+ The quick brown fox jumps over the lazy dog.<br/>
49
+ </p>
50
+ </div>
51
+ </div>
52
+
53
+ <div id="footer">
54
+ <address>
55
+ The quick brown fox jumps over the lazy dog.
56
+ </address>
57
+ </div>
58
+
59
+ </body>
60
+ </html>
@@ -0,0 +1,58 @@
1
+ require "optparse"
2
+
3
+ require "rubygems"
4
+ require "color/rgb/jp"
5
+
6
+ module Enumerable
7
+ def sum
8
+ self.inject(0.0){|s,e| s + e }
9
+ end
10
+ end
11
+
12
+ class Color::RGB
13
+ def to_a
14
+ [r, g, b]
15
+ end
16
+
17
+ def distance(other)
18
+ euclid_distance(self.to_a, other.to_a)
19
+ end
20
+
21
+ private
22
+
23
+ def euclid_distance(a, b)
24
+ Math.sqrt(a.zip(b).map{|aa,bb| (aa - bb) ** 2 }.sum)
25
+ end
26
+ end
27
+
28
+ def palletize(pallet, color, n = 1)
29
+ pallet.sort_by {|e| color.distance(e.rgb) }[0...n]
30
+ end
31
+
32
+
33
+ pallets = [Color::RGB::JP::JISZ8102, Color::RGB::JP::Traditional]
34
+ n = 3
35
+ ARGV.options do |opt|
36
+ opt.banner = "Usage: palletize [-n] rgb_hex_values..."
37
+ opt.on("-n=N", "output top N candidates", Integer) {|v| n = v }
38
+ opt.parse!
39
+ end
40
+ if ARGV.empty?
41
+ ARGV.options.parse("-h")
42
+ exit 1
43
+ end
44
+
45
+ ARGV.each do |c|
46
+ rgb = Color::RGB.from_html(c)
47
+ puts "=== %s (%s) ===" % [c, rgb.html]
48
+ puts
49
+ pallets.each do |pallet|
50
+ puts " [%s]" % pallet.name
51
+ puts
52
+ alts = palletize(pallet, rgb, n)
53
+ alts.each_with_index do |alt, i|
54
+ puts " %2d: %-20s %s" % [i + 1, alt.name.romaji, alt.rgb.html]
55
+ end
56
+ puts
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ require "helper/util"
2
+ require "helper/rake"
3
+ require "helper/rake_sh_filter"
@@ -0,0 +1,58 @@
1
+ require "rubygems"
2
+ require "rake"
3
+
4
+ def tasks
5
+ Rake.application.instance_eval { @tasks }
6
+ end
7
+
8
+ def current_scope
9
+ Rake.application.instance_eval { @scope.last }
10
+ end
11
+
12
+ def task_defined?(task_name)
13
+ Rake::Task.task_defined?(task_name)
14
+ end
15
+
16
+ def remove_tasks(*task_names)
17
+ task_names.flatten.each do |task_name|
18
+ remove_task(task_name)
19
+ end
20
+ end
21
+
22
+ def remove_task(task_name)
23
+ tasks.delete(task_name.to_s)
24
+ end
25
+
26
+ def lookup_task(task_name)
27
+ Rake::Task[task_name] rescue nil
28
+ end
29
+
30
+ def rakecall(task_name)
31
+ lookup_task(task_name).invoke
32
+ end
33
+
34
+ def override_task(task_args, &block)
35
+ task_name, deps = Rake.application.resolve_args(task_args)
36
+ original = lookup_task(task_name)
37
+ orgproc = lambda {} # nop
38
+ if original
39
+ Rake.application.last_comment = original.comment
40
+ deps |= original.prerequisites
41
+ orgproc = lambda{ original.execute }
42
+ end
43
+
44
+ remove_task(task_name)
45
+ Rake::Task.define_task(task_name => deps) do |t|
46
+ block.call(t, orgproc)
47
+ end
48
+ end
49
+
50
+ def task_for_windows(task_args, &block)
51
+ override_task(task_args) do |t, org|
52
+ if windows?
53
+ block.call(t)
54
+ else
55
+ org.call
56
+ end
57
+ end
58
+ end