Created
April 6, 2018 12:57
-
-
Save 5outh/d0b85bbad6cd1dc5b6712ec2a7fd5c06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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