Class: PaletteTown::Scheme

Inherits:
Object
  • Object
show all
Defined in:
lib/palettetown/scheme.rb

Class Method Summary collapse

Class Method Details

.author(author = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/palettetown/scheme.rb', line 11

def author author=nil
  if author.nil?
    @author
  else
    @author = author
  end
end

.darker(color, amount) ⇒ Object



30
31
32
33
34
# File 'lib/palettetown/scheme.rb', line 30

def darker color, amount
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
  color.lum *= 1.0 - amount
  color
end

.desaturate(color, amount) ⇒ Object



40
41
42
43
# File 'lib/palettetown/scheme.rb', line 40

def desaturate color, amount
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
  color.sat *= 1.0 - amount
end

.description(description = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/palettetown/scheme.rb', line 18

def description description=nil
  if description.nil?
    @description
  else
    @description = description
  end
end

.hi(*options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/palettetown/scheme.rb', line 49

def hi *options
  return @rules if options.length == 0

  @rules ||= {}
  rule = options.shift
  if options[0].is_a? Hash
    options = options[0]
  else
    options = {
      :fg => options[0],
      :bg => options[1]
    }
  end
  @rules[rule] = PaletteTown::Rule.new(options)
end

.lighter(color, amount) ⇒ Object



25
26
27
28
29
# File 'lib/palettetown/scheme.rb', line 25

def lighter color, amount
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
  color.lum *= 1.0 - amount
  color
end

.name(name = nil) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/palettetown/scheme.rb', line 4

def name name=nil
  if name.nil?
    @name
  else
    @name = name
  end
end

.saturate(color, amount) ⇒ Object



35
36
37
38
39
# File 'lib/palettetown/scheme.rb', line 35

def saturate color, amount
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
  color.sat *= 1.0 + amount
  color
end

.spin(color, amount) ⇒ Object



44
45
46
47
48
# File 'lib/palettetown/scheme.rb', line 44

def spin color, amount
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
  color.hue += amount
  color
end

.to_sObject



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
# File 'lib/palettetown/scheme.rb', line 64

def to_s
  out = <<-EOF
" Vim color file
"   Generated by PaletteTown
"   http://nuckchorris.github.io/palettetown/
"
" Name: #{name}
" Author: #{author}
" Notes: #{description}

hi clear
if version > 580
  if exists("syntax_on")
    syntax reset
  endif
endif

let colors_name="#{name}"

EOF
  if @rules[:Normal]
    out << <<-EOF
if has("gui_running")
  set background=#{if @rules[:Normal][:guibg].lum < 0.5 then "dark" else "light" end}
endif

EOF
    @rules[:Normal][:guibg].lum < 0.5
  else
    warn "No Normal hilight found; can't guess background"
  end
  @rules.each do |rule, opts|
    out << "hi #{rule}"
    opts.each do |key, val|
      out << " #{key}=#{val}" unless val.nil?
    end
    out << "\n"
  end
  out
end