Skip to content

Instantly share code, notes, and snippets.

@5outh
Created Apr 6, 2018
Embed
What would you like to do?
taperGeometric
:: Double
-- ^ percentage to decrease by each iteration
-> Double
-- ^ Starting width
-> [V2 Double]
-- ^ The path
-> [(V2 Double, Double)]
-- ^ The path, augmented with line widths
taperGeometric percentage startingWidth path = zip path widths
where
-- TODO: Probably want to use DList here? But can easily just reverse the path for now
widths = iterate (* percentage) startingWidth
-- left biased
taperedPair (v, s) (u, t) = (LineSegment v u, s)
renderSketch :: Generate ()
renderSketch = do
fillScreenHsv charcoal
let rects' = flip map ((,) <$> [0,20..80] <*> [0,20..80]) $ \(x,y) -> Rect x y 20 20
rects <- shuffleM rects'
for_ (zip [3..] rects) $ \(n, rect) -> do
path <- chaikinN 5 <$> replicateM n (genPointIn (scaleRect 0.8 rect))
let
tapered = taperGeometric 0.99 1 path
cairo $ setLineCap LineCapRound
for_ (pairsWith taperedPair tapered) $ \(segment, size) -> do
cairo $ do
setLineWidth size
drawLineSegment segment
setSourceHsv (lighten (1 - size) linen) *> stroke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment