Created
September 15, 2011 16:36
-
-
Save oleander/1219739 to your computer and use it in GitHub Desktop.
Auto drawer for Raphaël.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> | |
<script type="text/javascript" charset="utf-8" src="https://raw.github.com/DmitryBaranovskiy/raphael/master/raphael.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(function() { | |
var canvas = $("#canvas"); | |
var paper = Raphael(document.getElementById("canvas"), canvas.height(), canvas.width()); | |
var clickArea = $("#draw"); | |
var cords = [] | |
canvas.click(function(e){ | |
cords.push({ | |
x: (e.pageX - this.offsetLeft), | |
y: (e.pageY - this.offsetTop) | |
}); | |
clickArea.html("" + cords.length + " lines has been drawn.").click(); | |
}); | |
clickArea.click(function() { | |
var c = $.map(cords, function(element, i) { | |
var start = "L"; | |
if(i === 0){ | |
start = "M"; | |
} | |
return start + element.x + " " + element.y; | |
}); | |
paper.path(c.join(" ")); | |
}); | |
}); | |
</script> | |
<head> | |
<style type="text/css" media="screen"> | |
#canvas { | |
position: relative; | |
top: 70px; | |
margin-left: auto; | |
margin-right: auto; | |
height: 600px; | |
width: 700px; | |
border: 1px solid; | |
} | |
</style> | |
<body> | |
<span id="draw"> | |
Draw! | |
</span> | |
<div id="canvas"> | |
<div> | |
<body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment