Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
</head>
<body>

<svg id="svg" xmlns="http://www.w3.org/2000/svg"></svg>
<svg id="svg" xmlns="http://www.w3.org/2000/svg" height="100%" width="100%"
></svg>

<script>
function Circle(cx, cy, html_id)
{
var html_id = html_id;
this.info = { cx: cx, cy: cy };

//private function that generates a random number
var randomNumberBetween = function(min, max){
return Math.random()*(max-min) + min;
Expand All @@ -24,8 +25,8 @@
y: randomNumberBetween(-3,3)
}

//create a circle
var circle = makeSVG('circle',
//create a circle
var circle = makeSVG('circle',
{ cx: this.info.cx,
cy: this.info.cy,
r: 10,
Expand All @@ -40,11 +41,11 @@
var el = document.getElementById(html_id);

//see if the circle is going outside the browser. if it is, reverse the velocity
if( this.info.cx > document.body.clientWidth || this.info.cx < 0)
if( this.info.cx+10 > document.body.clientWidth || this.info.cx-10 < 0)
{
this.info.velocity.x = this.info.velocity.x * -1;
}
if( this.info.cy > document.body.clientHeight || this.info.cy < 0)
if( this.info.cy+10 > document.body.clientHeight || this.info.cy-10 < 0)
{
this.info.velocity.y = this.info.velocity.y * -1;
}
Expand Down Expand Up @@ -95,11 +96,16 @@
var playground = new PlayGround();
setInterval(playground.loop, 15);

// var playground2 = new PlayGround();
// setInterval(playground2.loop, 15);
//

document.onclick = function(e) {
playground.createNewCircle(e.x,e.y);
}

</script>


</body>
</html>
</html>