-
Notifications
You must be signed in to change notification settings - Fork 9
Addressing color palette issue in issue #34 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/env ruby | ||
|
||
$LOAD_PATH << "#{__dir__}/../lib" | ||
require "unicode_plot" | ||
|
||
# | ||
# Example of using the 256 color pallette | ||
# | ||
|
||
# dummy plot-line to set canvas | ||
plt = UnicodePlot.lineplot([0,0],[0,0], title: "256-color", color: 0, | ||
xlim: [0,31], ylim: [0,31], | ||
width: 33, height: 32, canvas: :braille) | ||
# sweep some colored lines using 256 color palette | ||
(0..255).each do |colornum| | ||
x1 = (colornum / 32).floor * 4 | ||
x2 = x1 + 3 | ||
y = colornum % 32 | ||
UnicodePlot.lineplot!(plt, [x1, x2],[y, y], color: colornum) | ||
end | ||
plt.render | ||
|
||
# | ||
# Example of using standard 8-color pallete with line-plots and named colors | ||
# When lines cross over each other, some 'mixing' effect happens that will | ||
# blend colors by OR'ing their value. | ||
# | ||
# Noting that 16-color cannot be accessed with line-plot, as | ||
# the ':light_*' colors and ':black' are not accepted. | ||
|
||
colorlist = %i[ normal red green yellow blue magenta cyan white ] | ||
plt = UnicodePlot.lineplot([0,0],[0,0], title: "8-color-mixing", color: 0, | ||
xlim: [0,15], ylim: [0,15], | ||
width: 33, height: 16, canvas: :braille) | ||
colorlist.each_with_index do |color, y| | ||
UnicodePlot.lineplot!(plt, [0, 15],[y*2, y*2], color: color) | ||
UnicodePlot.lineplot!(plt, [y*2, y*2],[0, 15], color: color) | ||
end | ||
plt.render |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ def pixel!(pixel_x, pixel_y, color) | |
index = index_at(char_x - 1, char_y - 1) | ||
if index | ||
@grid[index] = (@grid[index].ord | BRAILLE_SIGNS[char_x_off - 1][char_y_off - 1]).chr(Encoding::UTF_8) | ||
@colors[index] |= COLOR_ENCODE[color] | ||
@colors[index] |= COLOR_ENCODE.fetch(color, color) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that if color is a symbol (e.g. |
||
end | ||
color | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example script to show usage of 256-color palette and 8-color (with mixing).