Permalink
Browse files

Add tweets

  • Loading branch information...
1 parent 7d1ca77 commit 3e82cf31c72a85da878495d241476c77cde0dfc0 @gigasquid committed Jul 14, 2012
Showing with 55 additions and 8 deletions.
  1. +2 −1 index.html
  2. 0 {d3 → lib}/d3.v2.js
  3. +4 −0 lib/jquery-1.7.1.min.js
  4. +8 −0 roomba.css
  5. +41 −7 roomba.js
View
@@ -1,7 +1,8 @@
<html>
<head>
<title>Roomba Dreams</title>
- <script type="text/javascript" src="d3/d3.v2.js"></script>
+ <script type="text/javascript" src="lib/d3.v2.js"></script>
+ <script type="text/javascript" src="lib/jquery-1.7.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="roomba.css" />
</style>
</head>
File renamed without changes.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,3 +1,11 @@
.roomba{
background-image: "roomba_normal.jpg"
+}
+
+.tweet{
+ font-weight: bold;
+ font-family: Helvetica;
+ font-size: 16px;
+ width: 480px;
+ margin: 5px;
}
View
@@ -1,22 +1,36 @@
var roomba_data = [[200, 200]];
+var tweets = ["(Becomes Self-Aware)"];
+var tweet_num = 0;
-var dataset = []; //Initialize empty array
-for (var i = 0; i < 10; i++) { //Loop 25 times
- var newNumber = Math.floor(Math.random() * 460) + 20; //New random number (0-30)
- dataset = dataset.concat(newNumber); //Add new number to array
+function getTweets() {
+ var url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=SelfAwareROOMBA&callback=?'
+ $.getJSON(url,function(json){
+ for (i=0; i<json.length; i++){
+ if (!json[i].in_reply_to_user_id){
+ tweets.push(json[i].text);
+ }
+ }
+ tweets.reverse();
+ });
}
+getTweets();
+
//Width and height
var w = 500;
var h = 500;
var svg = d3.select("body").append("svg").attr("width", w).attr("height", h);
//setup the room
-svg.append("rect").attr("width", w).attr("height", h).attr("fill", "#ffcc66")
+svg.append("rect").attr("width", w).attr("height", h).attr("fill", "#ffffee")
.attr("stroke", "black").attr("stroke-width", "10");
+//setup the tweet area
+d3.select("body").append("div").attr("class", "tweet");
+
var roomba = svg.selectAll("roomba").data(roomba_data).enter()
+ .append("g")
.append("svg:image")
.attr("class", "roomba")
.attr("xlink:href", "roomba.gif")
@@ -25,14 +39,34 @@ var roomba = svg.selectAll("roomba").data(roomba_data).enter()
.attr("x", function(d) { return d[0];})
.attr("y", function(d) { return d[1];});
+var tweet = svg.selectAll("g")
+ .append("text");
+
function next_position(){
return Math.floor(Math.random() * 460) + 20;
}
+function showTweet(){
+ var i = tweet_num;
+ if (tweets.length > tweet_num +1){
+ tweet_num++;
+ }
+ if (tweets.length < tweet_num +1){
+ tweet_num = 0;
+ }
+ d3.select(".tweet").text(tweets[tweet_num]);
+}
+
+
function move(){
+ var new_x = next_position();
+ var new_y = next_position();
svg.selectAll("image.roomba").transition()
- .attr("x", next_position())
- .attr("y", next_position()).duration(1000).delay(100);
+ .attr("x", new_x)
+ .attr("y", new_y).duration(1000).delay(100);
+
+ showTweet();
+
setTimeout(move, 2000 + 200);
}

0 comments on commit 3e82cf3

Please sign in to comment.