skieeterno
11-19-2008, 04:04 PM
Hey guys..
I optained the following Javascript code, it basically moves a dot randomly about the sreen and outputs the movements to the screen followed by the coords of where each dot moved too.. and averages out the coords.
I need it to be created in another language i choose C ++ because it should be possible to output a graphical representation of all of the positions of the dots after the loop as finished, so for example 500 dots would be shown on screen along with all of the dots movements and coords.. look at the following code please and see if anyone can help me code it in C ++ or even anyother language
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
body {
overflow:hidden;
}
#container div,#timer {
width:250px;
line-height:30px;
padding-left:10px;
border:3px double #999;
margin:4px 0;
}
.hide {
display:none;
}
#dot {
width20px;
font-size:36px;
color:#f00;
position:absolute;
}
#coords {
padding:10px;
border:3px double #999;
margin-top:10px;
font-family:courier,monospace;
font-size:12px;
text-align:justify;
}
</style>
<script type="text/javascript">
/****** these values may be edited *****/
var iterations=9999;
var height=999;
var width=999;
var temp1=500;
var temp2=500;
/***************************************/
var speed=10;
var c=0;
var ur=0;
var ul=0;
var dr=0;
var dl=0;
var s=0;
var xc=0;
var yc=0;
if(window.addEventListener){
window.addEventListener('load',randomtest,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',randomtest);
}
}
function randomtest(){
secs=Math.floor((iterations-c)*speed/1000);
x=Math.floor(Math.random()*width);
y=Math.floor(Math.random()*height);
document.getElementById('coords').innerHTML+=x+':'+y+', ';
document.getElementById('dot').style.left=x+'px';
document.getElementById('dot').style.top=y+'px';
if((x>=temp2)&&(y>=temp1)) {
ur++;
temp1=x;
temp2=y;
}
else {
if((x<=temp2)&&(y>=temp1)) {
ul++;
temp1=x;
temp2=y;
}
else {
if((x>=temp2)&&(y<=temp1)) {
dr++;
temp1=x;
temp2=y;
}
else {
if((x<=temp2)&&(y<=temp1)) {
dl++;
temp1=x;
temp2=y;
}
}
}
}
c++;
xc=xc+x;
yc=yc+y;
if(c>iterations) {
clearTimeout(rnd);
document.getElementById('timer').className='hide';
document.getElementById('dot').className='hide';
document.body.style.overflow='visible';
document.getElementById('upright').firstChild.nodeValue='up right total='+ur;
document.getElementById('upleft').firstChild.nodeValue='up left total='+ul;
document.getElementById('downright').firstChild.nodeValue='down right total='+dr;
document.getElementById('downleft').firstChild.nodeValue='down left total='+dl;
document.getElementById('container').className='';
document.getElementById('coords').className='';
alert('average coords are:-\n\nx='+Math.round(xc/c)+'\ny='+Math.round(yc/c));
return;
}
document.getElementById('timer').firstChild.nodeValue='time remaining : '+secs+' seconds.';
rnd=setTimeout('randomtest()',speed);
}
</script>
</head>
<body>
<div id="timer"> </div>
<div id="container" class="hide">
<div id="upright"> </div>
<div id="upleft"> </div>
<div id="downright"> </div>
<div id="downleft"> </div>
</div>
<div id="dot">•</div>
<div id="coords" class="hide"></div>
</body>
</html>
I optained the following Javascript code, it basically moves a dot randomly about the sreen and outputs the movements to the screen followed by the coords of where each dot moved too.. and averages out the coords.
I need it to be created in another language i choose C ++ because it should be possible to output a graphical representation of all of the positions of the dots after the loop as finished, so for example 500 dots would be shown on screen along with all of the dots movements and coords.. look at the following code please and see if anyone can help me code it in C ++ or even anyother language
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
body {
overflow:hidden;
}
#container div,#timer {
width:250px;
line-height:30px;
padding-left:10px;
border:3px double #999;
margin:4px 0;
}
.hide {
display:none;
}
#dot {
width20px;
font-size:36px;
color:#f00;
position:absolute;
}
#coords {
padding:10px;
border:3px double #999;
margin-top:10px;
font-family:courier,monospace;
font-size:12px;
text-align:justify;
}
</style>
<script type="text/javascript">
/****** these values may be edited *****/
var iterations=9999;
var height=999;
var width=999;
var temp1=500;
var temp2=500;
/***************************************/
var speed=10;
var c=0;
var ur=0;
var ul=0;
var dr=0;
var dl=0;
var s=0;
var xc=0;
var yc=0;
if(window.addEventListener){
window.addEventListener('load',randomtest,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',randomtest);
}
}
function randomtest(){
secs=Math.floor((iterations-c)*speed/1000);
x=Math.floor(Math.random()*width);
y=Math.floor(Math.random()*height);
document.getElementById('coords').innerHTML+=x+':'+y+', ';
document.getElementById('dot').style.left=x+'px';
document.getElementById('dot').style.top=y+'px';
if((x>=temp2)&&(y>=temp1)) {
ur++;
temp1=x;
temp2=y;
}
else {
if((x<=temp2)&&(y>=temp1)) {
ul++;
temp1=x;
temp2=y;
}
else {
if((x>=temp2)&&(y<=temp1)) {
dr++;
temp1=x;
temp2=y;
}
else {
if((x<=temp2)&&(y<=temp1)) {
dl++;
temp1=x;
temp2=y;
}
}
}
}
c++;
xc=xc+x;
yc=yc+y;
if(c>iterations) {
clearTimeout(rnd);
document.getElementById('timer').className='hide';
document.getElementById('dot').className='hide';
document.body.style.overflow='visible';
document.getElementById('upright').firstChild.nodeValue='up right total='+ur;
document.getElementById('upleft').firstChild.nodeValue='up left total='+ul;
document.getElementById('downright').firstChild.nodeValue='down right total='+dr;
document.getElementById('downleft').firstChild.nodeValue='down left total='+dl;
document.getElementById('container').className='';
document.getElementById('coords').className='';
alert('average coords are:-\n\nx='+Math.round(xc/c)+'\ny='+Math.round(yc/c));
return;
}
document.getElementById('timer').firstChild.nodeValue='time remaining : '+secs+' seconds.';
rnd=setTimeout('randomtest()',speed);
}
</script>
</head>
<body>
<div id="timer"> </div>
<div id="container" class="hide">
<div id="upright"> </div>
<div id="upleft"> </div>
<div id="downright"> </div>
<div id="downleft"> </div>
</div>
<div id="dot">•</div>
<div id="coords" class="hide"></div>
</body>
</html>