Class: RMThemeGen::ThemeGenerator
- Inherits:
-
RMThemeParent
show all
- Defined in:
- lib/rmthemegen/rgb_contrast_test.rb,
lib/rmthemegen/rmthemegen_to_css.rb
Instance Attribute Summary collapse
-
#xmlout ⇒ Object
readonly
a huge structure of xml that can be given to XmlSimple.xml_out() to create that actual color theme file.
#themename
Instance Method Summary
collapse
#before_create, #clean_colorsets, #clear_colorsets, #handle_rand_seed, #reset_colorsets
Constructor Details
Returns a new instance of ThemeGenerator.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/rmthemegen/rgb_contrast_test.rb', line 11
def initialize
@iterations = 0
@iterations = ARGV[0].to_s.to_i
puts "rgb_contrast methods -- this should create an index.html that displays samples of text and their contrast rating by the methods in contrast_methods "
f = File.open("index.html","w+")
st1="<html>"
h = Hash.new
0.times do
begin
grkcol = Color::RGB.new(@rand.rand*256,@rand.rand*256,@rand.rand*256)
brkcol = Color::RGB.new(@rand.rand*256,@rand.rand*256,@rand.rand*256)
end until true key =(grkcol.contrast(brkcol)*100).to_i
h[key] = h.has_key?(key) ? h[key] += 1 : 1
end
0.upto 0 do |f|
st1 += "<p>"+f.to_s+": "+ ( h[f.to_i] ? h[f.to_i].to_s : "nada")+"</p>"
end
0.upto 255 do |i|
begin
grkcol = Color::RGB.new( 0,0,0 )
brkcol = Color::RGB.new(i,0,0)
end until true st1 += "<p style='padding:0;margin:0;background-color:#{grkcol.html};color:#{brkcol.html};'>aBD9 #!#$87 asf asdf werpl 09890 asd78coiuqwe rasdu 987zxcv klj;lcv "
st1 += "<span style='padding:0;margin:0;background-color:#ffffff;color:#000000;'>hue/lum/bri/all: #{(100*grkcol.diff_hue(brkcol)).to_i}/#{(100*grkcol.diff_lum(brkcol)).to_i}/#{(100*grkcol.diff_bri(brkcol)).to_i}/#{(100*grkcol.contrast(brkcol)).to_i}</p>"
end
st1+="</html>"
printf(f,st1)
f.close
end
|
Instance Attribute Details
#xmlout ⇒ Object
a huge structure of xml that can be given to XmlSimple.xml_out() to create that actual color theme file
9
10
11
|
# File 'lib/rmthemegen/rgb_contrast_test.rb', line 9
def xmlout
@xmlout
end
|
Instance Method Details
#randcolor(opts = {}) ⇒ Object
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
|
# File 'lib/rmthemegen/rgb_contrast_test.rb', line 88
def randcolor(opts={})
df= { :r=>nil, :g=>nil, :b=>nil, :bg_rgb => nil,
:min_cont => @min_cont, :max_cont => @max_cont,
:max_bright => @max_bright,
:min_bright => @min_bright,
:shade_of_grey => false} df = df.merge opts
df[:bg_rgb] = Color::RGB.from_html(df[:bg_rgb]) if df[:bg_rgb]
color = brightok = contok = nil;
while (!color || !brightok || !contok ) do
r = (df[:r] || rand*256)%256 g = (df[:g] || rand*256)%256
b = (df[:b] || rand*256)%256
g = b = r if df[:shade_of_grey] == true
color = Color::RGB.new(r,g,b)
contok = df[:bg_rgb] ? (df[:min_cont]..df[:max_cont]).cover?( color.contrast(df[:bg_rgb]) ) : true
brightok = (df[:min_bright]..df[:max_bright]).cover?( color.to_hsl.brightness )
end
cn = color.html
cn= cn.slice(1,cn.size)
return cn
end
|
#randfilename(existing = "") ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/rmthemegen/rgb_contrast_test.rb', line 73
def randfilename(existing = "")
if existing != "" then
out=existing
else
ar=["a","b","f","h","z","1","5"]
ar.shuffle!
out =""
ar.each { |n|
out << n
}
end
return "rmt_"+out+".xml"
end
|
#randthemename ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/rmthemegen/rgb_contrast_test.rb', line 65
def randthemename
out = " "
while out.include? " " do
out = @@adjectives[rand * @@adjectives.size]+"_"+@@nouns[rand * @@nouns.size]
end
return out
end
|
#to_css ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rmthemegen/rmthemegen_to_css.rb', line 24
def to_css
s = ' <style type="text/css"> '
s+= "#"+ @xmlout[:scheme][0][:name].to_s
s+=" { background-color: \##{@backgroundcolor.to_s}; } "
@xmlout[:scheme][0][:attributes][0][:option].each do |o|
if @@tokens_for_css.include? o[:name]
s+= "#"+ @xmlout[:scheme][0][:name].to_s
s+= " .#{o[:name]} {color: \##{o[:value][0][:option][0][:value]};"
if o[:value][0][:option][3][:value] == '0'
s+= ""
elsif o[:value][0][:option][3][:value] == '1'
s+= "font-weight:bold;"
elsif o[:value][0][:option][3][:value] == '2'
s+= "font-style:italic;"
elsif o[:value][0][:option][3][:value] == '2' s+= "font-weight:bold;font-style: italic;"
end s+="} "
end end
@xmlout[:scheme][0][:colors][0][:option].each do |o|
if @@tokens_for_css.include? o[:name]
s+= "#"+ @xmlout[:scheme][0][:name].to_s
s+= " .#{o[:name]} {background-color: \##{o[:value]};} "
end end
s += ' </style> '
return s
end
|