You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/Canvas.elm
+48-13Lines changed: 48 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,57 @@
1
1
moduleCanvas
2
2
exposing
3
3
(Canvas
4
+
,DrawImageParams(..)
5
+
,DrawOp(..)
4
6
,Error
5
7
,Point
8
+
,Repeat(..)
6
9
,Size
7
-
,DrawOp(..)
8
-
,DrawImageParams(..)
9
-
, initialize
10
-
, toHtml
11
-
, draw
10
+
,Style(..)
12
11
, batch
13
-
,loadImage
12
+
,draw
14
13
, getImageData
15
14
, getSize
15
+
, initialize
16
+
, loadImage
16
17
, setSize
17
18
, toDataUrl
19
+
, toHtml
18
20
)
19
21
20
22
{-| The canvas html element is a very simple way to render 2D graphics. Check out these examples, and get an explanation of the canvas element [here](https://github.com/elm-community/canvas). Furthermore, If you havent heard of [Elm-Graphics](http://package.elm-lang.org/packages/evancz/elm-graphics/latest), I recommend checking that out first, because its probably what you need. Elm-Canvas is for when you need unusually direct and low level access to the canvas element.
21
23
24
+
22
25
# Main Types
23
-
@docs Canvas, Point, Size, DrawOp, DrawImageParams
26
+
27
+
@docs Canvas, Point, Size, DrawOp, DrawImageParams, Style, Repeat
28
+
24
29
25
30
# Basics
31
+
26
32
@docs initialize, toHtml, draw, batch
27
33
34
+
28
35
# Loading Images
36
+
29
37
@docs loadImage, Error
30
38
39
+
31
40
# Image Data
41
+
32
42
@docs getImageData, toDataUrl
33
43
44
+
34
45
# Sizing
46
+
35
47
@docs getSize, setSize
36
48
37
49
-}
38
50
39
-
importHtmlexposing (Html, Attribute)
40
-
importTaskexposing (Task)
41
-
importColorexposing (Color)
51
+
importColorexposing (Color, Gradient)
52
+
importHtmlexposing (Attribute, Html)
42
53
importNative.Canvas
54
+
importTaskexposing (Task)
43
55
44
56
45
57
{-| A `Canvas` contains image data, and can be rendered as html with `toHtml`. It is the primary type of this package.
@@ -97,10 +109,10 @@ type DrawOp
97
109
|TransformFloatFloatFloatFloatFloatFloat
98
110
|TranslatePoint
99
111
|StrokeRectPointSize
100
-
|StrokeStyleColor
112
+
|StrokeStyleStyle
101
113
|TextAlignString
102
114
|TextBaselineString
103
-
|FillStyleColor
115
+
|FillStyleStyle
104
116
|BeginPath
105
117
|BezierCurveToPointPointPoint
106
118
|QuadraticCurveToPointPoint
@@ -112,6 +124,23 @@ type DrawOp
112
124
|Batch(ListDrawOp)
113
125
114
126
127
+
{-| `Style` specifies the style to apply as a `FillStyle` or a `StrokeStyle`.
128
+
-}
129
+
type Style
130
+
=ColorColor
131
+
|PatternCanvasRepeat
132
+
|GradientGradient
133
+
134
+
135
+
{-| Specifies the axis/axes along which to replicate a pattern. For use with the `Pattern` `Style`.
136
+
-}
137
+
type Repeat
138
+
=Repeat
139
+
|RepeatX
140
+
|RepeatY
141
+
|NoRepeat
142
+
143
+
115
144
{-| The `DrawOp` `DrawImage` takes a `Canvas` and a `DrawImageParam`. We made three different `DrawImageParam`, because there are three different sets of parameters you can give the native javascript `ctx.drawImage()`. [See here for more info](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage.)
116
145
-}
117
146
type DrawImageParams
@@ -125,6 +154,7 @@ type DrawImageParams
125
154
squareCanvas : Int -> Canvas
126
155
squareCanvas length =
127
156
initialize (Size length length)
157
+
128
158
-}
129
159
initialize:Size->Canvas
130
160
initialize =
@@ -136,6 +166,7 @@ initialize =
136
166
pixelatedRender : Canvas -> Html Msg
137
167
pixelatedRender canvas =
138
168
canvas |> toHtml [ class "pixelated" ]
169
+
139
170
-}
140
171
toHtml:List (Attributemsg) ->Canvas->Htmlmsg
141
172
toHtml =
@@ -153,13 +184,14 @@ toHtml =
153
184
, LineTo p1
154
185
, Stroke
155
186
]
187
+
156
188
-}
157
189
draw:DrawOp->Canvas->Canvas
158
190
draw =
159
191
Native.Canvas.draw
160
192
161
193
162
-
{-| You dont want to apply `DrawOp` one at a time. Bundle many `DrawOp` together in one batch, using `batch`.
194
+
{-| You dont want to apply `DrawOp` one at a time, its inefficient. Bundle many `DrawOp` together in one batch, using `batch`.
0 commit comments