Rename Form to Collage. Add the LineStyle module.
This commit is contained in:
parent
d10dcdc820
commit
ea4fe54a2a
3 changed files with 95 additions and 85 deletions
64
core/Graphics/Collage.elm
Normal file
64
core/Graphics/Collage.elm
Normal file
|
@ -0,0 +1,64 @@
|
|||
|
||||
module Graphics.Collage where
|
||||
|
||||
import Either
|
||||
import Graphics.LineStyle
|
||||
import Geometry
|
||||
|
||||
data Transform
|
||||
= Rotate Float
|
||||
| Move Float Float
|
||||
| Scale Float Float
|
||||
| Transform Float Float Float Float Float Float
|
||||
|
||||
type Form = { transforms : [Transform], form : BasicForm }
|
||||
|
||||
data FillStyle
|
||||
= NoFill
|
||||
| Solid Color
|
||||
| Texture String
|
||||
| Gradient Gradient
|
||||
|
||||
data BasicForm
|
||||
= FLine LineStyle Line
|
||||
| FShape (Either LineStyle FillStyle) Shape
|
||||
| FImage Int Int (Int,Int) String
|
||||
| FElement Element
|
||||
| FGroup [Form]
|
||||
|
||||
fill style shape = Form [] (FShape (Right style) shape)
|
||||
|
||||
filled : Color -> Shape -> Form
|
||||
filled color shape = fill (Solid color) shape
|
||||
|
||||
textured : String -> Shape -> Form
|
||||
textured src shape = fill (Texture src) shape
|
||||
|
||||
gradient : Gradient -> Shape -> Form
|
||||
gradient grad shape = fill (Gradient grad) shape
|
||||
|
||||
outline style shape = Form [] (FShape (Left style) shape)
|
||||
trace style line = Form [] (FLine style line)
|
||||
|
||||
sprite w h pos src = Form [] (FImage w h pos src)
|
||||
toForm e = Form [] (FElement e)
|
||||
|
||||
group fs = Form [] (FGroup fs)
|
||||
|
||||
add t f = { transforms = t :: f.transforms, form = f.form }
|
||||
|
||||
radians t = t
|
||||
degrees dep = pi * deg / 180
|
||||
rotations rot = 2 * pi * rot
|
||||
|
||||
rotate t = add (Rotate t)
|
||||
|
||||
scale s = add (Scale s s)
|
||||
scaleX s = add (Scale s 1)
|
||||
scaleY s = add (Scale 1 s)
|
||||
|
||||
move x y = add (Move x y)
|
||||
moveX x = add (Move x 0)
|
||||
moveY y = add (Move 0 y)
|
||||
|
||||
transform a b c d e f = add (Transform a b c d e f)
|
|
@ -1,85 +0,0 @@
|
|||
|
||||
module Graphics.Collage where
|
||||
|
||||
import Either
|
||||
import Graphics.LineStyle
|
||||
import Geometry
|
||||
|
||||
data Transform
|
||||
= Rotate Float
|
||||
| Move Float Float
|
||||
| Scale Float Float
|
||||
| Transform Float Float Float Float Float Float
|
||||
|
||||
data Form = Form [Transform] BasicForm
|
||||
|
||||
data FillStyle
|
||||
= NoFill
|
||||
| Solid Color
|
||||
| Texture String
|
||||
| Gradient Gradient
|
||||
|
||||
data BasicForm
|
||||
= FLine LineStyle Line
|
||||
| FShape (Either LineStyle FillStyle) Shape
|
||||
| FImage Int Int Int Int String
|
||||
| FElement Element
|
||||
| FGroup [Form]
|
||||
|
||||
fill style shape = FShape (Right style) shape
|
||||
|
||||
filled : Color -> Shape -> Form
|
||||
filled color shape = fill (Solid color) shape
|
||||
|
||||
textured : String -> Shape -> Form
|
||||
textured src shape = fill (Texture src) shape
|
||||
|
||||
gradient : Gradient -> Shape -> Form
|
||||
gradient grad shape = fill (Gradient grad) shape
|
||||
|
||||
outline style shape = FShape (Left style) shape
|
||||
trace = FLine
|
||||
|
||||
|
||||
linearGradient stops start end = setFillStyle (LinearGradient stops start end)
|
||||
radialGradient stops innerP innerR outerP outerR =
|
||||
setStyle (RadialGradient stops innerP innerR outerP outerR)
|
||||
|
||||
plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
|
||||
fillStyle=...,
|
||||
dashing=[], dashOffset=0 }
|
||||
|
||||
solid c = Form [] . FLine c
|
||||
dotted c = Form [] . FLine c
|
||||
dashed c = Form [] . FLine c
|
||||
lineStyle = Form [] . FLine
|
||||
|
||||
|
||||
filled clr shp = Form [] (FShape shp)
|
||||
outlined clr shp = Form [] (FShape shp)
|
||||
customOutline pattern clr (Shape ps pos) =
|
||||
Form [] (FShape (CustomOutline pattern) clr (Shape ps pos))
|
||||
textured src (Shape ps pos) = Form [] (FShape (Textured src) black (Shape ps pos))
|
||||
|
||||
fromLine = FLine
|
||||
fromShape = FShape
|
||||
fromElement = FElement
|
||||
|
||||
sprite w h pos src = Form 0 1 pos (FImage w h src)
|
||||
toForm pos e = Form 0 1 pos (FElement e)
|
||||
|
||||
addTransform t (Form ts form) = Form (t:ts) form
|
||||
|
||||
rotateRad rad = addTransform $ Rotate rad
|
||||
rotateDeg deg = addTransform $ Rotate (pi * deg / 180)
|
||||
rotate rot = addTransform $ Rotate (2 * pi * rot)
|
||||
|
||||
scale s = addTransform (Scale s s)
|
||||
scaleX s = addTransform (Scale s 1)
|
||||
scaleY s = addTransform (Scale 1 s)
|
||||
|
||||
move x y = addTransform (Move x y)
|
||||
moveX x = addTransform (Move x 0)
|
||||
moveY y = addTransform (Move 0 y)
|
||||
|
||||
transform a b c d e f = addTransform (Transform a b c d e f)
|
31
core/Graphics/LineStyle.elm
Normal file
31
core/Graphics/LineStyle.elm
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
module Graphics.LineStyle where
|
||||
|
||||
import Graphics.Color
|
||||
|
||||
data LineCap = Butt | Round | Square
|
||||
data LineJoin = Round | Bevel | Miter
|
||||
|
||||
type LineStyle = {
|
||||
color : Color,
|
||||
width : Float,
|
||||
cap : LineCap,
|
||||
join : LineJoin,
|
||||
miterLimit : Float,
|
||||
dashing : [Int],
|
||||
dashOffset : Int
|
||||
}
|
||||
|
||||
default = {
|
||||
color = black,
|
||||
width = 1,
|
||||
cap = Butt,
|
||||
join = Miter,
|
||||
dashing = [],
|
||||
dashOffset = 0,
|
||||
miterLimit = 10
|
||||
}
|
||||
|
||||
solid clr = { default | color <- clr }
|
||||
dashed clr = { default | color <- clr, dashing = [8,4] }
|
||||
dotted clr = { default | color <- clr, dashing = [3,3] }
|
Loading…
Reference in a new issue