hoop '4x4'
seed 7

import std.stitchcraft.gradientrows as gradientrows

// SEW-OUT ASSUMPTIONS (4x4 hoop): stable woven, one medium tearaway
// stabilizer, polyester 40 wt, NM 75 embroidery needle, no topping.

// --- Gradient band ---
let w = 76       // [40:90] band width (mm)
let h = 57       // [20:80] band height (mm)
let pitch = 0.4  // [0.4:0.05:1.4] combined line spacing (mm)
let gamma = 1.7  // [0.4:0.1:2.5] gradient curve (1 = linear)
let wobble = 0   // [0:0.05:0.6] hand-stitch jitter (mm)

palette ['#1b6ca8', '#e94560']
background '#f4efe6'
fabric 'woven'
threadprofile 'polyester-40wt'
needle 75
stabilizer 'tearaway'
topping 0
stitchlen 2.5

// `v` runs from 0 to 1 across the row-seeding axis. The helper error-diffuses
// this color-B share so every candidate row belongs to exactly one color.
def fade(v) [
  return pow(v, gamma)
]

def sewrows(rows) [
  for row in rows [
    up setpos(first(row)) down
    sewpath(resample(row, 2.5))
  ]
]

let region = [
  [0 - w / 2, 0 - h / 2],
  [w / 2, 0 - h / 2],
  [w / 2, h / 2],
  [0 - w / 2, h / 2]
]
let groups = gradientrows(region, 90, pitch, @fade)

color '#1b6ca8'
humanize wobble [ sewrows(groups[0]) ]
trim

color '#e94560'
// Reverse the second group so it starts at its dense end, near where A finished.
humanize wobble [ sewrows(reverse(groups[1])) ]
trim
