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 52 53 54 55
|
<!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 R=200;
var paper = Raphael("disque",2*R,2*R);
var disque = paper.set();
disque.push(paper.circle(R,R,R).attr('fill','red') );
disque.push(paper.path("M{0} {1} L{2} {3}",0,R,2*R,R).attr({
stroke: "black",
"stroke-width": 2
}) );
disque.push(paper.path("M{0} {1} L{2} {3}",R,0,R,2*R).attr({
stroke: "black",
"stroke-width": 2
}) );
disque.attr({ cursor:'pointer'});
var bouger=false;
var dtheta=0, oldtheta=0,alpha=0;
disque.mousedown(function(e){
oldtheta=Math.atan2(R-e.offsetY,e.offsetX-R)*180/Math.PI; //coords maths
bouger=true;
});
disque.mousemove(function(e){
if (bouger){
dtheta=Math.atan2(R-e.offsetY,e.offsetX-R)*180/Math.PI;
alpha=dtheta-oldtheta;
alpha=alpha%360;
disque.transform("r" + -alpha +','+ R + "," + R); //inverse du sens trigo
console.log(alpha);
}
});
disque.mouseup(function(){
bouger=false;
});
</script>
</body>
</html> |
Partager