Skip to content

Instantly share code, notes, and snippets.

@haideralipunjabi
Last active November 4, 2018 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haideralipunjabi/b072aa4a8e28a78392e7e83b18575d2b to your computer and use it in GitHub Desktop.
Save haideralipunjabi/b072aa4a8e28a78392e7e83b18575d2b to your computer and use it in GitHub Desktop.
A small python script used to generate Atom Icons inspired from Flags of different countries.

Atom Flag Icons Generator

A small python script used to generate Atom Icons inspired from Flags of different countries.
Check out the atom-icons project for these and other such icons for Atom

You can find the flagColors.json file here

import json
import os
json_data = open('flagColors.json')
data = json.load(json_data)
configs = []
if not os.path.exists('svg'):
os.makedirs('svg')
for flag in data:
colors = flag['colors']
count = 0
for color in colors:
if color['percent'] > 2:
count += 1
if count >= 3:
if round(colors[0]['percent']) == round(colors[1]['percent']) == round(colors[2]['percent']):
configs.extend([
{'name': flag['name']+"-1", 'colors': [colors[0]['hex'],colors[1]['hex'],colors[2]['hex']]},
{'name': flag['name']+"-2", 'colors': [colors[1]['hex'],colors[2]['hex'],colors[0]['hex']]},
{'name': flag['name']+"-3", 'colors': [colors[2]['hex'],colors[0]['hex'],colors[1]['hex']]},
])
elif round(colors[0]['percent']) == round(colors[1]['percent']):
configs.extend([
{'name': flag['name']+"-1", 'colors': [colors[0]['hex'],colors[1]['hex'],colors[2]['hex']]},
{'name': flag['name']+"-2", 'colors': [colors[1]['hex'],colors[0]['hex'],colors[2]['hex']]}
])
else:
configs.append(
{'name': flag['name'], 'colors': [colors[0]['hex'],colors[1]['hex'],colors[2]['hex']]}
)
else:
if round(colors[0]['percent']) == round(colors[1]['percent']):
configs.extend([
{'name': flag['name']+"-1", 'colors': [colors[0]['hex'],colors[0]['hex'],colors[1]['hex']]},
{'name': flag['name']+"-2", 'colors': [colors[0]['hex'],colors[1]['hex'],colors[1]['hex']]},
{'name': flag['name']+"-3", 'colors': [colors[1]['hex'],colors[0]['hex'],colors[0]['hex']]},
{'name': flag['name']+"-4", 'colors': [colors[1]['hex'],colors[1]['hex'],colors[0]['hex']]}
])
else:
configs.append(
{'name': flag['name'], 'colors': [colors[0]['hex'],colors[1]['hex'],colors[1]['hex']]}
)
for config in configs:
src = open('icon.svg').read()
src = src.replace('color_1', config['colors'][0])
src = src.replace('color_2', config['colors'][1])
src = src.replace('color_3', config['colors'][2])
f = open("svg/"+"flag_"+config['name'].replace(" ", '-') + '.svg','w')
f.write(src)
f.close()
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<g id="Outer_Circle">
<circle fill="color_2" cx="256" cy="256" r="256"/>
</g>
<g id="Inner_Circle">
<path fill="color_1" d="M488.035,254.309c0,128.453-104.146,232.599-232.602,232.599c-128.456,0-232.599-104.146-232.599-232.599
c0-128.456,104.143-232.599,232.599-232.599C383.89,21.709,488.035,125.853,488.035,254.309z"/>
</g>
<g id="Inner_Logo">
<g>
<path fill="color_3" d="M257.715,270.169c-10.639,0.077-18.575-7.993-18.664-18.856c-0.082-10.125,8.139-19.026,19.396-18.551
c9.911,0.417,18.399,8.823,18.337,18.934C276.718,261.865,268.112,270.204,257.715,270.169z"/>
<path fill="color_3" d="M417.563,254.87c-0.772-12.634-8.819-21.071-17.74-28.714c-5.485-4.703-11.743-8.388-18.08-11.877
c-1.297,0.013-2.27-0.814-3.334-1.345c-7.105-3.545-14.315-6.839-21.824-9.451c-23.188-8.066-47.132-12.718-71.439-15.543
c-13.31-1.547-26.681-2.573-40.108-2.421c-0.798,0.01-1.913,0.438-2.332-0.416c-0.477-0.967,0.515-1.695,1.101-2.37
c2.768-3.186,5.47-6.438,8.386-9.485c10.842-11.336,21.961-22.382,34.813-31.498c9.761-6.923,19.856-13.179,31.757-15.823
c11.947-2.655,20.75,2.758,22.953,14.155c2.123,10.984,1.452,21.923-0.716,32.804c-0.863,4.337,1.595,8.415,6.035,9.489
c3.896,0.943,7.803-1.593,8.788-5.896c0.9-3.921,1.28-7.929,1.766-11.927c1.188-9.846,1.225-19.63-1.408-29.211
c-3.191-11.618-9.816-20.388-21.916-23.931c-7.979-2.338-15.946-1.484-23.742,0.867c-18.727,5.65-34.001,17.087-48.345,29.797
c-6.287,5.57-12.438,11.378-18.013,17.73c-2.411,2.748-5.268,5.114-7.624,7.903c-4.76,5.627-9.326,11.415-13.944,17.159
c-0.863,1.073-1.926,1.402-3.227,1.265c-4.413-0.466-8.809,0.236-13.146,0.705c-3.229,0.348-6.492,0.148-9.729,0.847
c-3.617,0.78-7.39,0.823-11.078,1.297c-1.893,0.244-2.468-0.71-2.731-2.323c-2.219-13.501-4.468-26.996-2.855-40.767
c0.709-6.056,1.823-12.003,4.842-17.398c3.123-5.59,7.656-8.736,14.361-8.587c4.635,0.104,8.864,1.418,12.998,3.229
c7.017,3.077,13.125,7.604,19.247,12.125c3.358,2.481,8.096,1.916,10.459-0.975c2.598-3.171,2.413-7.417-0.896-10.368
c-7.104-6.332-15.04-11.418-23.802-15.201c-6.186-2.67-12.644-4.607-19.334-4.224c-13.783,0.791-23.182,8.084-28.441,20.779
c-3.296,7.949-4.8,16.281-5.04,24.839c-0.146,5.256-0.454,10.561,0.054,15.771c0.78,8.026,2.074,16.011,3.422,23.968
c0.354,2.082-0.325,2.242-1.972,2.605c-12.14,2.683-24.088,5.98-35.426,11.237c-3.554,1.648-6.83,3.896-10.656,4.953
c-0.319,0.615-0.919,0.833-1.474,1.187c-8.325,5.321-15.736,11.54-19.902,20.837c-2.456,5.484-3.477,11.196-2.477,17.173
c1.476,8.818,6.136,15.803,12.518,21.846c7.018,6.642,14.946,11.946,23.53,16.281c3.984,2.012,8.265,0.615,10.178-3.006
c2.034-3.85,0.969-7.52-2.953-10.09c-0.938-0.615-1.9-1.193-2.879-1.747c-7.14-4.039-13.918-8.545-19.417-14.75
c-7.013-7.912-7.769-15.95-2.016-23.423c2.831-3.677,6.391-6.611,10.303-9.093c12.78-8.11,26.995-12.485,41.572-15.909
c4.978-1.169,4.925-1.153,6.286,3.588c2.887,10.06,6.387,19.916,10.177,29.663c0.694,1.788,0.488,3.103-0.341,4.716
c-5.935,11.563-11.774,23.154-16.591,35.266c-5.604,14.088-10.432,28.369-12.975,43.344c-0.98,5.783-2.014,11.588-2.44,17.425
c-0.32,4.364,0.29,8.798,0.482,13.198c0.506,5.474,1.21,10.819,3.577,15.967c3.133,6.81,7.563,12.271,14.117,15.842
c8.456,4.605,17.401,4.557,26.513,2.326c13.188-3.23,24.592-10.032,35.496-17.791c1.627-1.158,3.296-2.616,2.976-5.069
c0.397-3.09-0.396-5.733-3.079-7.519c-2.684-1.78-5.496-1.805-8.219-0.084c-2.459,1.555-4.796,3.304-7.259,4.852
c-8.951,5.617-18.168,10.581-28.945,11.719c-5.223,0.551-10.134-0.635-13.815-4.17c-4.029-3.869-5.705-9.289-6.165-14.767
c-1.645-19.616,2.871-38.287,9.111-56.672c4-11.783,8.863-23.196,14.339-34.36c0.443-0.906,0.548-2.396,1.565-2.438
c1.09-0.043,1.249,1.459,1.646,2.363c4.657,10.625,10.416,20.688,15.783,30.945c3.31,6.325,7.305,12.27,11.074,18.337
c4.858,7.813,10.538,15.025,15.762,22.567c0.222,0.501,0.373,1.049,0.675,1.496c5.063,7.507,11.001,14.352,17.131,20.945
c10.655,11.463,21.991,22.252,35.719,30.109c9.38,5.369,19.143,9.693,30.312,8.837c8.172-0.626,15.119-3.923,20.57-10.218
c5.651-6.521,8.409-14.264,9.871-22.592c1.41-9.918,1.87-19.887,1.095-29.866c-1.39-17.82-5.655-35.089-10.804-52.122
c-5.052-16.727-11.544-32.932-18.979-48.743c-1.603-3.401-2.589-7.315-6.266-9.372c-2.093-0.604-4.229-0.662-6.369-0.493
c-5.855,3.088-5.509,8.714-3.091,12.9c1.029,1.782,2.021,3.604,2.827,5.494c6.725,15.788,13.585,31.518,18.225,48.106
c2.99,10.697,5.981,21.336,7.501,32.416c1.371,10.016,2.607,19.975,2.03,30.08c-0.304,5.311-1.093,10.583-2.897,15.604
c-2.149,5.977-5.27,11.221-11.944,13.104c-6.099,1.72-11.806-0.085-17.271-2.454c-11.202-4.85-20.384-12.669-29.287-20.789
c-5.116-4.664-9.563-9.979-14.135-15.173c-7.01-7.961-13.4-16.394-19.451-25.086c-7.753-11.137-14.898-22.636-21.179-34.694
c-6.499-12.48-12.777-25.052-18.327-37.987c-0.685-1.59-0.512-2.695,0.316-4.126c8.008-13.818,16.774-27.128,26.234-39.992
c0.996-1.354,1.992-1.928,3.69-1.943c13.994-0.129,27.951,0.41,41.903,1.595c16.549,1.405,32.91,3.992,49.065,7.699
c18.916,4.341,37.432,10.013,54.512,19.526c7.734,4.308,15.205,9.077,20.52,16.39c4.707,6.476,6.42,13.442,0.35,21.155
c-3.74,4.751-8.45,8.045-13.453,11.133c-4.478,2.762-9.378,4.619-14.127,6.811c-3.627,1.673-5.18,6.053-3.737,9.812
c1.292,3.367,5.583,5.337,9.319,4.177c1.604-0.5,3.162-1.182,4.704-1.867c10.977-4.879,21.406-10.568,29.122-20.152
C415.25,270.491,418.068,263.124,417.563,254.87z M206.979,205.849c-3.97,6.242-7.938,12.486-11.911,18.727
c-0.3,0.473-0.605,1.059-1.269,0.909c-0.595-0.134-0.805-0.717-0.95-1.274c-1.319-5.067-3.45-9.896-4.453-15.057
c-1.75-5.588-2.073-5.084,3.33-5.725c5.832-0.692,11.644-1.521,17.72-1.664C209.165,203.616,207.793,204.57,206.979,205.849z"/>
</g>
</g>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment