palettetown 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebd987e257be862399b70f73fcb1cc13bdb3bbd2
4
- data.tar.gz: c104fc0972568bfc59de43316bc82009ffa0ca6b
3
+ metadata.gz: 7d70cf361a1952993a74a5563cfd577852410a3a
4
+ data.tar.gz: 5c58590d55cce79f56c796c3685f768595b18704
5
5
  SHA512:
6
- metadata.gz: 0be59beace5d2c8055ada9a2e796453c718af84129058716f306aaa34ef624d15282d56344498b4d7e627cb8a892b62e57f007b0f9a4fa192b87e8f400c7b990
7
- data.tar.gz: 063ab5cc23866dddc2457a693b83eb6c121e5ddc28937b7860414a7a47fc6f5147a719f0f264eaa762bfa381bd2ed1bc8c47cb42a452aab2fcf5d9c9da8b0ff8
6
+ metadata.gz: 86c9ae9f8f737f0c36bd59996efbfc2eed048c8e0312f20f8e0fb509416c4417149840c2d57f4a5d2183656aac067604bf5c39c488481b4b088480a8485098a1
7
+ data.tar.gz: d878ba6111e4e00c705115434ea5b31e4d4b5c6d02738fb34dd6f67689a5749372b77521d134b4a086d83cfde597d3388b0a1344fb1aec5e67e15fe1e930cbda
data/README.md CHANGED
@@ -16,16 +16,21 @@ description 'the most super kawaii theme ever'
16
16
  main_bg = "00FF00"
17
17
 
18
18
  hi :Normal, "0000FF", main_bg
19
- hi :LineNr, darker(hi[:Normal][:fg], 10)
19
+ hi :LineNr, darker(hi[:Normal][:fg], 10.percent)
20
+ hi :String, spin(hi[:Normal][:bg], 90.degrees)
20
21
  hi :Boolean, :bg => main_bg
21
22
  ```
22
23
 
23
24
  ### Helpers
24
- * `lighter(color, amount)` - Increases luminosity of a color by `amount`%.
25
- * `darker(color, amount)` - Decreases luminosity of a color by `amount`%.
26
- * `saturate(color, amount)` - Increases saturation of a color by `amount`%.
27
- * `desaturate(color, amount)` - Decreases saturation of a color by `amount`%.
28
- * `spin(color, amount)` - shifts the hue by `amount` degrees.
25
+ * `lighter(color, amount)` - Increases luminosity of a color by `amount`.
26
+ * `darker(color, amount)` - Decreases luminosity of a color by `amount`.
27
+ * `saturate(color, amount)` - Increases saturation of a color by `amount`.
28
+ * `desaturate(color, amount)` - Decreases saturation of a color by `amount`.
29
+ * `spin(color, amount)` - shifts the hue by `amount` radians.
30
+
31
+ #### Monkeypatches
32
+ * `Fixnum#degrees` - provides a simple expression of degrees, returned in radians
33
+ * `Fixnum#percent` - provides a simple expression of percent, returned as a decimal
29
34
 
30
35
  ## Building a palette file
31
36
  Once you've written a palette file, you build it into a proper vim theme with
@@ -8,3 +8,4 @@ require "palettetown/color"
8
8
  require "palettetown/rule"
9
9
  require "palettetown/scheme"
10
10
  require "palettetown/cli"
11
+ require "palettetown/monkeypatches"
@@ -4,6 +4,8 @@ module PaletteTown
4
4
  def initialize color
5
5
  if color.is_a? String
6
6
  color = self.class.from_hex(color)
7
+ elsif color.is_a? Fixnum
8
+ color = self.class.from_hex("%06x" % color)
7
9
  elsif color.is_a? PaletteTown::Color
8
10
  color = color.to_h
9
11
  elsif color.is_a? Hash
@@ -25,9 +27,10 @@ module PaletteTown
25
27
  @lum + @sat - (@lum * @sat)
26
28
  end
27
29
  x = @lum * 2.0 - y
28
- r = self.class.hue_to_rgb(x, y, @hue + 1.0/3.0)
29
- g = self.class.hue_to_rgb(x, y, @hue)
30
- b = self.class.hue_to_rgb(x, y, @hue - 1.0/3.0)
30
+ # Why are we using 2pi here? Because we're using Radians, bitch.
31
+ r = self.class.hue_to_rgb(x, y, @hue * Math::PI * 2 + 1.0/3.0)
32
+ g = self.class.hue_to_rgb(x, y, @hue * Math::PI * 2)
33
+ b = self.class.hue_to_rgb(x, y, @hue * Math::PI * 2 - 1.0/3.0)
31
34
  end
32
35
  return {
33
36
  :r => (r * 255).to_i,
@@ -52,9 +55,9 @@ module PaletteTown
52
55
  private
53
56
  def self.from_hex color
54
57
  color.shift if color[0] == '#'
55
- r = color[0...2].to_i 16
56
- g = color[2...4].to_i 16
57
- b = color[4...6].to_i 16
58
+ r = color[0..1].to_i 16
59
+ g = color[2..3].to_i 16
60
+ b = color[4..5].to_i 16
58
61
 
59
62
  from_rgb(r, g, b)
60
63
  end
@@ -92,6 +95,7 @@ module PaletteTown
92
95
  hue += 4
93
96
  end
94
97
  hue /= 6
98
+ hue *= Math::PI * 2 # Convert 0..1 into radians
95
99
  end
96
100
  return {hue: hue, sat: sat, lum: lum}
97
101
  end
@@ -0,0 +1,8 @@
1
+ class Fixnum
2
+ def percent
3
+ return self / 100.0
4
+ end
5
+ def degrees
6
+ return self * (Math::PI / 180.0)
7
+ end
8
+ end
@@ -24,26 +24,26 @@ module PaletteTown
24
24
  end
25
25
  def lighter color, amount
26
26
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
27
- color.lum += amount / 100.0
27
+ color.lum *= 1.0 - amount
28
28
  color
29
29
  end
30
30
  def darker color, amount
31
31
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
32
- color.lum -= amount / 100.0
32
+ color.lum *= 1.0 - amount
33
33
  color
34
34
  end
35
35
  def saturate color, amount
36
36
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
37
- color.sat += amount / 100.0
37
+ color.sat *= 1.0 + amount
38
38
  color
39
39
  end
40
40
  def desaturate color, amount
41
41
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
42
- color.sat -= amount / 100.0
42
+ color.sat *= 1.0 - amount
43
43
  end
44
44
  def spin color, amount
45
45
  color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
46
- color.hue += amount / 360.0
46
+ color.hue += amount
47
47
  color
48
48
  end
49
49
  def hi *options
@@ -1,3 +1,3 @@
1
1
  module Palettetown
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: palettetown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Lejeck
@@ -69,6 +69,7 @@ files:
69
69
  - lib/palettetown.rb
70
70
  - lib/palettetown/cli.rb
71
71
  - lib/palettetown/color.rb
72
+ - lib/palettetown/monkeypatches.rb
72
73
  - lib/palettetown/rule.rb
73
74
  - lib/palettetown/scheme.rb
74
75
  - lib/palettetown/version.rb