Added convert_text fucntion to the text_to_gcode file, that takes user's text and return gcode
This commit is contained in:
@@ -6,8 +6,14 @@ import matplotlib.pyplot as plt
|
||||
|
||||
machine_type = Machine.THREEAXIS
|
||||
|
||||
# Create an instance of the Gcode class
|
||||
gcode = Gcode(
|
||||
|
||||
|
||||
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
|
||||
@@ -15,35 +21,41 @@ gcode = Gcode(
|
||||
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)
|
||||
|
||||
thefont = HersheyFonts()
|
||||
thefont.load_default_font()
|
||||
thefont.normalize_rendering(100)
|
||||
line_count = 1 # starts at 1 to offset the first line below y = 0
|
||||
|
||||
text_lines = thefont.lines_for_text('Wallter is a wall plotter')
|
||||
for line in text.splitlines():
|
||||
|
||||
# print(next(text_lines)[0])
|
||||
# first_point = next(text_lines)[0]
|
||||
# gcode.go_to(first_point[0], first_point[1])
|
||||
text_segments = thefont.lines_for_text(line)
|
||||
|
||||
last_p2 = (0,0)
|
||||
for (x1, y1), (x2, y2) in text_lines:
|
||||
if((x1, y1) == last_p2):
|
||||
gcode.write_to(x2 ,y2)
|
||||
else:
|
||||
gcode.draw_line(x1, y1, x2, y2)
|
||||
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)
|
||||
last_p2 = (x2,y2)
|
||||
|
||||
line_count += 1
|
||||
|
||||
# Finish the G-code file
|
||||
|
||||
gcode.end_gcode()
|
||||
|
||||
return gcode.output
|
||||
|
||||
|
||||
|
||||
|
||||
# Draw a line from (10, 20) to (30, 40)
|
||||
# gcode.draw_line(10, 20, 30, 40)
|
||||
|
||||
|
||||
# Finish the G-code file
|
||||
gcode.end_gcode()
|
||||
print(convert_text("un \ntexte \navec \ndes \nlignes"))
|
||||
|
||||
print("G-code file generated: test_gcode.gcode")
|
||||
Reference in New Issue
Block a user