ComputerCraft Forums

ComputerCraft => Programs => APIs and Utilities => Topic started by: HydroNitrogen on Aug 23, 2018, 01:43 PM

Title: palCollection - palette collection library
Post by: HydroNitrogen on Aug 23, 2018, 01:43 PM
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 (https://github.com/Wendelstein7/palCollection-CC). 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. (https://forums.computercraft.cc/index.php?topic=60.new#new)

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.


(https://camo.tmpim.com/2ecae3305b6969d32814486fe9ba926e533d222e/68747470733a2f2f6d656469612e7468696a6d656e2e78797a2f3346553834742e6a7067)

You can view a more accecible version of the palette table here. (https://wiki.computercraft.cc/User:HydroNitrogen/palCollection)


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:



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
(https://camo.tmpim.com/0d23ce14b705dd48454e0eba7aaeb1ad4db6e30d/68747470733a2f2f6d656469612e7468696a6d656e2e78797a2f50784772612e676966)


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 (https://raw.githubusercontent.com/Wendelstein7/palCollection-CC/master/palCollection.lua).
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.
Title: palCollection - palette collection library
Post by: pjals on Jul 05, 2020, 10:20 AM
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*