123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/usr/bin/env python
-
- filename = "square.gcode"
- w = 10
- h = 10
- n = 20
- pwr = 255
- speed_g0 = 3000
- speed_g1 = 500
-
- with open(filename, 'w') as f:
- def write(s):
- print(s)
- f.write(s + "\n")
-
- # header
- write("G90")
- write("G28")
- write("G92 X0 Y-20")
- write("M3 I")
- write("M3 S0")
- write("")
-
- square = [
- ( 0, 0 ),
- ( w, 0 ),
- ( w, h ),
- ( 0, h ),
- ]
-
- # first line is not having the power applied
- # so just draw it twice
- # TODO why?
- write("G0 X0 Y0 S0 F" + str(speed_g0))
- write("G1 X0 Y0 S" + str(pwr) + " F" + str(speed_g1))
-
- for i in range(0, n):
- for x, y in square:
- write("G1 X" + str(x) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed_g1))
- write("")
-
- # finish last line
- write("G1 X0 Y0 S" + str(pwr) + " F" + str(speed_g1))
- write("")
-
- # footer
- write("M5")
- write("G0 X0 Y0 F" + str(speed_g0))
|