mercredi 27 février 2019

rotate

<!doctype html>
<html lang="fr">
<head>
<meta charset="utf_8">
<title>Game</title>
<style>
html,body{
height:100%;
margin:0;
}
body{
overflow:hidden;
background:royalblue;
}
svg{
width:100%;
height:100%;
}
#display{
font-family:sans-serif;
font-size:10px;
color:#fff;
position:absolute;
top:0;
left:0;
z-index:-1;
}
</style>
<body>
<svg>
<image x="0" y="0" width="100" height="100" transform="rotate(0 0 0)" xlink:href="" id="i1"/>
</svg>
<div id="display"></div>
<script>
var ww=window.innerWidth;
var wh=window.innerHeight;
var display=document.getElementById("display");
var mx,my;
document.body.onmousemove=function(e){
mx=e.clientX;
my=e.clientY;
var adeg=Math.round(Math.atan2(my-(wh/2),mx-(wh/2))*180/Math.PI);
display.innerHTML="mouse x: "+mx+"<br>mouse y: "+my+"<br>angle: "+adeg;
}
</script>
</body>
</head>

jeudi 14 février 2019

<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Paths</title>
<style>
html,body{
height:100%;
margin:0;
}
body{
overflow:hidden;
background:royalblue;
}
</style>
</head>
<body>
<svg width="0" height="0" id="mysvg">
<path d="m0 0L0 0" stroke="white" stroke-width="1" fill="none" id="path1"/>
<path d="m0 0L0 0" stroke="white" stroke-width="1" fill="none" id="path2"/>
</svg>
<script>
var ww=window.innerWidth;
var wh=window.innerHeight;
var mysvg=document.getElementById("mysvg");
var path1=document.getElementById("path1");

function fresize(){
ww=window.innerWidth;
wh=window.innerHeight;
mysvg.setAttribute("width",ww);
mysvg.setAttribute("height",wh);
path1.setAttribute("d","m0 0L"+ww+" "+wh+"");
path2.setAttribute("d","m"+ww+" 0L0 "+wh+"");
}

function fpath(){
ww=window.innerWidth;
wh=window.innerHeight;
for(var i=0;i<=360;i=i+0.5){
var path=document.createElementNS(mysvg.namespaceURI,"path");
path.setAttributeNS(null,"stroke","#"+Math.round(0xFFFFFF * Math.random()).toString(16));
path.setAttributeNS(null,"stroke-width","4");
path.setAttributeNS(null,"fill","none");
path.setAttributeNS(null,"d","m0 "+wh/2+"L"+ww+" "+wh/2+"");
path.setAttributeNS(null,"transform","rotate("+i+" "+ww/2+" "+wh/2+")");
mysvg.appendChild(path);
}}

fresize();
fpath();
window.onresize=fresize;
</script>
</body>
</html>