1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
<!DOCTYPE html>
<html>
<head>
<title>Essai_angle</title>
<script type="text/javascript" src="path/to/raphael.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
</head>
<body>
<div id="disque"></div>
<script>
var disque=document.getElementById('disque');
var Ra=200;
var paper = Raphael("disque",2*Ra,2*Ra);
var disque = paper.set();
disque.push(paper.circle(Ra,Ra,Ra).attr('fill','red') );
disque.push(paper.path("M{0} {1} L{2} {3}",0,Ra,2*Ra,Ra).attr({
stroke: "black",
"stroke-width": 2
}) );
disque.push(paper.path("M{0} {1} L{2} {3}",Ra,0,Ra,2*Ra).attr({
stroke: "black",
"stroke-width": 2
}) );
disque.attr({ cursor:'pointer'});
var theta_start=0, theta_move=0, theta_old=0, theta_end=0;
disque.drag(onMove, onStart, onEnd);
function onStart(e){
theta_start=Math.atan2(Ra-e.offsetY,e.offsetX-Ra)*180/Math.PI;
}
function onMove(e){
theta_move=Math.atan2(Ra-e.offsetY,e.offsetX-Ra)*180/Math.PI;
theta_end=theta_move-theta_start+theta_old;
disque.transform("R" + (-theta_end )+','+ Ra + "," + Ra);
}
function onEnd(){
theta_old=theta_end;
}
</script>
</body>
</html> |
Partager