Skip to content

Commit b1a077d

Browse files
committed
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
1 parent 114e3f1 commit b1a077d

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

examples/0-simple-render.elm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Main exposing (..)
22

33
import Html exposing (Html)
4-
import Canvas exposing (Size, Point, DrawOp(..))
4+
import Canvas exposing (Size, Point, Canvas, DrawOp(..))
55
import Color exposing (Color)
66

77

@@ -30,4 +30,4 @@ rectangle point color =
3030
, FillStyle color
3131
, Fill
3232
]
33-
|> Canvas.batch
33+
|> Canvas.batch

examples/elm-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"."
88
],
99
"exposed-modules": [
10-
"Canvas",
10+
"Canvas"
1111
],
1212
"native-modules": true,
1313
"dependencies": {

readme.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,38 @@ Checkout the [examples](https://github.com/Elm-Canvas/examples).
1515
This code ..
1616

1717
``` Elm
18-
module Main exposing (..)
19-
2018
import Html exposing (Html)
21-
import Canvas exposing (Size, Point, DrawOp(..))
22-
import Color exposing (Color)
23-
19+
import Canvas exposing (Size, Point, Canvas, DrawOp(..))
20+
import Color
2421

2522
main : Html a
2623
main =
24+
Canvas.toHtml [] blueRectangle
25+
26+
27+
blueRectangle : Canvas
28+
blueRectangle =
2729
Canvas.initialize (Size 400 300)
28-
|> Canvas.draw drawing
29-
|> Canvas.toHtml []
30+
|> Canvas.draw fillBlue
3031

3132

32-
drawing : DrawOp
33-
drawing =
34-
[ rectangle (Point 10 10) Color.red
35-
, rectangle (Point 30 30) (Color.rgba 0 0 255 0.5)
36-
, FillStyle Color.white
37-
, Font "48px sans-serif"
38-
, FillText "Elm Canvas" (Point 50 120)
33+
fillBlue : DrawOp
34+
fillBlue =
35+
[ FillStyle Color.blue
36+
, FillRect (Point 0 0) size
3937
]
4038
|> Canvas.batch
4139

4240

43-
rectangle : Point -> Color -> DrawOp
44-
rectangle point color =
45-
[ BeginPath
46-
, Rect point (Size 370 270)
47-
, FillStyle color
48-
, Fill
49-
]
50-
|> Canvas.batch
41+
size : Size
42+
size =
43+
Size 400 300
44+
5145

5246

5347
-- Canvas.initialize : Size -> Canvas
54-
-- Canvas.batch : List DrawOp -> Canvas -> Canvas
48+
-- Canvas.batch : List DrawOp -> DrawOp
49+
-- Canvas.draw : DrawOp -> Canvas -> Canvas
5550
-- Canvas.toHtml : List (Attribute a) -> Canvas -> Html a
5651
```
5752

@@ -74,10 +69,7 @@ Almost all the properties and methods of the 2d canvas context are available in
7469

7570
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.
7671

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.
8173

8274
## Contributing
8375

0 commit comments

Comments
 (0)