Skip to content

Instantly share code, notes, and snippets.

@gfhuertac
Created June 14, 2018 12:22
Show Gist options
  • Save gfhuertac/1b6e705d57d42c657cee559e1bb02a68 to your computer and use it in GitHub Desktop.
Save gfhuertac/1b6e705d57d42c657cee559e1bb02a68 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot
import numpy
import math
number_codes = ['0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011']
def write_code(bcode, pos, number_value, separator=False):
#tu codigo aca
def write_separator(bcode, pos):
write_code(bcode, pos, '010', True)
def write_middle_separator(bcode, pos):
write_code(bcode, pos, '10101', True)
def write_barcode(number_value):
bcode = numpy.ones([30, 95, 3], dtype=float)
codes = numpy.fromiter(number_value, dtype=int)
check_sum = numpy.sum(codes[0::2])*3 + numpy.sum(codes[1::2])
check_code = (10 - check_sum%10)%10
codes = numpy.append(codes, [check_code])
pos = 0
write_separator(bcode, pos)
pos = pos + 3
for code in codes:
separator = False
if pos == 3 or pos == 85:
separator = True
write_code(bcode, pos, number_codes[code], separator)
pos = pos + 7
if pos == 45:
write_middle_separator(bcode, pos)
pos = pos + 5
write_separator(bcode, pos)
pos = pos + 3
matplotlib.pyplot.imsave('barcode.png', bcode)
write_barcode('01010101010')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment