rendered paste body<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title>js generator</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" >
</head>
<body>
<h3>Make gear </h3>
Just set some values and press Generate. Then copypaste text to some editor and save as phn.<br>
<br>
angle: <input id="angle" value="0"><br>
body: <input id="body" value="3"><br>
collide: <input type="checkbox" id="collide" checked="checked" value="true"><br>
color: <input id="colorr" value="0.91">,<input id="colorg" value="0.13">,<input id="colorb" value="0.36"><br>
density: <input id="density" value="2.0"><br>
friction: <input id="friction" value="0.5"><br>
pos: <input id="posx" value="3" >x<input id="posy" value="-3"><br>
restitution:<input id="restitution" value="0.5"><br>
<br>
<br>
number of teeth: <input id="teeth" value="6"><br>
min radius: <input id="minr" value="15"><br>
max radius: <input id="maxr" value="20"><br>
<input type="button" onClick="generuj()" value="generate"> <br>
Output:<br>
<textarea id="output" rows="15" cols="100"></textarea>
<script type="text/javascript">
function generuj()
{
var colize,minrad,maxrad,xx,yy,uhel,pi,numteeth,delta,deltal,deltah,deltar,deltaf,points,phndata;
if ( document.getElementById("collide").checked== true ) {
colize="true";
}
else {
colize="false";
}
minrad=document.getElementById("minr").value;
maxrad=document.getElementById("maxr").value;
numteeth=document.getElementById("teeth").value;
pi=Math.PI;
delta=(2*pi)/numteeth;
deltal=delta*(40/100);
deltar=delta*(15/100);
deltah=delta*(30/100);
deltaf=delta*(15/100);
uhel=0;
points="";
while (uhel+0.001 < 2*pi)
{
xx=minrad*Math.sin(uhel);
yy=minrad*Math.cos(uhel);
points=points+"["+xx+","+yy+"],";
uhel=uhel+deltal;
xx=minrad*Math.sin(uhel);
yy=minrad*Math.cos(uhel);
points=points+"["+xx+","+yy+"],";
uhel=uhel+deltar;
xx=maxrad*Math.sin(uhel);
yy=maxrad*Math.cos(uhel);
points=points+"["+xx+","+yy+"],";
uhel=uhel+deltah;
xx=maxrad*Math.sin(uhel);
yy=maxrad*Math.cos(uhel);
points=points+"["+xx+","+yy+"]";
uhel=uhel+deltaf;
if (uhel+0.001 < 2*pi) {
points=points+",";
}
}
phndata="version = 1;\n"+
"{\n"+
" angle = "+document.getElementById("angle").value+";\n"+
" body = "+document.getElementById('body').value+";\n"+
" collide = "+colize+";\n"+
" color = ["+document.getElementById('colorr').value+","+document.getElementById('colorg').value+","+document.getElementById('colorb').value+"];\n"+
" density = "+document.getElementById('density').value+";\n"+
" friction = "+document.getElementById('friction').value+";\n"+
" id = 1;\n"+
" pos = ["+document.getElementById('posx').value+","+document.getElementById('posy').value+"];\n"+
" restitution = "+document.getElementById('restitution').value+";\n"+
' type = "polygon";\n'+
"vecs = ["+points+"];\n"+
"}\n";
document.getElementById('output').value = phndata;
};
</script>
<!-- created by petr cvek, kopyrajt: delejte si s tim co chcete :-) -->
</body>
</html>