Skip to content

Instantly share code, notes, and snippets.

@haideralipunjabi
Last active November 4, 2018 10:23
Show Gist options
  • 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
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