simplified Hello
This commit is contained in:
parent
551b0a3a4e
commit
173164611b
2 changed files with 9 additions and 82 deletions
90
Hello.elm
90
Hello.elm
|
@ -1,103 +1,29 @@
|
|||
-- Welcome to your first Elm program!
|
||||
-- Let's go through some basic syntax to get you up to speed.
|
||||
-- Welcome to your first Elm program
|
||||
|
||||
-- This is how you assign a value or function to a name
|
||||
introString : String
|
||||
introString = "Hello, World!"
|
||||
-- Read up on syntax at http://elm-lang.org/learn/Syntax.elm
|
||||
|
||||
{- Function application works without parentheses. It's left associative.
|
||||
-- Learn about Elm's functions in the Catalog:
|
||||
-- http://library.elm-lang.org/catalog/elm-lang-Elm/0.13.0/
|
||||
|
||||
Elements are Elm's graphical unit. On the highest level, an Elm program
|
||||
is a manipulation of Elements which go out to screen.
|
||||
-}
|
||||
helloWorld : Element
|
||||
helloWorld = asText introString -- asText : anything -> Element
|
||||
helloWorld = asText "Hello, World!"
|
||||
|
||||
|
||||
{- Let-expressions are indentation sensative, you can set temporary
|
||||
values that can be used anywhere in the let-expression. The expression
|
||||
following 'in' is the return value.
|
||||
-}
|
||||
welcomeGraphics : Element
|
||||
welcomeGraphics =
|
||||
let dimensions = 90
|
||||
imgSize = 30
|
||||
elmLogo = image imgSize imgSize "http://elm-lang.org/logo.png"
|
||||
elmsPerSide = dimensions // imgSize
|
||||
row = flow right (map (always elmLogo) [1..elmsPerSide])
|
||||
row = flow right (repeat elmsPerSide elmLogo)
|
||||
in
|
||||
flow down (repeat elmsPerSide row)
|
||||
|
||||
-- main is where Elements go out to screen.
|
||||
-- A flow lets you group Elements together such that they order in a certain way.
|
||||
|
||||
main : Element
|
||||
main =
|
||||
flow down [
|
||||
helloWorld,
|
||||
welcomeGraphics,
|
||||
elmHeart
|
||||
welcomeGraphics
|
||||
]
|
||||
|
||||
{- You can do more complex graphics in Elm with a collage of forms.
|
||||
A collage is a list of forms that are placed within a bounded region.
|
||||
A form is a shape or element that can then be graphically manipulated.
|
||||
-}
|
||||
elmHeart : Element
|
||||
elmHeart =
|
||||
let root = sqrt 2 / 2
|
||||
scaleFactor = 100
|
||||
largeTrianglePoints = [(0,0), (root,0), (0,root)]
|
||||
largeTriangle = polygon largeTrianglePoints
|
||||
mediumTrianglePoints = [(0,0), (0.5,0), (0,0.5)]
|
||||
mediumTriangle = polygon mediumTrianglePoints
|
||||
smallTrianglePoints = [(0,0), (root/2,0), (0,root/2)]
|
||||
smallTriangle = polygon smallTrianglePoints
|
||||
elmSquare = square (root/2)
|
||||
parallelogramPoints = [(0,0), (0.5,0), (0.25,0.25), (-0.25,0.25)]
|
||||
parallelogram = polygon parallelogramPoints
|
||||
|
||||
bigBlue = largeTriangle
|
||||
|> filled lightBlue
|
||||
|> scale scaleFactor
|
||||
bigGrey = largeTriangle
|
||||
|> filled (rgb 109 118 138)
|
||||
|> scale scaleFactor
|
||||
midBlue = mediumTriangle
|
||||
|> filled lightBlue
|
||||
|> scale scaleFactor
|
||||
smallOrange1 = smallTriangle
|
||||
|> filled orange
|
||||
|> scale scaleFactor
|
||||
smallOrange2 = smallTriangle
|
||||
|> filled orange
|
||||
|> scale scaleFactor
|
||||
greenSq = elmSquare
|
||||
|> filled green
|
||||
|> scale scaleFactor
|
||||
greenParallelogram = parallelogram
|
||||
|> filled green
|
||||
|> scale scaleFactor
|
||||
in
|
||||
collage 200 200 [ -- we've made the tangram shapes
|
||||
greenSq -- now we can place them to make
|
||||
|> moveY -70 -- a picture. Try making your own
|
||||
|> rotate (pi / 4), -- tangram picture!
|
||||
smallOrange1
|
||||
|> moveY -45
|
||||
|> rotate (3 * pi / 4),
|
||||
bigBlue
|
||||
|> move (25,-70)
|
||||
|> rotate (pi / 4),
|
||||
midBlue
|
||||
|> move (-25,-20)
|
||||
|> rotate pi,
|
||||
bigGrey
|
||||
|> move (-25, 30)
|
||||
|> rotate (-3 * pi / 4),
|
||||
greenParallelogram
|
||||
|> move (25,-20),
|
||||
smallOrange2
|
||||
|> move (24, 30)
|
||||
|> rotate (-3 * pi / 4)
|
||||
]
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@ display (w',h') mario =
|
|||
| otherwise -> "stand"
|
||||
|
||||
src = "imgs/mario/"++ verb ++ "/" ++ show mario.dir ++ ".gif"
|
||||
--src = "http://i188.photobucket.com/albums/z137/DreamsInMotion/Video%20Game%20Pictures/Metroid/samus-1.gif"
|
||||
|
||||
marioImage = image 35 35 src
|
||||
|
||||
|
|
Loading…
Reference in a new issue