I'm trying to generate a G-code using python. I write instructions according to the grey-scale image pixel values, but if I need to work with big images it takes forever to compile a code. Some G-code programs process these images in seconds. How can I make this program faster?
Thank you for your time.
gray_height = gray.shape[0]
gray_length = gray.shape[1]
print("length", gray_length)
print("height", gray_height)
for i in range(gray_length):
j=0
for j in range(gray_height):
k = 'G01 X{}'.format(round(i*0.1,3)) + ' Y{}'.format(round(j*0.1,3)) + '\n' +'G01 Z -10' +'\n' +'G04 {}'.format(round(gray[i,j],2)) +'\n' + 'G01 Z 10' +'\n'
with open("file.txt", "a") as a_file:
a_file.write(k)