Skip to content

Commit

Permalink
Add random waviness to the squares using Perlin noise
Browse files Browse the repository at this point in the history
  • Loading branch information
James Carlson committed Jul 4, 2019
1 parent 64e8300 commit 7e5eeed
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,36 @@ renderQuad Quad{..} = renderClosedPath [quadA, quadB, quadC, quadD]
darkGunmetal :: Double -> Render ()
darkGunmetal = hsva 170 0.30 0.16

quadAddNoise :: Quad -> Generate Quad
quadAddNoise Quad{..} = do
perlinSeed <- fromIntegral <$> asks worldSeed

let
perlinOctaves = 5
perlinScale = 0.1
perlinPersistance = 0.5
perlinNoise
= P.perlin (round perlinSeed) perlinOctaves perlinScale perlinPersistance
perlin2d (V2 x y)
= P.noiseValue perlinNoise (x + perlinSeed, y + perlinSeed, perlinSeed) - 0.5
addNoise v = let noise = perlin2d v in v ^+^ V2 (noise / 5) (noise / 8)

pure $ Quad
(addNoise quadA)
(addNoise quadB)
(addNoise quadC)
(addNoise quadD)

renderSketch :: Generate ()
renderSketch = do
fillScreen eggshell 1

cairo $ setLineWidth 0.15

quads <- genQuadGrid
noisyQuads <- traverse quadAddNoise quads

cairo $ for_ quads $ \quad -> do
cairo $ for_ noisyQuads $ \quad -> do
renderQuad quad
darkGunmetal 1 *> stroke

Expand Down

0 comments on commit 7e5eeed

Please sign in to comment.