Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.