---
title: Tutorial 47 Building a Generative Art Print System
description: The intersection of code and creativity.
---
Tutorial 47 Building a Generative Art Print System
1. Lesson Header
- Lesson Number: 47
- Level: Master
- Title: Building a Generative Art Print System
- Estimated Duration: 90 Minutes
- Prerequisites: Lesson 35 (Visualization), Lesson 39 (Streaming), Lesson 27 (Math Gen)
- What You Will Build: A "Digital Plotter" for FDM.
2. Concept Introduction
The Plotter Workflow.
Instead of solid objects, we print Lines.
1. Generate: Create 2D art (SVG, Processing, Python).
2. Convert: Map lines to G-code.
3. Print: Use the printer as a plotter (Pen Plotter or Thin Wall Extruder).
- Pen Mode: Z-hop between lines.
- Extruder Mode: Retract between lines.
3. Machine State Explanation
The Canvas.
Bed Size (200x200mm) = Canvas Size.
Origin (0,0) = Bottom Left.
Z-Height: Constant (First Layer only) or stacked for texture.
4. Command Breakdown
- Python
turtle: Standard library for drawing. We can intercept its commands. - SVG Parsing: Reading vector graphics.
5. Minimal Working Example
The Random Walker.
Start at center.
Pick a random direction.
Move 10mm.
Repeat 100 times.
If out of bounds, bounce back.
6. Visual Representation
Interactive preview is available in the interactive reader.
7. Build Exercise
Task: Create a "Generative Landscape".
1. Generate Perlin Noise terrain lines.
2. Convert to G-code.
3. Add a "Sun" (Circle) in the background.
4. Optimize travel moves (Lesson 33).
Algorithm:
For y from 10 to 190 step 10:
Line from (10, y) to (190, y).
Perturb Y-coordinate with noise(x, y) * amplitude.
Use G0 to jump between lines.
8. Deep Insight Section
Hatching & Shading.
How to represent darkness with lines?
- Cross-Hatching: Grid density.
- Stippling: Dot density.
- Variable Width: Flow rate modulation (Lesson 19).
Darker = Wider Line (E higher).
Lighter = Thinner Line (E lower).
9. Common Failure Modes
- Stringing: If you jump 1000 times, you get 1000 strings. Use aggressive retraction (
G1 E-5 F3000) and Z-hop (G1 Z0.4). - Bed Adhesion: Single lines peel off easily. Print slow (
F1000) and hot (210C).
10. Real-World Application
Axidraw (Pen Plotters).
Artists use G-code (or HPGL) to drive pen plotters.
The logic is identical to FDM printing, just Z-Up/Down instead of E-Push/Pull.
Many FDM users attach a pen to their print head to convert it into a plotter.
11. Final Clean Version
The Landscape Generator:
import math
import random
def noise(x):
return math.sin(x * 0.05) * 10 + math.sin(x * 0.2) * 2
filename = "landscape.gcode"
width = 200
height = 200
lines = 20
with open(filename, "w") as f:
f.write("G28\nG1 Z0.2 F3000\n")
for i in range(lines):
base_y = (i / lines) * height
# Start of line
f.write(f"G0 X0 Y{base_y} F9000\n") # Travel
f.write("G1 E0.5 F1500\n") # Prime
# Draw segments
for x in range(0, width, 2):
y = base_y + noise(x + i * 10)
# Clamp Y
if y < 0: y = 0
if y > height: y = height
f.write(f"G1 X{x} Y{y:.3f} E0.05\n")
f.write("G1 E-0.5 F3000\n") # Retract
f.write("G0 Z0.4\n") # Hop
f.write("G0 Z0.2\n") # Land
f.write("G28 X0 Y0\n")
12. Stretch Challenge
Challenge: Implement Variable Width Shading.
Load a grayscale image.
Rasterize it into lines.
Vary the E value (Flow) based on pixel darkness.
Black = E0.1. White = E0.0.
This creates a "Lithophane" effect but with line thickness instead of height.