Skip to content

Instantly share code, notes, and snippets.

@5outh
Created April 6, 2018 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5outh/d0b85bbad6cd1dc5b6712ec2a7fd5c06 to your computer and use it in GitHub Desktop.
Save 5outh/d0b85bbad6cd1dc5b6712ec2a7fd5c06 to your computer and use it in GitHub Desktop.
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