-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameboxes.py
699 lines (503 loc) · 21.4 KB
/
gameboxes.py
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
from laserproject import LaserObject, LaserProject, LaserTextObject
from shapely.geometry import Polygon
from predefined import finger_jointed_side, move, finger_jointed_lid, rotate, rotate_90
material_thickness = 4.1
slot_width = material_thickness
slot_height = 6
def cardbox():
speed = 800
power = 850
passes = 20
# Create a box, meant for storing cards
# This box has one row of card
# material_thickness = 4.1
rows = 1
columns = 2
depth = 40 + 2 * material_thickness
# Card size determines the size of the box
card_width = 63
card_height = 92
# Card size determines the size of the box
card_width = 48
card_height = 70
# the base place of the box should be material_thickness + card_width and depth + 2 * material_thickness
base_width = columns * (card_width + material_thickness) + material_thickness
baseplate = LaserObject(speed, power, passes)
baseplate.add_polygon(finger_jointed_box(base_width, depth, 3, 2))
# Cards for ease of reference.
cards = LaserObject(speed, power, passes)
# for each card, create a rectangle
for i in range(columns):
x = i * (card_width + material_thickness) + material_thickness
card = [(x, 0), (x, card_height), (x+card_width, card_height), (x + card_width, 0), (x, 0)]
cards.add_polygon(card)
cards.location = (material_thickness, 20)
# total card width is card_width * columns
total_card_width = card_width * columns
total_divider = material_thickness * (columns - 1)
sides = material_thickness * 2
calculated_width = total_card_width + total_divider + sides
# Slots in the bottom box
slots_across = columns - 1
slots_space = slots_across * material_thickness
space_left = base_width - slots_space - 2 * material_thickness
space_between_tabs = space_left / (slots_across + 1)
slot_height = 6
for i in range(1, slots_across + 1):
tab_start_x = space_between_tabs * i + material_thickness * (i)
baseplate.add_rectangle(tab_start_x, depth/2 - slot_height/2 , 4, slot_height)
# Side of the box
# sides = finger_jointed_back(base_width, card_height, 3, 2)
h = card_height/2 - 2 - 5
print("h", h)
sides = finger_jointed_front(base_width, h, 3, 2)
side = LaserObject(speed, power, passes)
side.add_polygon(move(sides, 0 , material_thickness))
# side.add_polygon([[0,0], [base_width, h]])
# side.add_polygon([[0, h], [base_width, 0]])
xb = base_width/2
# side.add_polygon([[xb, 0], [xb, 30]])
# side.add_polygon([[0, 0], [xb, 30]])
# side.add_polygon([[0, 30], [xb, 0]])
xb = xb/2
# side.add_polygon([[xb, 20], [xb, -80]])
center = card_width / 2 + material_thickness
center = 50
title = LaserTextObject("Items", "../fonts/Ugalt.ttf", 20, 600, 250, 1)
title = title.convert_to_laser_object()
title.location = (xb, 0)
title.center()
title.translate(0, 20)
title.priority = 20
xb += base_width/2
# side.add_polygon([[base_width/2, 0], [base_width , 30]])
# side.add_polygon([[base_width/2, 30], [base_width , 0]])
# side.add_polygon([[xb, 20], [xb, -80]])
title2 = LaserTextObject("Artifacts", "../fonts/Ugalt.ttf", 20, 600, 250, 1)
title2 = title2.convert_to_laser_object()
title2.location = (xb, 0)
title2.center()
title2.translate(0, 20)
title2.priority = 20
# Insert
insert = card_insert_side(depth, card_height)
#side.add_polygon(move(insert, material_thickness, material_thickness ))
#side.add_polygon(move(insert, material_thickness, material_thickness))
insert = card_insert(depth, card_height)
#side.add_polygon((move(insert, material_thickness, material_thickness)))
laser_project = LaserProject()
# laser_project.laser_objects.append(baseplate)
laser_project.laser_objects.append(side)
laser_project.laser_objects.append(title)
laser_project.laser_objects.append(title2)
#laser_project.laser_objects.append(cards)
return laser_project
def finger_jointed_bottom(width, height, slots_across, slots_tall):
slot_width = 4
slot_height = 6
# We start 0,0 and then go to 0,height
# How many slots do we need to make, that is the space for the slots
slots_space = slots_tall * slot_height
space_left = height - slots_space
# We need to divide the space left by the number of slots + 1 (top and bottom)
space_between_tabs = space_left / (slots_tall + 1)
# Dynamic points calculation starting from bottom left, moving up and then down the right side
slots_space = slots_across * slot_height
space_left = width - slots_space
space_between_tabs = space_left / (slots_across + 1)
points = [[0, height]]
for i in range(1, slots_across + 1):
tab_start_x = space_between_tabs * i + slot_height * (i - 1)
points += [
[tab_start_x, height],
[tab_start_x, height + slot_width],
[tab_start_x + slot_height, height + slot_width],
[tab_start_x + slot_height, height],
]
points += [[width, height]]
points += [[width, 0]]
points += [[0, 0]]
points += [[0, height]]
# Now we create the right side
return points
def card_insert_side(width, height, slots_vertical = 2, slots_horizontal = 2):
# The side are on the inside, so subtract 2 x material_thickness
width -= 2 * material_thickness
# But, it also has an overhanging tab, so add 1 x material_thickness
width += material_thickness
points = []
# We start 0,0 and then go to 0,height
# How many slots do we need to make, that is the space for the slots
left = finger_joints_vertical(height, slots_vertical)
points += left
# Sloped Curve on the right
sloped = sloped_curve(width, height)
points += sloped
# Tabs inside slope
points += [
[width, height/2 - slot_height - 5],
[width - slot_width, height/2 - slot_height - 5],
]
print("Side" , height / 2 - slot_height - 5)
points += [[width - slot_width, 0]]
# And the bottom
bottom = finger_joints_horizontal(width + material_thickness, slots_horizontal)
# Move all bottom point left by material_thickness
bottom = move(bottom, -material_thickness, 0)
# Remove the first point in bottom
bottom = bottom[1:]
# Replace the last point in bottom
bottom[-1] = [0, 0]
points += bottom
return points
def card_insert(width, height):
# The side are on the inside, so subtract 2 x material_thickness
width -= 2 * material_thickness
# But, it also has an overhanging tab, so add 1 x material_thickness
width += material_thickness
# Bottom first, it has one tab in the middle
space_left = width - slot_height + material_thickness
# Determine the space between the tabs
space_between_tabs = space_left / 2
# Determine the starting x position of the first tab
tab_start_x = space_between_tabs
# Now make the bottom
points = [[width - slot_width, 0]]
# Add the first slot
points += [
[width - tab_start_x, 0],
[width - tab_start_x, - slot_width],
[tab_start_x - material_thickness, - slot_width],
[tab_start_x - material_thickness, 0]
]
points += [[0, 0], [0, height - slot_height]]
# Now a small tab in the top
points += [
[-slot_width, height - slot_height],
[-slot_width, height],
[0, height]
]
# get some rounded corners now
radius = 6
num_points = 16
points += [[0, height]]
# we have 3 points, a start, a corner and an end
start = [0, height]
corner = [ width/2, height]
end = [ width, height/2]
# find the point that is radius away from the corner towards start
# find the point that is radius away from the corner towards end
# Calculate the points along the curve
# curve = quadratic_bezier(start, corner, end, num_points)
# Find the corner points
left_corner_point = point_on_line(corner, start, radius)
right_corner_point = point_on_line(corner, end, radius)
first_curve = quadratic_bezier(left_corner_point, corner, right_corner_point, num_points)
# The second curve is between the next points
start = [ width/2, height]
corner = [ width, height/2]
end = [width,0]
# Find the corner points
left_corner_point = point_on_line(corner, start, radius)
right_corner_point = point_on_line(corner, end, radius)
second_curve = quadratic_bezier(left_corner_point, corner, right_corner_point, num_points)
points += first_curve
points += second_curve
# Add the arc to the points
# Now add a final tab
points += [
[width, height/2 - slot_height - 5],
[width - slot_width, height/2 - slot_height - 5],
#[width - slot_width, height/2 - slot_height - slot_height],
#[width, height / 2 - slot_height - slot_height],
]
points += [[width - slot_width, 0]]
return points
def finger_jointed_box(width, height, slots_across, slots_tall):
slot_width = 4
slot_height = 6
# We start 0,0 and then go to 0,height
# How many slots do we need to make, that is the space for the slots
slots_space = slots_tall * slot_height
space_left = height - slots_space
# We need to divide the space left by the number of slots + 1 (top and bottom)
space_between_tabs = space_left / (slots_tall + 1)
# Dynamic points calculation starting from bottom left, moving up and then down the right side
points = [[0, 0]]
# Generating tab points dynamically on the left side
for i in range(1, slots_tall + 1):
tab_start_y = space_between_tabs * i + slot_height * (i - 1)
points += [
[0, tab_start_y],
[slot_width , tab_start_y], # Left side of the tab
[slot_width , tab_start_y + slot_height], # Bottom side of the tab
[0, tab_start_y + slot_height], # Right side of the tab
]
# Add the top left corner
slots_space = slots_across * slot_height
space_left = width - slots_space
space_between_tabs = space_left / (slots_across + 1)
points += [[0, height]]
for i in range(1, slots_across + 1):
tab_start_x = space_between_tabs * i + slot_height * (i - 1)
points += [
[tab_start_x, height],
[tab_start_x, height - slot_width],
[tab_start_x + slot_height, height - slot_width],
[tab_start_x + slot_height, height],
]
points += [[width, height]]
# okay, we have, the left and top, now we need to do the right and bottom
# we can just mirror that
# take all the points, and mirror them so the box is complete
mirrored_points = [[width - x, height - y] for x, y in points]
points += mirrored_points
# Now we create the right side
return points
###
def finger_jointed_front(width, height, slots_across, slots_tall):
slot_height = 4
material_thickness = 4.1
# We start 0,0 and then go to 0,height
# How many slots do we need to make, that is the space for the slots
slots_space = slots_tall * slot_height
space_left = height - slots_space
# We need to divide the space left by the number of slots + 1 (top and bottom)
space_between_tabs = space_left / (slots_tall + 1)
# Dynamic points calculation starting from bottom left, moving up and then down the right side
# left = finger_joints_vertical(height, width, slots_vertical = 2, slots=True, side = "left")
points = [[0, 0]]
slots_space = slots_across * slot_height
space_left = width - slots_space
space_between_tabs = space_left / (slots_across + 1)
points += [
[0, height - slot_height],
[material_thickness, height - slot_height],
[material_thickness, height]
]
# Instead of this, we need one vertical slot, in the center
# Insert slots in the middle
columns = 2
number_of_slots = columns - 1
material_thickness = 4.1
# Determine how much space is left after the slots
space_left = width - number_of_slots * material_thickness
# Determine the space between the slots
space_between_slots = space_left / (number_of_slots + 1)
# Determine the width of the slot
slot_width = material_thickness
# Determine the starting x position of the first slot
tab_start_x = space_between_slots
# Determine the starting y position of the slot
tab_start_y = height
# Add the first slot
points += [
[tab_start_x, tab_start_y],
[tab_start_x, tab_start_y - slot_height],
[tab_start_x + slot_width, tab_start_y - slot_height],
[tab_start_x + slot_width, tab_start_y],
]
points += [
[width - material_thickness, height],
[width - material_thickness, height - slot_height],
[width, height - slot_height],
[width, 0]
]
bottom = finger_joints_horizontal( width, slots_horizontal = 3, slots=False)
points += bottom
return points
def finger_jointed_back(width, height, slots_across, slots_tall):
slot_width = 4.1
slot_height = 6
#print(height)
# We start 0,0 and then go to 0,height
# How many slots do we need to make, that is the space for the slots
slots_space = slots_tall * slot_height
space_left = height - slots_space
# We need to divide the space left by the number of slots + 1 (top and bottom)
space_between_tabs = space_left / (slots_tall + 1)
# Dynamic points calculation starting from bottom left, moving up and then down the right side
left = finger_joints_vertical(height, width, slots_vertical = 2, slots=True, side = "left")
points = left
slots_space = slots_across * slot_height
space_left = width - slots_space
space_between_tabs = space_left / (slots_across + 1)
points += [[0, height]]
# Instead of this, we need one vertical slot, in the center
# Insert slots in the middle
columns = 2
number_of_slots = columns - 1
material_thickness = 4.1
# Determine how much space is left after the slots
space_left = width - number_of_slots * material_thickness
# Determine the space between the slots
space_between_slots = space_left / (number_of_slots + 1)
# Determine the height of the slot
slot_height = 6
# Determine the width of the slot
slot_width = material_thickness
# Determine the starting x position of the first slot
tab_start_x = space_between_slots
# Determine the starting y position of the slot
tab_start_y = height
# Add the first slot
points += [
[tab_start_x, tab_start_y],
[tab_start_x, tab_start_y - slot_height],
[tab_start_x + slot_width, tab_start_y - slot_height],
[tab_start_x + slot_width, tab_start_y],
]
# # Top Side Slots
# for i in range(1, slots_across + 1):
# tab_start_x = space_between_tabs * i + slot_height * (i - 1)
# points += [
# [tab_start_x, height],
# [tab_start_x, height + slot_width],
# [tab_start_x + slot_height, height + slot_width],
# [tab_start_x + slot_height, height],
# ]
# Right side
right = finger_joints_vertical(height, width, slots_vertical = 2, slots=True, side = "right")
points += right
# Bottom Side Slots
for i in range(1, slots_across + 1):
# Calculate starting x position from the right, moving leftward
tab_start_x = width - (space_between_tabs * i + slot_height * (i - 1) )
points += [
[tab_start_x, 0],
[tab_start_x, -slot_width], # Slot extends upwards
[tab_start_x - slot_height, -slot_width], # Right side of the slot
[tab_start_x - slot_height, 0], # Back to starting height
]
points += [[0, 0]]
# okay, we have, the left and top, now we need to do the right and bottom
# we can just mirror that
# take all the points, and mirror them so the box is complete
# mirrored_points = [[width - x, height - y] for x, y in points]
# points += mirrored_points
# Now we create the right side
return points
import numpy as np
def quadratic_bezier(p0, p1, p2, N=16):
"""
Computes N points along a quadratic Bézier curve defined by three points.
Parameters:
- p0: Tuple (x, y), the starting point of the curve.
- p1: Tuple (x, y), the control point of the curve.
- p2: Tuple (x, y), the ending point of the curve.
- N : Integer, the number of points on the curve to calculate.
Returns:
- List of tuples representing points (x, y) along the curve.
"""
t_values = [i / (N - 1) for i in range(N)]
curve_points = []
for t in t_values:
x = (1 - t) ** 2 * p0[0] + 2 * (1 - t) * t * p1[0] + t ** 2 * p2[0]
y = (1 - t) ** 2 * p0[1] + 2 * (1 - t) * t * p1[1] + t ** 2 * p2[1]
curve_points.append((x, y))
return curve_points
def point_on_line(a, b, n):
"""
Calculates a point C that is N distance away from point A along the line AB.
Parameters:
- a: Tuple (x, y), the coordinates of point A.
- b: Tuple (x, y), the coordinates of point B.
- n: Float, the distance from point A to point C.
Returns:
- Tuple (x, y) representing the coordinates of point C.
"""
# Calculate the vector from A to B
vector_ab = (b[0] - a[0], b[1] - a[1])
# Calculate the distance from A to B
length_ab = (vector_ab[0]**2 + vector_ab[1]**2)**0.5
# Normalize the vector
unit_vector_ab = (vector_ab[0] / length_ab, vector_ab[1] / length_ab)
# Calculate point C as A + n * unit_vector
c = (a[0] + n * unit_vector_ab[0], a[1] + n * unit_vector_ab[1])
return c
def finger_joints_vertical(height, width=0, slots_vertical = 2, slots=False, side = "left"):
slots_space = slots_vertical * slot_height
space_left = height - slots_space
# We need to divide the space left by the number of slots + 1 (top and bottom)
space_between_tabs = space_left / (slots_vertical + 1)
# Create points
points = []
if slots:
modifier = -1
else:
modifier = 1
if side == "left":
points = [[0, 0]]
# Generating tab points dynamically on the left side
for i in range(1, slots_vertical + 1):
tab_start_y = space_between_tabs * i + slot_height * (i - 1)
points += [
[0, tab_start_y],
[-slot_width * modifier , tab_start_y], # Left side of the tab
[-slot_width * modifier, tab_start_y + slot_height], # Bottom side of the tab
[0, tab_start_y + slot_height], # Right side of the tab
]
points += [[0, height]]
if side == "right":
points = [[width, height]]
for i in range(1, slots_vertical + 1):
# Calculate starting y position from the top, moving downward
tab_start_y = height - (space_between_tabs * i + slot_height * (i - 1))
points += [
[width, tab_start_y],
[width - (slot_width * - modifier), tab_start_y], # Left side of the tab
[width - (slot_width * - modifier), tab_start_y - slot_height], # Bottom side of the tab
[width, tab_start_y - slot_height], # Right side of the tab
]
points += [[width, 0]]
return points
def finger_joints_horizontal(width, slots_horizontal = 2, slots=False, direction= "bottom"):
# We start 0,0 and then go to 0,height
# How many slots do we need to make, that is the space for the slots
slots_space = slots_horizontal * slot_height
space_left = width - slots_space
# We need to divide the space left by the number of slots + 1 (top and bottom)
space_between_tabs = space_left / (slots_horizontal + 1)
points = [[width, 0]]
if direction == "bottom":
multiplier = 1
else:
multiplier = -1
# Bottom Side Slots
for i in range(1, slots_horizontal + 1):
# Calculate starting x position from the right, moving leftward
tab_start_x = width - (space_between_tabs * i + slot_height * (i - 1) )
points += [
[tab_start_x, 0],
[tab_start_x, -slot_width * multiplier], # Slot extends upwards
[tab_start_x - slot_height, -slot_width * multiplier], # Right side of the slot
[tab_start_x - slot_height, 0], # Back to starting height
]
points += [[0, 0]]
return points
def sloped_curve(width, height):
# Below this, is the sloped side
# get some rounded corners now
radius = 6
num_points = 16
# we have 3 points, a start, a corner and an end
start = [0, height]
corner = [ width/2, height]
end = [ width, height/2]
# find the point that is radius away from the corner towards start
# find the point that is radius away from the corner towards end
left_corner_point = point_on_line(corner, start, radius)
right_corner_point = point_on_line(corner, end, radius)
first_curve = quadratic_bezier(left_corner_point, corner, right_corner_point, num_points)
# The second curve is between the next points
start = [ width/2, height]
corner = [ width, height/2]
end = [width,0]
# Find the corner points
left_corner_point = point_on_line(corner, start, radius)
right_corner_point = point_on_line(corner, end, radius)
second_curve = quadratic_bezier(left_corner_point, corner, right_corner_point, num_points)
points = []
points += first_curve
points += second_curve
return points