# Save as PNG with ggsaveggsave("my_puzzle.png", width =8, height =6, dpi =300)
library(jigsawR)# Generate a 3x4 puzzleresult <-generate_puzzle(type ="rectangular",grid =c(3, 4), # 3 rows, 4 columnssize =c(300, 400), # height=300mm, width=400mm (landscape)seed =42, # For reproducibilityfill_palette ="viridis")# Check the resultn_pieces <-length(result$pieces)canvas_w <- result$canvas_size[1]canvas_h <- result$canvas_size[2]cli::cli_alert_info("Generated {n_pieces} pieces")cli::cli_alert_info("Canvas size: {canvas_w} x {canvas_h} mm")
Render the SVG:
render_puzzle_preview(result)
Save your puzzle:
# Save as SVG (for laser cutting, etc.)writeLines(result$svg_content, "my_puzzle.svg")# Save as PNG (requires rsvg)rsvg::rsvg_png(charToRaw(result$svg_content), "my_puzzle.png", width =800)
TipWhich approach should I use?
API: Best for manufacturing (laser cutting, 3D printing) and when you need raw SVG output
ggpuzzle: Best for visualization, data exploration, and when you want ggplot2’s styling options
Parameter Mapping
The two approaches use equivalent parameters:
API (generate_puzzle())
ggpuzzle (geom_puzzle_rect())
type = "rectangular"
Use geom_puzzle_rect()
grid = c(3, 4)
rows = 3, cols = 4
size = c(300, 400)
height = 300, width = 400
seed = 42
seed = 42
tabsize = 6
tabsize = 6
offset = 10
offset = 10
Puzzle Types
1. Rectangular
Classic jigsaw with interlocking tabs on all sides.