Skip to content

Commit

Permalink
start radial gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Nov 10, 2013
1 parent 88944c6 commit 933a4dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/Diagrams/TwoD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ module Diagrams.TwoD
, sized, sizedAs

-- * Textures
, Texture(..), SpreadMethod(..), GradientStop
, LGradient(..), lGradStops, lGradTrans, lGradStart, lGradEnd, lGradSpreadMethod
, Texture(..), SpreadMethod(..), GradientStop, mkStops

, LGradient(..), lGradStops, lGradTrans, lGradStart, lGradEnd
, lGradSpreadMethod, defaultLG, _LG

, RGradient(..)
, rGradStops, rGradTrans, rGradRadius, rGradCenter, rGradFocus, rGradSpreadMethod
, getFillTexture, fillTexture
, getFillTexture, fillTexture, defaultRG, _RG

-- ** Colors
, fillColorT, fcT, fcAT, recommendFillColorT
Expand Down
44 changes: 31 additions & 13 deletions src/Diagrams/TwoD/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
-- Maintainer : diagrams-discuss@googlegroups.com
--
-- Diagrams may have /attributes/ which affect the way they are
-- rendered. This module defines Gradients and Colors in TwoD.
-- rendered. This module defines Gradients and Colors (Textures) in two
-- dimensions. Some of these functions are carbon copies of funtions defined
-- in Diagrams.Attributes, provided for backward compatability. Functions
-- ending in T like /fcT/ have counterparts without the T, e.g. /fc/.
--
-----------------------------------------------------------------------------

Expand All @@ -25,7 +28,7 @@ module Diagrams.TwoD.Attributes (
, lineLGradient, lineRGradient

-- * Texture
, Texture(..), _SC, _LG, _RG
, Texture(..), _SC, _LG, _RG, defaultLG, defaultRG, mkStops

-- * Line texture
, LineTexture(..), getLineTexture, lineTexture
Expand All @@ -48,7 +51,6 @@ import Diagrams.TwoD.Types (T2, R2, P2, mkP2)
import Control.Lens (makeLenses, makePrisms, (&), (%~))

import Data.Colour hiding (AffineSpace)
import Data.Colour.Names (white)
import Data.Default.Class
import Data.Typeable

Expand All @@ -68,16 +70,6 @@ data LGradient = LGradient
, _lGradTrans :: T2
, _lGradSpreadMethod :: SpreadMethod }

instance Default LGradient where
def = LGradient
{ _lGradStops = [ (SomeColor (black :: Colour Double), 0, 1)
, (SomeColor (white :: Colour Double), 1, 1)]
, _lGradStart = mkP2 0 0
, _lGradEnd = mkP2 1 0
, _lGradTrans = scaling 1
, _lGradSpreadMethod = GradPad
}

makeLenses ''LGradient

-- | Radial Gradient
Expand All @@ -96,6 +88,28 @@ data Texture = SC SomeColor | LG LGradient | RG RGradient

makePrisms ''Texture

defaultLG :: Texture
defaultLG = LG (LGradient
{ _lGradStops = []
, _lGradStart = mkP2 0 0
, _lGradEnd = mkP2 1 0
, _lGradTrans = scaling 1
, _lGradSpreadMethod = GradPad
})

defaultRG :: Texture
defaultRG = RG (RGradient
{ _rGradStops = []
, _rGradRadius = 1
, _rGradCenter = mkP2 0 0
, _rGradFocus = mkP2 0 0
, _rGradTrans = scaling 1
, _rGradSpreadMethod = GradPad
})

mkStops :: Color c => [(c, Double, Double)] -> [GradientStop]
mkStops s = map (\(x, y, z) -> (SomeColor x, y, z)) s

newtype LineTexture = LineTexture (Last Texture)
deriving (Typeable, Semigroup)
instance AttributeClass LineTexture
Expand Down Expand Up @@ -136,6 +150,10 @@ lineRGradient g = lineTexture (RG g)

newtype FillTexture = FillTexture (Recommend (Last Texture))
deriving (Typeable, Semigroup)

--instance Typeable FillTexture where
-- typeOf _ = typeOf (FillColor undefined)

This comment has been minimized.

Copy link
@jeffreyrosenbluth

jeffreyrosenbluth Nov 11, 2013

Author Member

This was a failed attempt at a hack to force FillTexture and FillColor to be part of the same semigroup.
I still wonder if it's possible?


instance AttributeClass FillTexture

type instance V FillTexture = R2
Expand Down

0 comments on commit 933a4dd

Please sign in to comment.