| |
| |
|
|
| |
| source("R/rectangular_puzzle.R") |
| source("R/puzzle_core_clean.R") |
| source("R/puzzle_separation.R") |
|
|
| cat("=== Puzzle Piece Separation Examples ===\n\n") |
| cat("This feature maintains pieces in their original grid positions\n") |
| cat("but adds configurable gaps between them.\n\n") |
|
|
| |
| cat("Example 1: Laser Cutting Layout (2x2)\n") |
| cat("-" , rep("-", 40), "\n", sep="") |
|
|
| |
| puzzle_2x2 <- generate_puzzle_core( |
| seed = 1234, |
| grid = c(2, 2), |
| size = c(100, 100) |
| ) |
|
|
| |
| optimal_offset <- calculate_optimal_offset( |
| piece_width = puzzle_2x2$piece_width, |
| piece_height = puzzle_2x2$piece_height, |
| kerf = 0.2, |
| min_separation = 3 |
| ) |
|
|
| cat(sprintf("Piece size: %.0f x %.0f mm\n", |
| puzzle_2x2$piece_width, puzzle_2x2$piece_height)) |
| cat(sprintf("Optimal offset for laser cutting: %.2f mm\n", optimal_offset)) |
|
|
| |
| svg_laser <- generate_separated_puzzle_svg( |
| puzzle_structure = puzzle_2x2, |
| offset = optimal_offset, |
| colors = "black", |
| stroke_width = 0.5 |
| ) |
|
|
| writeLines(svg_laser, "output/example_laser_cutting_2x2.svg") |
| cat("✓ Saved: output/example_laser_cutting_2x2.svg\n\n") |
|
|
| |
| cat("Example 2: Progressive Separation (shows different offsets)\n") |
| cat("-" , rep("-", 40), "\n", sep="") |
|
|
| offsets <- c(0, 5, 10, 20) |
| colors <- c("#FF6B6B", "#4ECDC4", "#45B7D1", "#FFA07A") |
|
|
| for (offset in offsets) { |
| svg <- generate_separated_puzzle_svg( |
| puzzle_structure = puzzle_2x2, |
| offset = offset, |
| colors = colors, |
| stroke_width = 1.5 |
| ) |
| |
| filename <- sprintf("output/example_separation_%dmm.svg", offset) |
| writeLines(svg, filename) |
| cat(sprintf(" Offset %2d mm: %s\n", offset, filename)) |
| } |
|
|
| cat("\n") |
|
|
| |
| cat("Example 3: Production Layout (4x3 puzzle)\n") |
| cat("-" , rep("-", 40), "\n", sep="") |
|
|
| |
| puzzle_4x3 <- generate_puzzle_core( |
| seed = 9999, |
| grid = c(3, 4), |
| size = c(200, 150), |
| tabsize = 22, |
| jitter = 3 |
| ) |
|
|
| |
| production_offset <- 8 |
|
|
| svg_production <- generate_separated_puzzle_svg( |
| puzzle_structure = puzzle_4x3, |
| offset = production_offset, |
| colors = "darkblue", |
| stroke_width = 1.0 |
| ) |
|
|
| writeLines(svg_production, "output/example_production_4x3.svg") |
|
|
| |
| original_area <- puzzle_4x3$size[1] * puzzle_4x3$size[2] |
| separated_width <- puzzle_4x3$size[1] + (4 - 1) * production_offset |
| separated_height <- puzzle_4x3$size[2] + (3 - 1) * production_offset |
| separated_area <- separated_width * separated_height |
|
|
| cat(sprintf("Original puzzle size: %.0f x %.0f mm (area: %.0f mm²)\n", |
| puzzle_4x3$size[1], puzzle_4x3$size[2], original_area)) |
| cat(sprintf("Separated layout size: %.0f x %.0f mm (area: %.0f mm²)\n", |
| separated_width, separated_height, separated_area)) |
| cat(sprintf("Area increase: %.1f%%\n", |
| (separated_area - original_area) / original_area * 100)) |
| cat("✓ Saved: output/example_production_4x3.svg\n\n") |
|
|
| |
| cat("Example 4: Assembly Guide with Color Coding\n") |
| cat("-" , rep("-", 40), "\n", sep="") |
|
|
| |
| puzzle_3x3 <- generate_puzzle_core( |
| seed = 42, |
| grid = c(3, 3), |
| size = c(150, 150) |
| ) |
|
|
| |
| guide_colors <- c( |
| "#FF6B6B", |
| "#4ECDC4", |
| "#45B7D1", |
| "#FF6B6B", |
| "#4ECDC4", |
| "#FF6B6B", |
| "#4ECDC4", |
| "#4ECDC4", |
| "#FF6B6B" |
| ) |
|
|
| svg_guide <- generate_separated_puzzle_svg( |
| puzzle_structure = puzzle_3x3, |
| offset = 15, |
| colors = guide_colors, |
| stroke_width = 2.0 |
| ) |
|
|
| writeLines(svg_guide, "output/example_assembly_guide_3x3.svg") |
| cat("✓ Saved: output/example_assembly_guide_3x3.svg\n") |
| cat(" Color coding: Red=corners, Teal=edges, Blue=center\n\n") |
|
|
| |
| cat("Example 5: Enhanced Function Demonstration\n") |
| cat("-" , rep("-", 40), "\n", sep="") |
|
|
| modes <- list( |
| list(desc = "Traditional (touching pieces)", |
| mode = "individual", offset = 0), |
| list(desc = "Small separation (5mm)", |
| mode = "separated", offset = 5), |
| list(desc = "Medium separation (10mm)", |
| mode = "separated", offset = 10), |
| list(desc = "Large separation (15mm)", |
| mode = "separated", offset = 15) |
| ) |
|
|
| for (i in seq_along(modes)) { |
| m <- modes[[i]] |
| svg <- generate_puzzle_svg_enhanced( |
| puzzle_structure = puzzle_2x2, |
| mode = m$mode, |
| offset = m$offset, |
| colors = c("red", "blue", "green", "orange") |
| ) |
| |
| filename <- sprintf("output/example_enhanced_mode_%d.svg", i) |
| writeLines(svg, filename) |
| cat(sprintf(" %s\n → %s\n", m$desc, filename)) |
| } |
|
|
| |
| cat("\n=== Summary ===\n") |
| cat("Generated examples demonstrate:\n") |
| cat(" 1. Laser cutting layout with optimal offset calculation\n") |
| cat(" 2. Progressive separation visualization (0, 5, 10, 20mm)\n") |
| cat(" 3. Production layout with material usage calculation\n") |
| cat(" 4. Assembly guide with color coding\n") |
| cat(" 5. Enhanced function with different modes\n") |
| cat("\nAll files saved to output/ directory\n") |
| cat("\nUse cases:\n") |
| cat(" • Laser cutting: Optimal spacing for kerf and handling\n") |
| cat(" • Education: Clear piece identification and assembly\n") |
| cat(" • Production: Efficient material usage with adequate separation\n") |
| cat(" • Documentation: Visual guides and instructions\n") |