Skip to content

Commit

Permalink
Fix tweets and bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
gigasquid committed Jul 14, 2012
1 parent 3e82cf3 commit 2578dcd
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions roomba.js
Expand Up @@ -19,6 +19,7 @@ getTweets();
//Width and height //Width and height
var w = 500; var w = 500;
var h = 500; var h = 500;
var roomba_image = 48;


var svg = d3.select("body").append("svg").attr("width", w).attr("height", h); var svg = d3.select("body").append("svg").attr("width", w).attr("height", h);
//setup the room //setup the room
Expand All @@ -27,37 +28,33 @@ svg.append("rect").attr("width", w).attr("height", h).attr("fill", "#ffffee")
//setup the tweet area //setup the tweet area
d3.select("body").append("div").attr("class", "tweet"); d3.select("body").append("div").attr("class", "tweet");




var roomba = svg.selectAll("roomba").data(roomba_data).enter() var roomba = svg.selectAll("roomba").data(roomba_data).enter()
.append("g") .append("g")
.append("svg:image") .append("svg:image")
.attr("class", "roomba") .attr("class", "roomba")
.attr("xlink:href", "roomba.gif") .attr("xlink:href", "roomba.gif")
.attr("width", 48) .attr("width", roomba_image)
.attr("height", 48) .attr("height", roomba_image)
.attr("x", function(d) { return d[0];}) .attr("x", function(d) { return d[0];})
.attr("y", function(d) { return d[1];}); .attr("y", function(d) { return d[1];});


var tweet = svg.selectAll("g") var tweet = svg.selectAll("g")
.append("text"); .append("text");


function next_position(){ function next_position(){
return Math.floor(Math.random() * 460) + 20; return Math.floor(Math.random() * (490 - roomba_image) + (roomba_image + 10));
} }


function showTweet(){ function showTweet(){
var i = tweet_num;
if (tweets.length > tweet_num +1){ if (tweets.length > tweet_num +1){
tweet_num++; tweet_num++;
} }
if (tweets.length < tweet_num +1){ if (tweets.length <= tweet_num +1){
tweet_num = 0; tweet_num = 0;
} }
d3.select(".tweet").text(tweets[tweet_num]); d3.select(".tweet").text(tweets[tweet_num]);
} }



function move(){ function move(){
var new_x = next_position(); var new_x = next_position();
var new_y = next_position(); var new_y = next_position();
Expand All @@ -67,9 +64,7 @@ function move(){


showTweet(); showTweet();


setTimeout(move, 2000 + 200); setTimeout(move, 4000 + 200);
} }


move(); move();


0 comments on commit 2578dcd

Please sign in to comment.