-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumeric_text_printer.ggcode
More file actions
199 lines (175 loc) · 5.78 KB
/
numeric_text_printer.ggcode
File metadata and controls
199 lines (175 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Numeric Text Printer - Works around string parameter limitation
// Uses character codes instead of strings
note {=== Numeric Text Printer ===}
note {Character codes: A=65, B=66, C=67, ... H=72, E=69, L=76, O=79}
note {Space=32, 0=48, 1=49, 2=50, etc.}
let safe_z = 2
// Function to draw a single character by numeric code
function draw_char(x_pos, y_pos, char_code, size) {
note {Drawing character code [char_code] at X[x_pos] Y[y_pos]}
let width = size
let height = size * 1.5
// A = 65
if char_code == 65 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G0 Z[safe_z]
G0 X[x_pos - width/4] Y[y_pos]
G0 Z[0]
G1 X[x_pos + width/4] Y[y_pos]
G0 Z[safe_z]
}
// B = 66
if char_code == 66 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos]
G1 X[x_pos - width/2] Y[y_pos]
G1 X[x_pos + width/2] Y[y_pos]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G1 X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// C = 67
if char_code == 67 {
G0 Z[safe_z] X[x_pos + width/2] Y[y_pos + height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G1 X[x_pos - width/2] Y[y_pos - height/2]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// E = 69
if char_code == 69 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos + height/2]
G0 Z[safe_z]
G0 X[x_pos - width/2] Y[y_pos]
G0 Z[0]
G1 X[x_pos + width/2] Y[y_pos]
G0 Z[safe_z]
G0 X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// G = 71
if char_code == 71 {
G0 Z[safe_z] X[x_pos + width/2] Y[y_pos + height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G1 X[x_pos - width/2] Y[y_pos - height/2]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G1 X[x_pos + width/2] Y[y_pos]
G1 X[x_pos] Y[y_pos]
G0 Z[safe_z]
}
// H = 72
if char_code == 72 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G0 Z[safe_z]
G0 X[x_pos + width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos + width/2] Y[y_pos + height/2]
G0 Z[safe_z]
G0 X[x_pos - width/2] Y[y_pos]
G0 Z[0]
G1 X[x_pos + width/2] Y[y_pos]
G0 Z[safe_z]
}
// L = 76
if char_code == 76 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G0 Z[safe_z]
G0 X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// O = 79
if char_code == 79 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G1 X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// 0 = 48
if char_code == 48 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos - width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G1 X[x_pos - width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// 1 = 49
if char_code == 49 {
G0 Z[safe_z] X[x_pos] Y[y_pos - height/2]
G0 Z[0]
G1 X[x_pos] Y[y_pos + height/2]
G0 Z[safe_z]
}
// 2 = 50
if char_code == 50 {
G0 Z[safe_z] X[x_pos - width/2] Y[y_pos + height/2]
G0 Z[0]
G1 X[x_pos + width/2] Y[y_pos + height/2]
G1 X[x_pos + width/2] Y[y_pos]
G1 X[x_pos - width/2] Y[y_pos]
G1 X[x_pos - width/2] Y[y_pos - height/2]
G1 X[x_pos + width/2] Y[y_pos - height/2]
G0 Z[safe_z]
}
// Space = 32 (no drawing)
if char_code == 32 {
note {Space character}
}
}
// Helper function to print multiple characters
function print_word(start_x, start_y, size, spacing) {
note {=== Printing HELLO ===}
draw_char(start_x, start_y, 72, size) // H
draw_char(start_x + size + spacing, start_y, 69, size) // E
draw_char(start_x + 2*(size + spacing), start_y, 76, size) // L
draw_char(start_x + 3*(size + spacing), start_y, 76, size) // L
draw_char(start_x + 4*(size + spacing), start_y, 79, size) // O
}
// Usage examples
note {=== Usage Examples ===}
// Print "HELLO" at origin
print_word(0, 0, 8, 2)
// Print "HELLO" at different position and size
print_word(0, -30, 6, 1.5)
// Individual characters
note {=== Individual Characters ===}
draw_char(0, -50, 71, 10) // G
draw_char(15, -50, 71, 10) // G
draw_char(30, -50, 67, 10) // C
draw_char(45, -50, 79, 10) // O
draw_char(60, -50, 68, 10) // D (if we had it)
// Numbers
note {=== Numbers ===}
draw_char(0, -70, 50, 8) // 2
draw_char(12, -70, 48, 8) // 0
draw_char(24, -70, 50, 8) // 2
draw_char(36, -70, 52, 8) // 4
// Return to safe position
G0 Z[safe_z] X[0] Y[0]
note {=== Numeric Text Printer Complete ===}
note {Usage: draw_char(x, y, ascii_code, size)}
note {Common codes: A=65, B=66, C=67, E=69, G=71, H=72, L=76, O=79}
note {Numbers: 0=48, 1=49, 2=50, Space=32}