Created
April 9, 2015 02:33
-
-
Save YusukeIwaki/3c10c9e2e36e92d5bcc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from Tkinter import Tk, Canvas, Frame, BOTH | |
import colorsys | |
def hex2rgb(hexColor): | |
r = (0x00ff0000 & hexColor) >> 16 | |
g = (0x0000ff00 & hexColor) >> 8 | |
b = (0x000000ff & hexColor) | |
return r,g,b | |
def rgb2hex(r,g,b): | |
hexColor=(b & 0xff) | |
hexColor+=((g & 0xff) << 8) | |
hexColor+=((r & 0xff) << 16) | |
return hexColor | |
def _a(a_str): | |
a=a_str.strip().split() | |
for line in a: | |
cap=line.split("#")[0] | |
rgb = int("0x"+line.split("#")[1],16) | |
print cap,colorsys.rgb_to_hsv(*hex2rgb(rgb)) | |
_a("""50#FFFDE7 | |
100#FFF9C4 | |
200#FFF59D | |
300#FFF176 | |
400#FFEE58 | |
500#FFEB3B | |
600#FDD835 | |
700#FBC02D | |
800#F9A825 | |
900#F57F17""") | |
_a("""50#FFF8E1 | |
100#FFECB3 | |
200#FFE082 | |
300#FFD54F | |
400#FFCA28 | |
500#FFC107 | |
600#FFB300 | |
700#FFA000 | |
800#FF8F00 | |
900#FF6F00""") | |
_a("""50#E8F5E9 | |
100#C8E6C9 | |
200#A5D6A7 | |
300#81C784 | |
400#66BB6A | |
500#4CAF50 | |
600#43A047 | |
700#388E3C | |
800#2E7D32 | |
900#1B5E20""") | |
def gen(basecolorRGB): | |
r,g,b = hex2rgb(basecolorRGB) | |
col2=rgb2hex(g,b,r) | |
col3=rgb2hex(b,r,g) | |
return zip([basecolorRGB, col2, col3,basecolorRGB, col2, col3,basecolorRGB, col2, col3,basecolorRGB, col2, col3,basecolorRGB], range(13)) | |
class Example(Frame): | |
def __init__(self, parent,basecolor,size): | |
Frame.__init__(self, parent) | |
self.parent = parent | |
self.basecolors = gen(basecolor) | |
self.size=size | |
self.initUI() | |
def initUI(self): | |
self.parent.title("Material Design") | |
self.pack(fill=BOTH, expand=1) | |
canvas = Canvas(self) | |
unit=self.size[1]/len(self.basecolors) | |
for i,basecolor in enumerate(self.basecolors): | |
color,caption = basecolor | |
canvas.create_rectangle(0, unit*i, self.size[0], unit*(i+1), fill="#"+hex(color)[2:]) | |
canvas.create_text(self.size[0]/2, unit*(2*i+1)/2, text=caption, justify="center") | |
canvas.pack(fill=BOTH, expand=1) | |
def main(): | |
root = Tk() | |
size=(200,650) | |
ex = Example(root,0x2473C5,size) | |
root.minsize(*size) | |
root.maxsize(*size) | |
root.mainloop() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment