From e0d49cdf57e7561c06fc2e64c382b0956e3b4cbb Mon Sep 17 00:00:00 2001 From: jgk Date: Tue, 23 Mar 2021 16:05:37 +0100 Subject: [PATCH] Refactor low light display --- src/Dodge/WorldEvent/Flash.hs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Dodge/WorldEvent/Flash.hs b/src/Dodge/WorldEvent/Flash.hs index 972b742ec..bcf5ad259 100644 --- a/src/Dodge/WorldEvent/Flash.hs +++ b/src/Dodge/WorldEvent/Flash.hs @@ -10,6 +10,8 @@ import Dodge.WorldEvent.HelperParticle import Picture import Geometry +import Data.Maybe (maybeToList) + import Control.Lens flareAt' :: Color -> Float -> Float -> Point2 -> World -> World @@ -23,13 +25,15 @@ lowLightColAt col alphay p w = foldr (lowLightWidthHit 10 5 col alphay p) w ps where ps = map ((+.+) p) $ nRaysRad 20 30 lowLightWidthForHit :: Float -> Float -> Color -> Float -> Int -> Point2 -> Point2 -> World -> World -lowLightWidthForHit len wdth col alphay t a b w - = case thingsHitLongLine a b w of - ((p, E3x2 wall):_) - -> over particles' ((:) (wallGlareFor t len wdth col alphay p wall)) w - ((p, E3x1 cr):_) - -> over particles' ((:) (crGlareFor t wdth col alphay p cr)) w - _ -> w +lowLightWidthForHit len wdth col alphay t a b w = w & particles' %~ (maybeToList glareLine ++) + where glareLine = glareBetween t len wdth col alphay a b w + +glareBetween :: Int -> Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> Maybe Particle' +glareBetween 0 _ _ _ _ _ _ _ = Nothing +glareBetween t len wdth col alphay a b w + = Just $ Particle' {_ptPict' = lowLightPic len wdth col alphay a b w + ,_ptUpdate' = \ w' _ -> (w',glareBetween (t-1) len wdth col alphay a b w') + } lowLightPic :: Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> Picture lowLightPic len wdth col alphay a b w