Skip to content

Instantly share code, notes, and snippets.

@mnmly
Forked from j4mie/example.html
Created August 23, 2011 05:57
Show Gist options
  • Save mnmly/1164446 to your computer and use it in GitHub Desktop.
Save mnmly/1164446 to your computer and use it in GitHub Desktop.
A tiny shim for Paper.js/CoffeeScript prototyping
window.stainedPaper = function (func) {
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
paper.setup(canvas);
func.call(paper);
};
<!DOCTYPE html>
<title>CoffeeScript/Paper.js</title>
<script src="https://raw.github.com/paperjs/paper.js/master/dist/paper.js"></script>
<script src="https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"></script>
<script src="https://raw.github.com/gist/1164446/coffee-stained-paper.js"></script>
<script type="text/coffeescript">
stainedPaper ->
    path = new @Path()
    # Give the stroke a color
    path.strokeColor = 'black'
    start = new @Point(100, 100)
    # Move to start and draw a line from there
    path.moveTo(start)
    # Note that the plus operator on Point objects does not work
    # in JavaScript. Instead, we need to call the add() function:
    path.lineTo start.add([ 200, -50 ])
    # Draw the view now:
    @view.draw()
rect = new @Path.Rectangle([100, 50], [10, 100])
rect.strokeColor = 'black'
@view.onFrame = (event) ->
# On each frame, rotate the path by 3 degrees:
rect.rotate(3)
</script>
@mnmly
Copy link
Author

mnmly commented Aug 23, 2011

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