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

Attributes inherited from RMThemeParent

#themename

Instance Method Summary collapse

Methods inherited from RMThemeParent

#before_create, #clean_colorsets, #clear_colorsets, #handle_rand_seed, #reset_colorsets

Constructor Details

#initializeThemeGenerator

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 "

  #for testing purposes of the RGB contrast evaluator
f = File.open("index.html","w+")
st1="<html>"
h = Hash.new
#generate histogram 
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)
    #puts grkcol.contrast(brkcol)
  end until true# grkcol.contrast(brkcol) > 0.20
  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(@rand.rand*256,@rand.rand*256,@rand.rand*256)
#        brkcol = Color::RGB.new(@rand.rand*256,@rand.rand*256,@rand.rand*256)
    grkcol = Color::RGB.new(  0,0,0 )
    brkcol = Color::RGB.new(i,0,0)
    #puts grkcol.contrast(brkcol)
  end until true# grkcol.contrast(brkcol) > 0.20
  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>"
 # grkcol = Color::RGB.new(0xf1,0x11,0x9a)
 # brkcol = Color::RGB.new(0xa0,0xf4,0x2f)
 # 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>"
 # grkcol = Color::RGB.new(0x42,0x08,0x11)
 # brkcol = Color::RGB.new(0x48,0x19,0xd0)
 # st1 += "<p style='background-color:#{grkcol.html};color:#{brkcol.html};'>aBD9 #!#$87 asf asdf werpl  09890 asd78coiuqwe rasdu 987zxcv klj;lcv "
  #st1 += "<span style='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

#xmloutObject (readonly)

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, #these are the usual 0..255 
        :bg_rgb => nil,
        :min_cont  => @min_cont, #if a backrgb (background color)  is supplied this will be used to create a minimum contrast with it.
        :max_cont => @max_cont,
        :max_bright => @max_bright,
        :min_bright => @min_bright,
      #  :bright_median => 0.5,
        :shade_of_grey => false} #forces r == g == b
  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 #mod for robustness 
    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)
  #puts "bg" + @backgroundcolor if df[:bg_rgb]
  #puts "color "+color.html
  #puts "contrast "+color.contrast(df[:bg_rgb]).to_s if df[:bg_rgb]
    contok = df[:bg_rgb] ? (df[:min_cont]..df[:max_cont]).cover?( color.contrast(df[:bg_rgb]) ) : true
  #puts "contok "+contok.to_s
    brightok = (df[:min_bright]..df[:max_bright]).cover?( color.to_hsl.brightness )  
  #puts "brightok "+brightok.to_s
  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

#randthemenameObject



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_cssObject



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
#fout = File.new("index.html", "w+")
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]};"
      #fonttype = 0 #bold: 1,  #italic: 2, bold & italic: 3
      if o[:value][0][:option][3][:value] == '0'
        #neither bold nor italic
        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' #bold and italic
        s+= "font-weight:bold;font-style: italic;"
      end #if
  s+="} "  
    end #if 
  end 
  #these options are all for background values so far (caret row color and selection background)
  # so we will treat them all that way for now (see line 41: s+= " .#{o[:name]} {background-color: \##{o[:value]};} "

  @xmlout[:scheme][0][:colors][0][:option].each do |o|
    if @@tokens_for_css.include? o[:name]
      s+= "#"+ @xmlout[:scheme][0][:name].to_s 
#            puts o.inspect
      s+= " .#{o[:name]} {background-color: \##{o[:value]};} "
    end #if 
  end 
    
s += ' </style> ' 
    #  y="<div id='#{@xmlout[:scheme][0][:name].to_s}'>"
    #    @xmlout[:scheme][0][:attributes][0][:option].each do |o|
    #      if @@tokens_for_css.include? o[:name]
    #        y+= "<span class='#{o[:name]}'>"+ o[:name]+"</span>" 
    #      end #if 
    #    end
return s
end