class PaletteTown::Scheme

Public Class Methods

author(author=nil) click to toggle source
# File lib/palettetown/scheme.rb, line 11
def author author=nil
  if author.nil?
    @author
  else
    @author = author
  end
end
darker(color, amount) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/palettetown/scheme.rb, line 18
def description description=nil
  if description.nil?
    @description
  else
    @description = description
  end
end
hi(*options) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/palettetown/scheme.rb, line 4
def name name=nil
  if name.nil?
    @name
  else
    @name = name
  end
end
saturate(color, amount) click to toggle source
# 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) click to toggle source
# 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_s() click to toggle source
# 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