/    Sign up×
Community /Pin to ProfileBookmark

hai.,,,,, i want to generate a square in JS and i want that square to move from one placew to another……. with taking (x,y) coordinates…… and if there is cordinate inbetween when the square is going to move then the square has to move to the adjacent side of the square
thanyou

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Laurence485Dec 31.2011 — ok first of all that title needs to be more descriptive, it does not tell anyone what you are trying to achieve. Post some code of what you have already tried so it can be modified by someone.
Copy linkTweet thisAlerts:
@viswa313authorJan 02.2012 — <html>

<head>

<title> Generate Boxes </title>

<style>

body {

font-family:verdana;

font-size:11px;

}

#box{

border:1px solid green;

width:48px;

height:48px;

position:relative;

background-color:black;

}

#box1{

border:1px solid green;

width:48px;

height:48px;

position:relative;

background-color:black;

}

#container{

width:350px;

height:350px;

border:1px solid black;

}

#main{

margin-top:140px;

margin-left:350px;

}


.box {

position:absolute;
border:1px solid grey;
width:48px;
height:48px;
background-color:silver;
}



</style>

<script type="text/javascript">

var Cont = function() {

var Box = function(x, y) {
this.x = x;
this.y = y;
}


this.newBox = function() {
var x = Math.floor(Math.random() * 10);
var y = Math.floor(Math.random() * 10);
var box = new Box(x, y);
for(var i = 0; i < this.boxes.length; i++) {
if(box.x == this.boxes[i].x && box.y == this.boxes[i].y) {
box = this.newBox();
}
}
return box;
}






</script>

</head>

<body>

<div id="main">

<div id="container">

<div id="box"></div>

<div id="box1"></div>

</div>


</div>

</body>

</html>
×

Success!

Help @viswa313 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...