Commit Graph

59 Commits

Author SHA1 Message Date
4a7b0cc000 Fix mypy checking
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-04 22:05:17 -07:00
88ceb5e2ff Add PNGWriter
* png files are an available output in the CLI
* --svg-square-size is now --square-size
* output type of Writer.write is bytes instead of a string. Just use
  str.decode if string output is needed

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-04 21:58:31 -07:00
1758d477a8 Update js/index.html to include available hash algorithms
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 12:32:52 -07:00
d61da024c9 Run black
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 12:23:08 -07:00
c17326f4e7 Refactor matricizer, fix some linter complaints
* Matricizer.choose_dimensions was not actually being used. It has been
  removed, and dimensions of the hash matrix are now determined
  internally by the matricizer, rather than in its constructor.
* Linter was complaining about missing documentation and some other
  minor styling things so those are fixed
* Linter had a few more stupid lints enabled ("too-many-statements"?
  really? god forbid your code is too long, I'm not a computer science
  student, come on guys)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 12:20:07 -07:00
2b30070851 Remove colorizer.py in reference to the last commit
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 11:49:21 -07:00
ca2aa4ca3b Refactor colorizer
Colorizer was a class-based thing but it doesn't really need to be,
because everything is colorized using palettes. If we need to use a
different style of colorization in the future, we will bring the
colorizer class back.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 11:24:31 -07:00
c416c24a9c Add Javascript implementation
Add a simple JS port of colorhash for easier demonstration purposes. You
don't need to open a command line to create a colorhash, you can just
use the webpage.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 11:16:07 -07:00
6091170ed4 Fix fatal bug in RandomartMatricizer
Big oops on my part. The Randomart was looking a bit "same-y", and for a
good reason. The algorithm should be going in two-bit chunks at a time,
but I completely forgot to shift the bits over every time. This is added
now, huge mistake on my part whoopsie

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-06-03 10:08:36 -07:00
ae288b06df Add git add and ANSI output to gencommit.sh
Usually you want to `git add` when you run gencommit.sh, so that has
been added.

Also, add ANSI output because I like to see what we're generating while
in the terminal.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-31 22:26:39 -07:00
3071725d31 Rename hsl_colors -> hsl_palette
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-31 21:14:37 -07:00
6086f5a46d Fix some mypy typing issues
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-31 10:13:54 -07:00
28eca5e2de Remove StaticPalette class, redefine Palette type
StaticPalette was not really being used besides as a list wrapper, so
that is removed. Palette type is getting some use in the rest of the
codebase, so I have redefined that type as a Sequence[str], becauase
that's basically what it is.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-31 10:10:48 -07:00
7249ab3cff Add license
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-31 09:51:18 -07:00
7990c9ad6a Update README with a new "weaknesses" section and commit hash example
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:44:08 -07:00
2726f2d80f Add tools/gencommit.sh which will only generate the commithash SVG
This is useful so we aren't wasting cycles generating examples that
don't need to be generated and we just cut to the chase

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:35:38 -07:00
19578536aa Update commithash example to use nibbleart instead of randomart
I just like how it looks a little better

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:31:17 -07:00
5b5c2444db Add a new "rainbow-reverse" palette for randomart
This tries to add a bit more color distinction to the randomart
algorithm. As it so happens, half of the randomart examples got
converted to using the new palette, so that's a nice little win.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:27:27 -07:00
43e99e15bb Add png generation back in (using the imagemagick convert tool), add png files to gitignore
This is so we aren't committing binary data to the git repository if
that data may get updated in the future because I decide to make changes
to algorithms, palettes, etc. It's still nice to get the png files
generated so they can stay.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:26:08 -07:00
87af541cc4 Remove fullsource and use the current (previous) commit hash instead
Regenerating the fullsource hash was a bit tedious. Instead, it makes a
bit more sense to use the current commit hash as the header image. This
uses sha1 nibbleart.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:22:58 -07:00
2182997ab8 Last README.md tweak for now, I prommy
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:08:22 -07:00
9b6ede3c6f More README.md fiddling
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:07:50 -07:00
dafbda5e12 Fiddle with the README some more
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:06:49 -07:00
1600c9874a Add fullsource.in, update fullsource examples
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:04:57 -07:00
9088920008 Update some TODOs
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:04:04 -07:00
c0ebb960da Re-arrange motivation section of the README
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 12:03:31 -07:00
a28a39a63f Comment out PNG generation in tools/genexamples.sh
We don't reeeeaaaaally need PNG files for this, plus if we include PNGs
it will make the repository unwieldy and annoying.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:55:54 -07:00
8e18d623f1 Update README to include SVG of the full source
I think it looks cool and it's a good way to show off the tool.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:52:11 -07:00
30ed7ce21e Update SVG examples since a few things (dimensions, palette selection) have changed
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:51:47 -07:00
782c1fc8d1 Add full source code to example generation
This will just do a `cat` of all Python files in the colorhash/
directory and shove it into a fullsource.in file.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:49:42 -07:00
eeb51ce510 Update README to show example of ANSI vs SVG output
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:44:00 -07:00
ad014b4ea4 Add ANSI color output, set that as the default
ANSI-based color output is available and now the default. Add a
-y / --output-type argument to select SVG or ANSI output. Also update
tools/genexamples.sh to use the SVG output type.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:38:33 -07:00
1def2fa7bf Update colors to be expressed explicitly as RGB or HSL
Generally, palettes are expressed using HSL, but sometimes we want the
output to be in RGB (or some other format). Colors are now expressed
using either RGBColor or HSLColor and can easily be converted between
the two.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 11:02:11 -07:00
ee16b14c73 Fix some mypy type errors in cli.py
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 10:57:39 -07:00
5fc595278c Fix a mypy error with matricizer.py
Self type is not allowed to access static members, in this case
DIMENSIONS

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 10:48:45 -07:00
2d0537e0d6 Add initial README
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-30 09:25:28 -07:00
54993bc63b Update TODOs in cli.py
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-26 19:43:03 -07:00
f1a64e2354 Move CLI implementation to its own file and out of __main__
CLI implementation will now live in colorhash/cli.py, and __main__ will
just import and call the cli_main() function.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-26 19:30:50 -07:00
6aed63c069 Add Matricizer.choose_dimensions
Matrices can choose their dimensions based on hash algorithm

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 22:54:53 -07:00
9298d72c17 Split up palettes into multicolor/gradient
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 22:30:42 -07:00
0baf1f7688 Palettes are selected by matricizer
Matricizers select color palettes now. This is motivated by the fact
that the gradient palettes don't really look good for openssh randomart
based art, and rainbows do look good.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 22:18:50 -07:00
6c370237ea Remove yellow-light palette. Doesn't look good.
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 21:41:39 -07:00
426c9580a7 Update palettes to use HSL coloring
Introduce a new function called `hsl_colors` and a helper `quantize`
function that creates palettes using HSL values on the fly. Default
palettes are now split into "<colorname>-dark" and "<colorname>-light"
for more variation.

In my experiments, red-centric colors seem to be more distinguishable
than others. You have red, green, blue - you can tell they're distinct.
Interleaved between these you have yellow, cyan, and magenta, also
distinct. But between yellow and green, or green and cyan, these colors
feel less distinct than orange, purple or pink. I have opted to elide
non-red "in-betweens" such as those. So we have a dark and light variant
of the following colors as palettes:

red, orange, yellow, green, cyan, blue, purple, magenta, pink, gray, and
also a rainbow palette that is every color at its full saturation.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 17:39:33 -07:00
d5bd09072a Fix a few things in __main__.py
* Palette choices are determined by the list of palettes available and
  not hard-coded
* Auto palette is chosen by the length of the palette choices rather
  than hard-coded
* Palette help listing is text-wrapped at 70 characters

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 17:37:46 -07:00
1277c2db8b Add input-type
Input can now either be a path, raw data, or a hash itself (path is
default)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 11:45:42 -07:00
e14c796888 Split out color palettes to their own file
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-24 11:45:23 -07:00
909306cd0c Remove old .svgs from the examples
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-23 11:17:03 -07:00
660a0cb60c Add .pylintrc and some documentation + fixes to shut pylint up.
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-22 12:05:20 -07:00
840e878748 Fix types for mypy
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-22 11:15:43 -07:00
2cc9ea319b Add dummy __init__.py for package use
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2024-05-22 11:08:02 -07:00