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
Changed the readme a bit. Made some written content better, and brought the primary example up to date with the 0.3.0 api. Fixed a bug in the examples elm-package
Copy file name to clipboardExpand all lines: readme.md
+19-27Lines changed: 19 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,43 +15,38 @@ Checkout the [examples](https://github.com/Elm-Canvas/examples).
15
15
This code ..
16
16
17
17
```Elm
18
-
moduleMainexposing (..)
19
-
20
18
importHtmlexposing (Html)
21
-
importCanvasexposing (Size, Point, DrawOp(..))
22
-
importColorexposing (Color)
23
-
19
+
importCanvasexposing (Size, Point, Canvas, DrawOp(..))
20
+
importColor
24
21
25
22
main:Htmla
26
23
main =
24
+
Canvas.toHtml [] blueRectangle
25
+
26
+
27
+
blueRectangle:Canvas
28
+
blueRectangle =
27
29
Canvas.initialize (Size400300)
28
-
|>Canvas.draw drawing
29
-
|>Canvas.toHtml []
30
+
|>Canvas.draw fillBlue
30
31
31
32
32
-
drawing:DrawOp
33
-
drawing =
34
-
[ rectangle (Point1010)Color.red
35
-
, rectangle (Point3030)(Color.rgba 002550.5)
36
-
,FillStyleColor.white
37
-
,Font"48px sans-serif"
38
-
,FillText"Elm Canvas"(Point50120)
33
+
fillBlue:DrawOp
34
+
fillBlue =
35
+
[FillStyleColor.blue
36
+
,FillRect(Point00) size
39
37
]
40
38
|>Canvas.batch
41
39
42
40
43
-
rectangle:Point->Color->DrawOp
44
-
rectangle point color =
45
-
[BeginPath
46
-
,Rect point (Size370270)
47
-
,FillStyle color
48
-
,Fill
49
-
]
50
-
|>Canvas.batch
41
+
size:Size
42
+
size =
43
+
Size400300
44
+
51
45
52
46
53
47
-- Canvas.initialize : Size -> Canvas
54
-
-- Canvas.batch : List DrawOp -> Canvas -> Canvas
48
+
-- Canvas.batch : List DrawOp -> DrawOp
49
+
-- Canvas.draw : DrawOp -> Canvas -> Canvas
55
50
-- Canvas.toHtml : List (Attribute a) -> Canvas -> Html a
56
51
```
57
52
@@ -74,10 +69,7 @@ Almost all the properties and methods of the 2d canvas context are available in
74
69
75
70
We made this package for a some really unusual use cases, which likely arent your use case. Think hard before choosing to use Elm-Canvas, you probably dont need it. If you have image assets you want to move around the screen (like in a video game), then [evancz/elm-graphics](https://github.com/evancz/elm-graphics) and [elm-community/webgl](https://github.com/elm-community/webgl) are better options. If you want to render vector graphics use [elm-svg](http://package.elm-lang.org/packages/elm-lang/svg/latest). You should use the canvas when you absolutely need to change pixel values in a very low level way, which is an unusual project requirement.
76
71
77
-
In making this package, we had various design considerations. On one hand we wanted to make things clearer and simpler than the native canvas API actually is (theres a lot of room for improvement on that front). On the other hand, we knew that there are other packages out there that are clear and simple, and that anyone who needs Elm-Canvas likely wasnt satisfied with a clear and simple API. For Elm-Canvas, we are just trying to expose as much of the native canvas API as we can into Elm. We are making no presumption about why a clear and simple rendering API was not sufficient for you.
78
-
79
-
That said, we didnt make a package so sparse as the only expose the native API. The events submodule exposes some useful html event handlers that return the exact position of mouse events. Doing pixel-perfect drawing is notoriously complicated, so we made a pixel submodule to make that more straight forward.
80
-
72
+
In making this package, we had various design considerations. On one hand we wanted to make things clearer and simpler than the native canvas API actually is (theres a lot of room for improvement on that front). On the other hand, the use cases we had in mind for Elm-Canvas are some what broad. For Elm-Canvas, we are just trying to expose as much of the native canvas API as we can into Elm. Elm-Canvas makes no presumption about a what your specific use case is, but we figure direct access to the canvas api will help you get to where you need.
0 commit comments