unmagic-color 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -0
- data/lib/unmagic/color/console/help.rb +9 -27
- data/lib/unmagic/color/gradient/bitmap.rb +21 -0
- data/lib/unmagic/color/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 971c6c19affe985327415a3993e1b47b739a972a51617a39c92be5c4a1af2f2e
|
|
4
|
+
data.tar.gz: a44de67386e8360347f526b97fc14e925178c475cd93c46fbd831444fd4bc776
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c24ada886792f4443852806fbe7fbae4a491d7428f83eb61e830ce7b768daf7a0b4d46ec615bd8e4f88b797501baedeafd9b6ada46fc6767d4dc3922e481ebb
|
|
7
|
+
data.tar.gz: fa0b066a29064c5d0db5db70a60489a2201eb5970860865b86b5927eb9f2f64a96e258dcfb85aecf37a0d8e1afda94e702a174e3310fb51408f41500bcad326e
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.2] - 2026-01-05
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Gradient::Bitmap#to_ansi` method to render gradients as colored blocks in terminal
|
|
14
|
+
|
|
10
15
|
## [0.2.1] - 2026-01-05
|
|
11
16
|
|
|
12
17
|
### Added
|
|
@@ -81,6 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
81
86
|
- HSL color progressions for palette generation
|
|
82
87
|
- Multiple hash functions for string-to-color derivation
|
|
83
88
|
|
|
89
|
+
[0.2.2]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.2.2
|
|
84
90
|
[0.2.1]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.2.1
|
|
85
91
|
[0.2.0]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.2.0
|
|
86
92
|
[0.1.0]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
A comprehensive Ruby color manipulation library with support for RGB, HSL, and OKLCH color spaces. Parse, convert, and manipulate colors with an intuitive API.
|
|
6
6
|
|
|
7
|
+
We have a fancy-pants WASM based demo here: https://unreasonable-magic.github.io/unmagic-color/
|
|
8
|
+
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
11
|
Add this line to your application's Gemfile:
|
|
@@ -17,38 +17,20 @@ module Unmagic
|
|
|
17
17
|
link = highlighter.link("https://github.com/unreasonable-magic/unmagic-color")
|
|
18
18
|
|
|
19
19
|
code = highlighter.highlight(<<~RUBY)
|
|
20
|
-
# Parse
|
|
20
|
+
# Parse a color (hex, rgb, hsl, oklch, ansi, css named, x11)
|
|
21
21
|
parse("#ff5733")
|
|
22
|
-
|
|
22
|
+
parse("goldenrod")
|
|
23
|
+
|
|
24
|
+
# Manually create colors
|
|
25
|
+
rgb(255, 87, 51, alpha: percentage(50))
|
|
23
26
|
hsl(9, 100, 60)
|
|
24
27
|
oklch(0.65, 0.22, 30)
|
|
25
|
-
parse("rebeccapurple")
|
|
26
|
-
|
|
27
|
-
# Manipulate colors
|
|
28
|
-
color = parse("#ff5733")
|
|
29
|
-
color.lighten(0.1)
|
|
30
|
-
color.darken(0.1)
|
|
31
|
-
color.saturate(0.1)
|
|
32
|
-
color.desaturate(0.1)
|
|
33
|
-
color.rotate(30)
|
|
34
|
-
|
|
35
|
-
# Convert between formats
|
|
36
|
-
color.to_rgb
|
|
37
|
-
color.to_hsl
|
|
38
|
-
color.to_oklch
|
|
39
|
-
color.to_hex
|
|
40
|
-
color.to_css_oklch
|
|
41
28
|
|
|
42
|
-
#
|
|
43
|
-
|
|
29
|
+
# Show a color card
|
|
30
|
+
show("#ff5733")
|
|
44
31
|
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
hsl(9, 100, 60)
|
|
48
|
-
oklch(0.65, 0.22, 30)
|
|
49
|
-
parse("#ff5733")
|
|
50
|
-
gradient(:linear, ["#FF0000", "#0000FF"])
|
|
51
|
-
percentage(50)
|
|
32
|
+
# Make a rainbow
|
|
33
|
+
puts gradient(:linear, %w[red orange yellow green blue purple], direction: "to right").rasterize(width: 60).to_ansi
|
|
52
34
|
RUBY
|
|
53
35
|
|
|
54
36
|
"#{link}\n\n#{code}"
|
|
@@ -85,6 +85,27 @@ module Unmagic
|
|
|
85
85
|
def to_a
|
|
86
86
|
@pixels.flatten
|
|
87
87
|
end
|
|
88
|
+
|
|
89
|
+
# Convert to ANSI escape codes for terminal display.
|
|
90
|
+
#
|
|
91
|
+
# Renders each pixel as a colored character using 24-bit true color
|
|
92
|
+
# ANSI codes. Each row is joined and rows are separated by newlines.
|
|
93
|
+
#
|
|
94
|
+
# @param fill [String] Character to use for each pixel (default: "█")
|
|
95
|
+
# @return [String] ANSI-colored string representation
|
|
96
|
+
#
|
|
97
|
+
# @example Render a rainbow gradient
|
|
98
|
+
# gradient = Gradient.linear(%w[red yellow green blue])
|
|
99
|
+
# bitmap = gradient.rasterize(width: 40)
|
|
100
|
+
# puts bitmap.to_ansi
|
|
101
|
+
#
|
|
102
|
+
# @example Use custom fill character
|
|
103
|
+
# puts bitmap.to_ansi(fill: "▀")
|
|
104
|
+
def to_ansi(fill: "█")
|
|
105
|
+
@pixels.map do |row|
|
|
106
|
+
row.map { |color| "\e[#{color.to_ansi}m#{fill}\e[0m" }.join
|
|
107
|
+
end.join("\n")
|
|
108
|
+
end
|
|
88
109
|
end
|
|
89
110
|
end
|
|
90
111
|
end
|