Skip to content

Instantly share code, notes, and snippets.

@zcstarr
Created May 24, 2015 23:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zcstarr/0f0fa9082550e4520849 to your computer and use it in GitHub Desktop.
Save zcstarr/0f0fa9082550e4520849 to your computer and use it in GitHub Desktop.
Quick fix for elm-lang example Stamper Gist
<html>
<head>
<title>Embedding Elm in HTML!</title>
<script type="text/javascript" src="elm.js"></script>
</head>
<body>
<h1>Stamper</h1>
<div id="stamper" style="width:50%; height:400px;"></div>
</body>
<script type="text/javascript">
var stamperDiv = document.getElementById('stamper');
Elm.embed(Elm.Stamper, stamperDiv);
</script>
</html>
module Stamper where
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import List
import List exposing ((::))
import Mouse
import Signal
import Window
main : Signal Element
main =
Signal.map2 renderStamps Window.dimensions clickLocations
clickLocations : Signal (List (Int,Int))
clickLocations =
Signal.foldp (::) [] (Signal.sampleOn Mouse.clicks Mouse.position)
renderStamps : (Int,Int) -> List (Int,Int) -> Element
renderStamps (w,h) locs =
let pentagon (x,y) =
ngon 5 20
|> filled (hsla (toFloat x) 0.9 0.6 0.7)
|> move (toFloat x - toFloat w / 2, toFloat h / 2 - toFloat y)
|> rotate (toFloat x)
in
layers
[ collage w h (List.map pentagon locs)
, show "Click to stamp a pentagon."
]
@zcstarr
Copy link
Author

zcstarr commented May 24, 2015

Just a quick fix for an elm example referencing
http://elm-lang.org/edit/examples/Intermediate/Stamps.elm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment