...

View Full Version : Done the HTML part, need help with the C ++ part



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">&nbsp;</div>

<div id="container" class="hide">
<div id="upright">&nbsp;</div>
<div id="upleft">&nbsp;</div>
<div id="downright">&nbsp;</div>
<div id="downleft">&nbsp;</div>
</div>

<div id="dot">&bull;</div>
<div id="coords" class="hide"></div>

</body>
</html>

oesxyl
11-19-2008, 04:13 PM
I see that you still don't understand what Philip M tell you about the title, so read point 2 from this link:

http://www.codingforums.com/postguide.htm

PS: moving code from js forum to this don't make it to become c++.

regards

skieeterno
11-19-2008, 04:26 PM
PS: moving code from js forum to this don't make it to become c++.

regards

I cant understand your point? mostly cause it isnt english.. and the fact is has nothing to do with my post...

My initial spec has the program created in C++ tho it has been a while since i coded in it, so i simply asked not for code but for help in coding myself..

Thanks for your interest in my post tho ;)

oesxyl
11-19-2008, 04:35 PM
I cant understand your point? mostly cause it isnt english.. and the fact is has nothing to do with my post...

My initial spec has the program created in C++ tho it has been a while since i coded in it, so i simply asked not for code but for help in coding myself..

Thanks for your interest in my post tho ;)
what means cant, tho? sorry for my english, you must be very inteligent since you discover my bad english, :).

no regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum