palCollection - palette collection library

Started by HydroNitrogen, Aug 23, 2018, 01:43 PM

Previous topic - Next topic

HydroNitrogen

About

palCollection (Palette Collection) is a simple but powerful library that aims to be easy to use and can be implemented by other software.
palCollection brings new, popular, historic and beautiful palettes that have been seen in the real world in all kind of places to ComputerCraft.


Downloading

palCollection is available on GitHub here. You can check out its repo, or download the library file directly by executing the following in your terminal:

wget https://raw.githubusercontent.com/Wendelstein7/palCollection-CC/master/palCollection.lua palCollection.lua

Dependency

palCollection requires my other library palPal to function!
Please see this forum post to inquire more information about working with palPal.

Alternatively, you can just download palPal directly by executing the following in your terminal:

wget https://raw.githubusercontent.com/Wendelstein7/palPal-CC/master/palPal.lua palPal.lua

Palettes

palCollection currently has 5 palettes.

  • default from Dan200/ComputerCraft The default palette that ComputerCraft has been using for years. Really old, and pretty ugly, yet a little nostalgic.
  • greyshades from HydroNitrogen A linear colour gradient starting from black (0) to white (1) in 16 steps.
  • zxspectrum from https://en.wikipedia.org/wiki/ZX_Spectrum_graphic_modes#Color_palette The ZX Spectrum (and compatibles) computers uses a variation of the 4-bit RGBI palette philosophy. This results in each of the colors of the 3-bit palette having a basic and bright variant, with the exception of black. The bright half of the palette is generated using the video display's maximum voltage levels for each of the three R/G/B color components that a color uses. The basic half of the palette is displayed by simply reducing these voltages.
  • solarized from https://ethanschoonover.com/solarized/ Solarized is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several unique properties. I designed this colorscheme with both precise CIELAB lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions.
  • onedark from https://github.com/ch1bo/bright-colors A modified version of the dark Vim/Neovim color scheme for the GUI and 16/256/true-color terminals, based on FlatColor, with colors inspired by the excellent One Dark syntax theme.



You can view a more accecible version of the palette table here.


Documentation

palCollection has a particular layout of variables. To harness palCollection's power, we must first load it into our environment by doing the following:

local palCollection = require("palCollection")
Now we can access palCollection's
Collections:

-- palette tables (to be passed to palPal to load palettes)
 palCollection.palettes.<palette>
-- for example:
 palCollection.palettes.solarized -- returns palette table { ... }

 -- palette colours (to be used as friendly names for referring in for example .setTextColour)
 palCollection.colours.<palette>.<colour>
 -- for example:
 palCollection.colours.solarized.violet -- returns number 4096

 -- palette sources (where the palette colour data originated from)
 palCollection.sources.<palette>
 -- for example:
 palCollection.sources.solarized -- returns string "https://ethanschoonover.com/solarized/"

 -- note: en-us users can replace colour with color, but not grey with gray.
Reference:

  • [icode]<palette>[/icode] refers to the name of a palette here, for example [icode]solarized[/icode] or [icode]default[/icode].
  • [icode]<colour>[/icode] refers to the name of a colour here, for example [icode]violet[/icode] (in solarized) or [icode]darkerWhite[/icode] (in greyshades).


Example

palCollection's simpleness can be demonstrated using the following brief example to show the concept of loading a diffrent palette in and then drawing al it's colours.

-- First we load palCollection and palPal into our environment
 local palPal = require("palPal")
 local palCollection = require("palCollection")

 -- Then we give 16 rows in the terminal unique background colours.
 local c, y = 1, 1
 repeat
  term.setBackgroundColour(c)
  term.setCursorPos(1, y)
  term.clearLine()
  c = c * 2; y = y + 1
 until c > 32768

 -- Now we loop trough all diffrent palettes
 for name, palette in pairs(palCollection.palettes) do
  -- We load the palette into the term using palPal
  palPal.loadPalette(term, palette)
  -- And we wait for the user to press a key to continue to the next colour
  os.pullEvent("key")
 end

 -- Then we restore the default palette again
 palPal.loadPalette(term, palCollection.palettes.default)

 -- Finally we clean up the terminal
 term.clear()
 term.setCursorPos(1,1)
 term.write("Thanks for viewing the palCollection demo!")

Executing the example will result in a slideshow of all palettes, trough which the user must continue by pressing keys.
Spoiler


Licence

palCollection is licenced under the MIT licence, Copyright (c) 2018 Wendelstein7 (a.k.a. HydroNitrogen)

You can definetely use this in your programs, I really recommend everyone doing so! You should make your programs that require it download the library from the raw GitHub link.
You are allowed to distribute this library yourself along with your other software that requires it (giving proper credit), but I strongly recommend downloading it from GitHub dynamically.
Please do collaborate on the ComputerCraft Wiki! Thanks!
Also like my post if you found it informative or helpful. This gets me to know what I should do more of. Thanks again!

pjals

Quote from: HydroNitrogen on Aug 23, 2018, 01:43 PMExecuting the example will result in a slideshow of all palettes, trough which the user must continue by pressing keys.
through*
hi i am T79, bye