Last active
October 18, 2018 20:58
-
-
Save tcyrus/48a688790c525c33abd7 to your computer and use it in GitHub Desktop.
My new avatar generator, uses my GPG signature to make a unique image, Now in an iPython Notebook
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from random import randint\n", | |
"from IPython.display import JSON, SVG" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"S = \"6B825BEB42CD4F73E2A989AF72B609A7A884EA8B\"\n", | |
"T = \"TCYRUS\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"M = [\n", | |
" [S[0],T[0],T[1],T[2],T[3],T[4],T[5],S[1]],\n", | |
" [T[0],S[2],S[3],S[4],S[5],S[6],S[7],T[5]],\n", | |
" [T[1],S[8],S[9],S[10],S[11],S[12],S[13],T[4]],\n", | |
" [T[2],S[14],S[15],S[16],S[17],S[18],S[19],T[3]],\n", | |
" [T[3],S[20],S[21],S[22],S[23],S[24],S[25],T[2]],\n", | |
" [T[4],S[26],S[27],S[28],S[29],S[30],S[31],T[1]],\n", | |
" [T[5],S[32],S[33],S[34],S[35],S[36],S[37],T[0]],\n", | |
" [S[38],T[5],T[4],T[3],T[2],T[1],T[0],S[39]]\n", | |
"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"D = {}\n", | |
"colors = set()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def randcol():\n", | |
" return '#%02X%02X%02X' % (randint(0, 255), randint(0, 255), randint(0, 255))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"svg = \"<svg>\"\n", | |
"\n", | |
"for r, R in enumerate(M):\n", | |
" for x, X in enumerate(R):\n", | |
" if not X in D:\n", | |
" color = randcol()\n", | |
" while color in colors:\n", | |
" color = randcol()\n", | |
" D[X] = color\n", | |
" colors.add(color)\n", | |
" else:\n", | |
" color = D[X]\n", | |
" svg += \"<rect x='{}' y='{}' width='15' height='15' style='fill:{}' />\".format(str(15*x), str(15*r), color)\n", | |
"\n", | |
"svg += \"</svg>\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'6': '#5DD83A', 'T': '#C65997', 'C': '#33F5F6', 'Y': '#098F99', 'R': '#3BADFF', 'U': '#272B50', 'S': '#74A5E7', 'B': '#2BFBF7', '8': '#4F3254', '2': '#D2C723', '5': '#3B5B3A', 'E': '#ED6317', '4': '#EFC130', 'D': '#1BA955', 'F': '#F73C42', '7': '#07F7FA', '3': '#99D9EA', 'A': '#0605B1', '9': '#0527E3', '0': '#A852C3'}\n" | |
] | |
} | |
], | |
"source": [ | |
"#JSON(D)\n", | |
"print(D)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": [ | |
"<svg><rect height=\"15\" style=\"fill:#5DD83A\" width=\"15\" x=\"0\" y=\"0\"/><rect height=\"15\" style=\"fill:#C65997\" width=\"15\" x=\"15\" y=\"0\"/><rect height=\"15\" style=\"fill:#33F5F6\" width=\"15\" x=\"30\" y=\"0\"/><rect height=\"15\" style=\"fill:#098F99\" width=\"15\" x=\"45\" y=\"0\"/><rect height=\"15\" style=\"fill:#3BADFF\" width=\"15\" x=\"60\" y=\"0\"/><rect height=\"15\" style=\"fill:#272B50\" width=\"15\" x=\"75\" y=\"0\"/><rect height=\"15\" style=\"fill:#74A5E7\" width=\"15\" x=\"90\" y=\"0\"/><rect height=\"15\" style=\"fill:#2BFBF7\" width=\"15\" x=\"105\" y=\"0\"/><rect height=\"15\" style=\"fill:#C65997\" width=\"15\" x=\"0\" y=\"15\"/><rect height=\"15\" style=\"fill:#4F3254\" width=\"15\" x=\"15\" y=\"15\"/><rect height=\"15\" style=\"fill:#D2C723\" width=\"15\" x=\"30\" y=\"15\"/><rect height=\"15\" style=\"fill:#3B5B3A\" width=\"15\" x=\"45\" y=\"15\"/><rect height=\"15\" style=\"fill:#2BFBF7\" width=\"15\" x=\"60\" y=\"15\"/><rect height=\"15\" style=\"fill:#ED6317\" width=\"15\" x=\"75\" y=\"15\"/><rect height=\"15\" style=\"fill:#2BFBF7\" width=\"15\" x=\"90\" y=\"15\"/><rect height=\"15\" style=\"fill:#74A5E7\" width=\"15\" x=\"105\" y=\"15\"/><rect height=\"15\" style=\"fill:#33F5F6\" width=\"15\" x=\"0\" y=\"30\"/><rect height=\"15\" style=\"fill:#EFC130\" width=\"15\" x=\"15\" y=\"30\"/><rect height=\"15\" style=\"fill:#D2C723\" width=\"15\" x=\"30\" y=\"30\"/><rect height=\"15\" style=\"fill:#33F5F6\" width=\"15\" x=\"45\" y=\"30\"/><rect height=\"15\" style=\"fill:#1BA955\" width=\"15\" x=\"60\" y=\"30\"/><rect height=\"15\" style=\"fill:#EFC130\" width=\"15\" x=\"75\" y=\"30\"/><rect height=\"15\" style=\"fill:#F73C42\" width=\"15\" x=\"90\" y=\"30\"/><rect height=\"15\" style=\"fill:#272B50\" width=\"15\" x=\"105\" y=\"30\"/><rect height=\"15\" style=\"fill:#098F99\" width=\"15\" x=\"0\" y=\"45\"/><rect height=\"15\" style=\"fill:#07F7FA\" width=\"15\" x=\"15\" y=\"45\"/><rect height=\"15\" style=\"fill:#99D9EA\" width=\"15\" x=\"30\" y=\"45\"/><rect height=\"15\" style=\"fill:#ED6317\" width=\"15\" x=\"45\" y=\"45\"/><rect height=\"15\" style=\"fill:#D2C723\" width=\"15\" x=\"60\" y=\"45\"/><rect height=\"15\" style=\"fill:#0605B1\" width=\"15\" x=\"75\" y=\"45\"/><rect height=\"15\" style=\"fill:#0527E3\" width=\"15\" x=\"90\" y=\"45\"/><rect height=\"15\" style=\"fill:#3BADFF\" width=\"15\" x=\"105\" y=\"45\"/><rect height=\"15\" style=\"fill:#3BADFF\" width=\"15\" x=\"0\" y=\"60\"/><rect height=\"15\" style=\"fill:#4F3254\" width=\"15\" x=\"15\" y=\"60\"/><rect height=\"15\" style=\"fill:#0527E3\" width=\"15\" x=\"30\" y=\"60\"/><rect height=\"15\" style=\"fill:#0605B1\" width=\"15\" x=\"45\" y=\"60\"/><rect height=\"15\" style=\"fill:#F73C42\" width=\"15\" x=\"60\" y=\"60\"/><rect height=\"15\" style=\"fill:#07F7FA\" width=\"15\" x=\"75\" y=\"60\"/><rect height=\"15\" style=\"fill:#D2C723\" width=\"15\" x=\"90\" y=\"60\"/><rect height=\"15\" style=\"fill:#098F99\" width=\"15\" x=\"105\" y=\"60\"/><rect height=\"15\" style=\"fill:#272B50\" width=\"15\" x=\"0\" y=\"75\"/><rect height=\"15\" style=\"fill:#2BFBF7\" width=\"15\" x=\"15\" y=\"75\"/><rect height=\"15\" style=\"fill:#5DD83A\" width=\"15\" x=\"30\" y=\"75\"/><rect height=\"15\" style=\"fill:#A852C3\" width=\"15\" x=\"45\" y=\"75\"/><rect height=\"15\" style=\"fill:#0527E3\" width=\"15\" x=\"60\" y=\"75\"/><rect height=\"15\" style=\"fill:#0605B1\" width=\"15\" x=\"75\" y=\"75\"/><rect height=\"15\" style=\"fill:#07F7FA\" width=\"15\" x=\"90\" y=\"75\"/><rect height=\"15\" style=\"fill:#33F5F6\" width=\"15\" x=\"105\" y=\"75\"/><rect height=\"15\" style=\"fill:#74A5E7\" width=\"15\" x=\"0\" y=\"90\"/><rect height=\"15\" style=\"fill:#0605B1\" width=\"15\" x=\"15\" y=\"90\"/><rect height=\"15\" style=\"fill:#4F3254\" width=\"15\" x=\"30\" y=\"90\"/><rect height=\"15\" style=\"fill:#4F3254\" width=\"15\" x=\"45\" y=\"90\"/><rect height=\"15\" style=\"fill:#EFC130\" width=\"15\" x=\"60\" y=\"90\"/><rect height=\"15\" style=\"fill:#ED6317\" width=\"15\" x=\"75\" y=\"90\"/><rect height=\"15\" style=\"fill:#0605B1\" width=\"15\" x=\"90\" y=\"90\"/><rect height=\"15\" style=\"fill:#C65997\" width=\"15\" x=\"105\" y=\"90\"/><rect height=\"15\" style=\"fill:#4F3254\" width=\"15\" x=\"0\" y=\"105\"/><rect height=\"15\" style=\"fill:#74A5E7\" width=\"15\" x=\"15\" y=\"105\"/><rect height=\"15\" style=\"fill:#272B50\" width=\"15\" x=\"30\" y=\"105\"/><rect height=\"15\" style=\"fill:#3BADFF\" width=\"15\" x=\"45\" y=\"105\"/><rect height=\"15\" style=\"fill:#098F99\" width=\"15\" x=\"60\" y=\"105\"/><rect height=\"15\" style=\"fill:#33F5F6\" width=\"15\" x=\"75\" y=\"105\"/><rect height=\"15\" style=\"fill:#C65997\" width=\"15\" x=\"90\" y=\"105\"/><rect height=\"15\" style=\"fill:#2BFBF7\" width=\"15\" x=\"105\" y=\"105\"/></svg>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.SVG object>" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"SVG(svg)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment