from Gcode_generator import Gcode from Gcode_generator import Machine from HersheyFonts import HersheyFonts import matplotlib.pyplot as plt machine_type = Machine.THREEAXIS vertical_offset = 100 def convert_text(text): # Create an instance of the Gcode class gcode = Gcode( file="test_gcode", # Output file name (no .gcode extension) mm_per_px=0.1, # Conversion factor: mm per pixel speed=1000, # Speed in mm/min machine=machine_type, max_s=255, # Laser power (only for LASER machines) safe_z= 5, work_z= 0 ) thefont = HersheyFonts() thefont.load_default_font() thefont.normalize_rendering(100) line_count = 1 # starts at 1 to offset the first line below y = 0 for line in text.splitlines(): text_segments = thefont.lines_for_text(line) last_p2 = (0,0) for (x1, y1), (x2, y2) in text_segments: y1 -= vertical_offset * line_count y2 -= vertical_offset * line_count if((x1, y1) == last_p2): gcode.write_to(x2 ,y2) else: gcode.draw_line(x1, y1, x2, y2) last_p2 = (x2,y2) line_count += 1 # Finish the G-code file gcode.end_gcode() return gcode.output print(convert_text("un \ntexte \navec \ndes \nlignes")) print("G-code file generated: test_gcode.gcode")