Mercurial > hg > tilerswift
view colours.py @ 113:ef1a879802ad
TILE_PALETTES: add a few more standard palettes
This almost gives enough standard palettes to pick a few at first.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 19 Sep 2019 17:16:21 -0400 |
parents | 822e2fb5197c |
children |
line wrap: on
line source
from PyQt5 import QtGui as QG, QtCore as QC NES_PALETTE = [ "#7C7C7C", # 00 "#0000FC", # 01 "#0000BC", # 02 "#4428BC", # 03 "#940084", # 04 "#A80020", # 05 "#A81000", # 06 "#881400", # 07 "#503000", # 08 "#007800", # 09 "#006800", # 0A "#005800", # 0B "#004058", # 0C "#000000", # 0D "#000000", # 0E "#000000", # 0F "#BCBCBC", # 10 "#0078F8", # 11 "#0058F8", # 12 "#6844FC", # 13 "#D800CC", # 14 "#E40058", # 15 "#F83800", # 16 "#E45C10", # 17 "#AC7C00", # 18 "#00B800", # 19 "#00A800", # 1A "#00A844", # 1B "#008888", # 1C "#000000", # 1D "#000000", # 1E "#000000", # 1F "#F8F8F8", # 20 "#3CBCFC", # 21 "#6888FC", # 22 "#9878F8", # 23 "#F878F8", # 24 "#F85898", # 25 "#F87858", # 26 "#FCA044", # 27 "#F8B800", # 28 "#B8F818", # 29 "#58D854", # 2A "#58F898", # 2B "#00E8D8", # 2C "#787878", # 2D "#000000", # 2E "#000000", # 2F "#FCFCFC", # 30 "#A4E4FC", # 31 "#B8B8F8", # 32 "#D8B8F8", # 33 "#F8B8F8", # 34 "#F8A4C0", # 35 "#F0D0B0", # 36 "#FCE0A8", # 37 "#F8D878", # 38 "#D8F878", # 39 "#B8F8B8", # 3A "#B8F8D8", # 3B "#00FCFC", # 3C "#F8D8F8", # 3D "#000000", # 3E "#000000", # 3F ] QT_NES_PALETTE = [QG.QColor(color).rgb() for color in NES_PALETTE] TILE_PALETTES = { "Primary": [0x20, 0x16, 0x19, 0x01], "Megaman": [0x20, 0x0f, 0x21, 0x01], "Mario": [0x20, 0x16, 0x36, 0x07], "Luigi": [0x0f, 0x30, 0x37, 0x19], "Link": [0x20, 0x29, 0x37, 0x28], "Simon": [0x0f, 0x28, 0x37, 0x07], "White Mage": [0x0f, 0x16, 0x30, 0x37], "Black Mage": [0x0f, 0x28, 0x08, 0x01], } def is_dark(qt_colour): r, g, b = qt_colour.red(), qt_colour.green(), qt_colour.blue() luminance = (0.2126*r + 0.7152*g + 0.0722*b)/256 return luminance < 0.5 def widget_icon_path(widget): return "darkside" if is_dark(widget.palette().color(QG.QPalette.Background)) else "lightside" def palette_to_qt(palette): return [ QG.QColor(0, 0, 0, 0).rgba() if color_idx is None else QG.QColor(NES_PALETTE[color_idx]).rgb() for color_idx in palette ] def palette_to_pixmap(palette): pixmap = QG.QPixmap(QC.QSize(80, 20)) painter = QG.QPainter(pixmap) palette = [QG.QColor(NES_PALETTE[colour_idx]) for colour_idx in palette] for idx, colour in enumerate(palette): painter.setPen(colour) brush = QG.QBrush() brush.setColor(colour) brush.setStyle(QC.Qt.SolidPattern) painter.setBrush(brush) painter.drawRect(idx*20, 0, idx*20 + 19, 19) return pixmap