彩色处理机

colp的Python项目详细描述


COLP

Python versionsPRs welcomeBuild StatusCoverage StatusPyPI

彩色处理器

目标

该工具的灵感来源于各种处理工具,如awk、sed和imagemagick。没有用于单色操作的处理库,无论是否交互。 colp试图解决这个问题。它支持许多颜色模型(在本自述文件后面指定)。目标是有能力脚本和自动化任何算法的颜色转换。

安装

pip install colp

示例用法

交互式操作颜色
$ colp 'a=RGB(1,1,1)' # optionally load a color to memory

┌─┐┌─┐┬  ┬─┐
│  │ ││  │─┘
└─┘┘─┘┆─┘┆   the color processor

> a = a.redder()                  # single channel increment
> a
RGB(2, 1, 1)
> a = a + 1                       # all channels increment
> a
RGB(3, 2, 2)
> lightgoldenrodyellow            # X11/HTML constants
RGB(250, 250, 210)
> -a                              # inversion 
RGB(252, 253, 253)
> red.rotate(180) == -red == cyan # rotate hue in HSV space
True
> skyblue ; skyblue.brighter()    # brighter in HSV space
RGB(135, 206, 235)
RGB(136, 208, 237)

> a_set_of_colors = [RGB(25,25,112), HSV(186,23,90), plum, orchid, fuchsia, HEX('#800080')]
> sorted(a_set_of_colors)
[RGB(25, 25, 112), HEX('#800080'), RGB(218, 112, 214), RGB(221, 160, 221), HSV(186, 23, 90), HEX('#ff00ff')]
>
> cursor = RGB(0,0,0)             # define your own custom functions
> def pop_and_turn(x):
>       if x: # equivalent to RGB(0,0,0) == 0
>             x = x.redder() * 255
>       return x.rotate(30)
> 
> for i in range(10):
>       cursor = pop_and_turn(cursor)
>       print(cursor)
>
RGB(255, 0, 127)
RGB(255, 0, 0)
RGB(255, 127, 0)
RGB(255, 255, 0)
RGB(127, 255, 0)
RGB(0, 255, 0)
RGB(0, 255, 127)
RGB(0, 255, 255)
RGB(0, 127, 255)
RGB(0, 0, 255)
> red.interpolate(blue, 10)       # interpolate between colors
[HEX('#ff0000'), HEX('#e50019'), HEX('#cc0033'), HEX('#b2004c'), HEX('#990066'), HEX('#7f007f'), HEX('#660099'), HEX('#4c00b2'), HEX('#3300cc'), HEX('#1900e5'), HEX('#0000ff')]

或管道命令
$ echo "HEX('#ff0000').rotate(15.).to(RGB)" | colp

RGB(255, 63, 0)

来自python脚本的用法
from colp import *
print(RGB(1,2,3).to(HEX))

输出:

HEX('#010203')

类层次结构

Color
├── RGB
│   ├── HEX
│   └── CMYK
├── YIQ
│   ├── YUV 
│   ├── YPbPr
│   ├── YDbDr
│   └── YCbCr
│       └── xvYCC
├── CIE
│   ├── CIELAB
│   ├── CIELCh
│   ├── CIEUVW
│   └── CIEXYZ
└── HSV = HSD = HSB = HSI
    └── HSL

形式参数

usage: colp [-h] [-n] [-v] [-c] [-s] [-l SCRIPT_FILE] [VAR [VAR ...]]

Color Processor

positional arguments:
  VAR                   arbitrary python code execution

optional arguments:
  -h, --help            show this help message and exit
  -n, --no-banner       don't show banner on interactive mode
  -v, --visualizer      visualize current color processed
  -c, --css-mode        css-compliant output
  -s, --scripting-mode  colp script output, which can be reinterpreted by colp
  -l SCRIPT_FILE, --load-script SCRIPT_FILE
                        load script from file or stdin

基本颜色运算符

^{}^{}^{}^{}
^{}^{}^{}^{}
^{}^{}^{}^{}
^{}^{}^{}^{}
^{}^{}^{}^{}

命名常数(140)

良好的资源

支持的颜色模型

✓ RGB/RGBA/HEX:✓ HSV=HSB=HSI=HSD:
drawingdrawing
HSL:CMY[K]:
drawingdrawing
[CIE]LAB:YCbCr:
drawingdrawing
YIQ:YUV:
drawingdrawing

贡献

还有许多其他有用的颜色空间可以转换,本自述中只列出了一些。 要覆盖一个新的颜色空间,只需添加一个扩展Color的类,或者更好的是添加一个Color子类。 当然,css文件编辑也有一定的自动化空间。

欢迎拉取请求!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java中最小长度的字数计算   java事务处理JavaEE 6   java如何进行5分钟刷新并检查txt是否被修改?   java可以同时拖动多个对象   变量长、双精度、字节、字符在Java中的用途是什么?   spring将XMLBean配置转换为java配置   java检测不可靠网络上的TCP丢失   Java:TCP加密、SSL和Netty   在java中,如何使用isAssignableFrom的映射避免多个if-else   在J2EE动态Web项目中找不到java CSS文件   java遍历领域查询到RealmList   安卓阅读网站内容Java   java如何修改/自定义/反编译Opera mini jar文件?   java死锁播放框架如何使用控制器中的参数检查@RestrictedResource?   java在MS Excel中导入xml文件我们如何使用Python或任何其他编程语言自动化此流程?   java如何暂停正在运行的线程并在需要时重新启动同一线程?