-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_compact_font.ggcode
More file actions
367 lines (313 loc) · 10.8 KB
/
simple_compact_font.ggcode
File metadata and controls
367 lines (313 loc) · 10.8 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Simple Ultra-Compact Font System
// Complete A-Z, 0-9 using minimal algorithmic approach
note {=== Simple Ultra-Compact Font ===}
note {Algorithmic generation - minimal code, complete character set}
let safe_z = 2
// CORE ALGORITHM: Pattern-based character generation
// Uses simple geometric rules instead of storing bitmaps
function draw_compact_char(x, y, char, size) {
note {Compact: '[char]' at X[x] Y[y]}
let w = size / 2 // Half width
let h = size / 2 // Half height
// Helper function to draw a line segment
function draw_line(x1, y1, x2, y2) {
G0 Z[safe_z] X[x + x1] Y[y + y1]
G0 Z[0]
G1 X[x + x2] Y[y + y2]
G0 Z[safe_z]
}
// Helper function to draw a rectangle outline
function draw_rect(x1, y1, x2, y2) {
G0 Z[safe_z] X[x + x1] Y[y + y1]
G0 Z[0]
G1 X[x + x2] Y[y + y1] // Top
G1 X[x + x2] Y[y + y2] // Right
G1 X[x + x1] Y[y + y2] // Bottom
G1 X[x + x1] Y[y + y1] // Left (close)
G0 Z[safe_z]
}
// LETTERS: Algorithmic patterns
if char == "A" {
// A: Triangle + crossbar
draw_line(-w, -h, 0, h) // Left diagonal
draw_line(0, h, w, -h) // Right diagonal
draw_line(-w/2, 0, w/2, 0) // Crossbar
}
if char == "B" {
// B: Left vertical + two bumps
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, h, w/2, h) // Top horizontal
draw_line(w/2, h, w/2, 0) // Top right
draw_line(w/2, 0, -w, 0) // Middle horizontal
draw_line(-w, 0, w/2, 0) // Middle horizontal (repeat for bump)
draw_line(w/2, 0, w/2, -h) // Bottom right
draw_line(w/2, -h, -w, -h) // Bottom horizontal
}
if char == "C" {
// C: Open rectangle (horseshoe)
draw_line(w, h, -w, h) // Top
draw_line(-w, h, -w, -h) // Left
draw_line(-w, -h, w, -h) // Bottom
}
if char == "D" {
// D: Rectangle with curved right (simplified as angled)
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, h, w/2, h) // Top
draw_line(w/2, h, w, 0) // Top-right curve
draw_line(w, 0, w/2, -h) // Bottom-right curve
draw_line(w/2, -h, -w, -h) // Bottom
}
if char == "E" {
// E: Left vertical + three horizontals
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, h, w, h) // Top
draw_line(-w, 0, w/2, 0) // Middle
draw_line(-w, -h, w, -h) // Bottom
}
if char == "F" {
// F: Like E but no bottom horizontal
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, h, w, h) // Top
draw_line(-w, 0, w/2, 0) // Middle
}
if char == "G" {
// G: C with inner horizontal
draw_line(w, h, -w, h) // Top
draw_line(-w, h, -w, -h) // Left
draw_line(-w, -h, w, -h) // Bottom
draw_line(w, -h, w, 0) // Right bottom
draw_line(w, 0, 0, 0) // Inner horizontal
}
if char == "H" {
// H: Two verticals + crossbar
draw_line(-w, -h, -w, h) // Left vertical
draw_line(w, -h, w, h) // Right vertical
draw_line(-w, 0, w, 0) // Crossbar
}
if char == "I" {
// I: Center vertical + top/bottom bars
draw_line(-w, h, w, h) // Top bar
draw_line(0, h, 0, -h) // Center vertical
draw_line(-w, -h, w, -h) // Bottom bar
}
if char == "J" {
// J: Top bar + right vertical + bottom curve
draw_line(-w, h, w, h) // Top bar
draw_line(w, h, w, -h/2) // Right vertical
draw_line(w, -h/2, 0, -h) // Curve to center bottom
draw_line(0, -h, -w/2, -h) // Bottom curve
}
if char == "K" {
// K: Left vertical + two diagonals
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, 0, w, h) // Upper diagonal
draw_line(-w, 0, w, -h) // Lower diagonal
}
if char == "L" {
// L: Left vertical + bottom horizontal
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, -h, w, -h) // Bottom horizontal
}
if char == "M" {
// M: Two verticals + peak
draw_line(-w, -h, -w, h) // Left vertical
draw_line(w, -h, w, h) // Right vertical
draw_line(-w, h, 0, h/2) // Left peak
draw_line(0, h/2, w, h) // Right peak
}
if char == "N" {
// N: Two verticals + diagonal
draw_line(-w, -h, -w, h) // Left vertical
draw_line(w, -h, w, h) // Right vertical
draw_line(-w, -h, w, h) // Diagonal
}
if char == "O" {
// O: Complete rectangle
draw_rect(-w, -h, w, h)
}
if char == "P" {
// P: Left vertical + top bump
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, h, w, h) // Top
draw_line(w, h, w, 0) // Right top
draw_line(w, 0, -w, 0) // Middle
}
if char == "Q" {
// Q: O with tail
draw_rect(-w, -h, w, h) // Rectangle
draw_line(w/2, -h/2, w, -h) // Tail
}
if char == "R" {
// R: P + diagonal leg
draw_line(-w, -h, -w, h) // Left vertical
draw_line(-w, h, w, h) // Top
draw_line(w, h, w, 0) // Right top
draw_line(w, 0, -w, 0) // Middle
draw_line(-w, 0, w, -h) // Diagonal leg
}
if char == "S" {
// S: Snake pattern
draw_line(-w, h, w, h) // Top
draw_line(-w, h, -w, 0) // Left top
draw_line(-w, 0, w, 0) // Middle
draw_line(w, 0, w, -h) // Right bottom
draw_line(w, -h, -w, -h) // Bottom
}
if char == "T" {
// T: Top bar + center vertical
draw_line(-w, h, w, h) // Top bar
draw_line(0, h, 0, -h) // Center vertical
}
if char == "U" {
// U: Horseshoe
draw_line(-w, h, -w, -h) // Left vertical
draw_line(-w, -h, w, -h) // Bottom
draw_line(w, -h, w, h) // Right vertical
}
if char == "V" {
// V: Converging lines
draw_line(-w, h, 0, -h) // Left diagonal
draw_line(w, h, 0, -h) // Right diagonal
}
if char == "W" {
// W: Double V
draw_line(-w, h, -w/2, -h) // Left outer
draw_line(-w/2, -h, 0, h/2) // Left inner
draw_line(0, h/2, w/2, -h) // Right inner
draw_line(w/2, -h, w, h) // Right outer
}
if char == "X" {
// X: Two diagonals
draw_line(-w, -h, w, h) // Main diagonal
draw_line(-w, h, w, -h) // Cross diagonal
}
if char == "Y" {
// Y: Converging to center vertical
draw_line(-w, h, 0, 0) // Left diagonal
draw_line(w, h, 0, 0) // Right diagonal
draw_line(0, 0, 0, -h) // Center vertical
}
if char == "Z" {
// Z: Zigzag
draw_line(-w, h, w, h) // Top
draw_line(w, h, -w, -h) // Diagonal
draw_line(-w, -h, w, -h) // Bottom
}
// NUMBERS: Seven-segment inspired but simplified
if char == "0" {
draw_rect(-w, -h, w, h) // Rectangle
}
if char == "1" {
draw_line(0, -h, 0, h) // Center vertical
}
if char == "2" {
draw_line(-w, h, w, h) // Top
draw_line(w, h, w, 0) // Right top
draw_line(w, 0, -w, 0) // Middle
draw_line(-w, 0, -w, -h) // Left bottom
draw_line(-w, -h, w, -h) // Bottom
}
if char == "3" {
draw_line(-w, h, w, h) // Top
draw_line(w, h, w, -h) // Right vertical
draw_line(w, 0, 0, 0) // Middle (partial)
draw_line(w, -h, -w, -h) // Bottom
}
if char == "4" {
draw_line(-w, h, -w, 0) // Left top
draw_line(-w, 0, w, 0) // Middle
draw_line(w, h, w, -h) // Right vertical
}
if char == "5" {
draw_line(w, h, -w, h) // Top
draw_line(-w, h, -w, 0) // Left top
draw_line(-w, 0, w, 0) // Middle
draw_line(w, 0, w, -h) // Right bottom
draw_line(w, -h, -w, -h) // Bottom
}
if char == "6" {
draw_line(w, h, -w, h) // Top
draw_line(-w, h, -w, -h) // Left vertical
draw_line(-w, 0, w, 0) // Middle
draw_line(w, 0, w, -h) // Right bottom
draw_line(w, -h, -w, -h) // Bottom
}
if char == "7" {
draw_line(-w, h, w, h) // Top
draw_line(w, h, 0, -h) // Diagonal
}
if char == "8" {
draw_rect(-w, -h, w, h) // Rectangle
draw_line(-w, 0, w, 0) // Middle horizontal
}
if char == "9" {
draw_line(-w, h, w, h) // Top
draw_line(-w, h, -w, 0) // Left top
draw_line(-w, 0, w, 0) // Middle
draw_line(w, h, w, -h) // Right vertical
draw_line(w, -h, -w, -h) // Bottom
}
// SPECIAL CHARACTERS
if char == " " {
// Space - no drawing
note {Space}
}
if char == "." {
// Period - small dot
G0 Z[safe_z] X[x] Y[y - h]
G0 Z[0]
G1 X[x + w/4] Y[y - h]
G1 X[x + w/4] Y[y - h + w/4]
G1 X[x] Y[y - h + w/4]
G1 X[x] Y[y - h]
G0 Z[safe_z]
}
if char == "!" {
// Exclamation - vertical line + dot
draw_line(0, 0, 0, h) // Vertical line
G0 Z[safe_z] X[x] Y[y - h] // Dot
G0 Z[0]
G1 X[x + w/4] Y[y - h]
G1 X[x + w/4] Y[y - h + w/4]
G1 X[x] Y[y - h + w/4]
G1 X[x] Y[y - h]
G0 Z[safe_z]
}
}
// DEMONSTRATION
note {=== Simple Compact Font Demo ===}
// Test alphabet
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let x_pos = 0
let y_pos = 20
for letter in alphabet {
draw_compact_char(x_pos, y_pos, letter, 6)
x_pos = x_pos + 8
if x_pos > 100 {
x_pos = 0
y_pos = y_pos - 10
}
}
// Test numbers
let numbers = "0123456789"
x_pos = 0
y_pos = 0
for digit in numbers {
draw_compact_char(x_pos, y_pos, digit, 6)
x_pos = x_pos + 8
}
// Test sample text
let sample = "HELLO WORLD 2024!"
x_pos = 0
y_pos = -15
for char in sample {
draw_compact_char(x_pos, y_pos, char, 8)
x_pos = x_pos + 10
}
// Return to safe position
G0 Z[safe_z] X[0] Y[0]
note {=== Simple Compact Font Complete ===}
note {Algorithmic generation: No bitmap storage needed}
note {Complete A-Z, 0-9, and basic punctuation}
note {Scalable and efficient for CNC applications}
note {Minimal code - maximum character coverage}