123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #!/usr/bin/env python
-
- filename = "grid.gcode"
- w = 200
- h = 280
- d = 10
- pwr = 100
- speed_g0 = 3000
- speed_g1 = 1000
-
- digits = [
- [
- # 0
- (0.0, 0.0),
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.0),
- (0.0, 0.0)
- ], [
- # 1
- (0.5, 0.0),
- (0.5, 1.0)
- ], [
- # 2
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.5),
- (0.0, 0.5),
- (0.0, 0.0),
- (1.0, 0.0),
- ], [
- # 3
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.5),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- ], [
- # 4
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 1.0),
- (1.0, 0.0),
- ], [
- # 5
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- ], [
- # 6
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.0),
- (1.0, 0.0),
- (1.0, 0.5),
- (0.0, 0.5),
- ], [
- # 7
- (0.0, 1.0),
- (1.0, 1.0),
- (1.0, 0.0),
- ], [
- # 8
- (1.0, 0.5),
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- (0.0, 0.5),
- ], [
- # 9
- (1.0, 0.5),
- (1.0, 1.0),
- (0.0, 1.0),
- (0.0, 0.5),
- (1.0, 0.5),
- (1.0, 0.0),
- (0.0, 0.0),
- ]
- ]
-
- font_w = 1.5
- font_h = 3.0
- font_d = 0.5
-
- def draw_digit(f, i, sx, sy, ox, oy):
- dig = digits[i]
- n = 0
- for p in dig:
- x, y = p
- s = ""
-
- if n == 0:
- s += "G0 S0 F" + str(speed_g0)
- else:
- s += "G1 S" + str(pwr) + " F" + str(speed_g1)
-
- s += " X" + str(ox + sx * x)
- s += " Y" + str(oy + sy * y)
-
- print(s)
- f.write(s + "\n")
- n += 1
-
- return s
-
- 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("")
-
- # 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 Y" + str(h) + " S" + str(pwr) + " F" + str(speed_g1))
-
- # vertical lines
- write("; vertical lines")
- for x in range(0, w + d, d):
- write("G0 X" + str(x) + " Y0 S0 F" + str(speed_g0))
- write("G1 X" + str(x) + " Y" + str(h) + " S" + str(pwr) + " F" + str(speed_g1))
- write("")
-
- # horizontal lines
- write("; horizontal lines")
- for y in range(0, h + d, d):
- write("G0 X0 Y" + str(y) + " S0 F" + str(speed_g0))
- write("G1 X" + str(w) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed_g1))
- write("")
-
- # horizontal text
- for x in range(0, w, d):
- n = int(x / 10)
- write("; number '" + str(n) + "' at x " + str(x))
- if n >= 10:
- draw_digit(f, int(n / 10), font_w, font_h, font_d + x, font_d)
- draw_digit(f, int(n % 10), font_w, font_h, 2 * font_d + font_w + x, font_d)
- else:
- draw_digit(f, n, font_w, font_h, font_d + x, font_d)
- write("")
-
- # vertical text
- for y in range(d, h, d):
- n = int(y / 10)
- write("; number '" + str(n) + "' at y " + str(y))
- if n >= 10:
- draw_digit(f, int(n / 10), font_w, font_h, font_d, font_d + y)
- draw_digit(f, int(n % 10), font_w, font_h, 2 * font_d + font_w, font_d + y)
- else:
- draw_digit(f, n, font_w, font_h, font_d, font_d + y)
- write("")
-
- # footer
- write("M5")
- write("G0 X0 Y0 F" + str(speed_g0))
|