21
Mar 12

Tweets in your HTML page

[More or less for the class I teach now]

For showing your tweets (or anyone’s for that matter) in a website, twitter offers two JavaScript files, blogger.js and user_timeline.json. To make it work, there’s three steps to take:

  1. Add one specific HTML element as a placeholder for the tweets
  2. Embed two JavaScript files into your page
  3. Add some CSS to have it show the way you want

Following is a short explanation of how it works.

The HTML

You only need to place one HTML element in your page into which the tweets end up. This element needs to have the id attribute set to twitter_update_list. This is because the scripts need to know where to put the tweets. In the example below I use a unordered list ( <ul> ) as a placeholder. So, somewhere in my page there is this code:

1
2
3
<!-- placeholder for the tweets -->
<ul id="twitter_update_list">
</ul>

The JavaScript files

The two files can be linked to your page from the twitter server, so no need to host them yourselves. The embedding can be done by copy pasting the following code right below the HTML seen above.

1
2
3
4
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js">
</script>
<script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=mannobult&include_rts=1&callback=twitterCallback2&count=4">
</script>

The first can be embedded as is, there’s no settings to it, nor the real need to change it’s code. The second does need some settings. They are discussed after the next section.

blogger.js

The file you just need to embed, nothing more. This file contains two functions to parse the incoming data into chunks of HTML. Each incoming tweet is placed inside a list item (<li>). Usernames (words preceded with the at-char (@)) are made into links to the twitter timeline of that person. Furthermore, all links are wrapped in an anchor tag. Lastly a link to the actual tweet is created from the id of the tweet. The tekst linking to the tweet is the indication how long ago the tweet was placed. This leads to, for instance, the following HTML structure:

1
2
3
4
    <li>
        <span>@<a href="http://twitter.com/druiven">druiven</a> tja, al met al niet goedkoop met overnachting enzo :( early bird en docentenkeurtings helpen gelukkig wel...</span>
        <a style="font-size:85%" href="http://twitter.com/mannobult/statuses/178219079629418496">11 days ago</a>
    </li>

Nasty detail IMHO here is the inline styling of the link to the tweet. I guess they had better left it to the CSS of the user. Fortunately there is the !important rule to override it.

The function that does the parsing looks for an element with the id ‘twitter_update_list’ to place all the list items in. Since the parser places the individual tweets into list items, it makes sense to use a list ( (<ul> or (<ol> ) as this html element.

user_timeline.json

This is the script that does the actual request to twitter. Here you can set a number of options to determine what is retrieved from the twitter server. Here is a short overview:

user_id
The id of the user you want to show the tweets of.
screen_name
The screen name of the user you want to show the tweets of (this is the name that appears in the browser address bar when you view that user’s timeline on twitter). Either this one or the user_id needs to be provided, not both.
include_rts
Show what you retweeted or not. 0 or 1.
count
How many tweets you want to show. 1 or more.
callback
Required. Leave as is or write your own JavaScript to parse the data coming in from the server.

For a more detailed description, see: the twitter docs

All the settings are done as GET parameters on the URL of the script. So, broken into separate lines it reads like:
http://api.twitter.com/1/statuses/user_timeline.json?
screen_name=mannobult
&include_rts=1
&callback=twitterCallback2
&count=4

The CSS

The CSS you want to add is of course entirely up to you. However, knowing what HTML output the JavaScript generates is necessary.
So you may want CSS for the following elements:

  • The element you placed yourselves (with id=”twitter_update_list”)
  • List items that appear inside it (containing all info of one tweet)
  • A span element inside the list items
  • Anchor elements inside the span for any links in the tweet
  • The anchor element which is a child of the list item (with the link to the tweet)

Below an example of what the CSS could look like (comments in the code):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<style type="text/css">
        /* The placeholder in which the tweets are placed */
        #twitter_update_list
        {
            list-style-type: none;
            margin: 0;
            padding: 0;
            width: 300px;
            color: #000;
            font-family: Verdana, Geneva, sans-serif;
        }
        /* Each tweet is wrapped inside a list item, have them spaced by a margin */
        #twitter_update_list li
        {
            margin:.2em 0;
        }
       
        /* have alternating colors for subsequent tweets */
        #twitter_update_list li:nth-child(even)
        {
            background-color: #0CF;
        }
        #twitter_update_list li:nth-child(odd)
        {
            background-color: #09F;
        }
       
        /* the tweet text itself */
        #twitter_update_list li span
        {
            display:inline-block;
            color: #000;
            font-size: .8em;
            padding: 0.5em;
        }

        /* Links inside the tweet */
        #twitter_update_list li span a
        {
            color: #000;
        }

        /* The link of how long ago the tweet was placed. Note the !important rule to override the inline style rule created by blogger.js */
        #twitter_update_list li > a
        {
            display: block;
            text-decoration: none;
            font-size: 0.8em !important;
            color: #FFF;
            padding: 0.2em;
            background: rgba( 128, 128, 128, 0.7 );
        }
    </style>

All the above results in the following:
example of embedded tweets


27
Feb 12

Introducing HTML5 Game Development by Jesse Freeman (O’Reilly Media)

Jesse Freeman‘s Introducing HTML5 Game Development, Developing Games with Impact is an excellent read for anyone willing to get their hands dirty with JavaScript as language of choice for game development. It offers general insights on what is needed to develop a game. Topics include writing game design docs, using in game stats to analize player behavior, some asset preparation and more. However, it mainly offers a head start in developing JavaScript based games with the Impact game engine, covering next to all it’s features.

Disclaimer

I did not get myself a copy of Impact. Just reviewing the book and not the Impact framework I did not see it as nessecary. Had impact been on sale like it was about a month or so ago I might have gotten my on copy (notch, notch, wink, wink).

The positives

Let’s start with those according to the feedback rules…

To me te book feels like a cookbook to get one specific game done (“type this here …”) at times. It however gives a good overview of most if not all ‘classes’ and possibilities of Impact and how to get up to speed with building a relatively small game with it. Using the accompanying level editor called Weltmeister Jesse shows you how to design levels, how to load them in Impact and bring the level to life. What else can you ask for?

Next to that more or less main goal of the book, you’ll get an overview of the whole process of game development. From initial idea to publishing (and possible deployment on iOS with a template Xcode project that comes with Impact). Good insights from someone who knows what he is talking about.

Finally it contains some heads up on HTML5 development. I’m afraid that is still nessecary with the way browser support is at the moment.

The negatives

The subtitle of book is a nice pun (and the name of the game framework is well chosen), but may be somewhat misleading for the less informed buyer of the book. Actually tagging along with Jesse in building your own game will set you back $99: the subtitle’s “Impact” refers not only to the effect games may aim to have on their player, but also to the commercial Impact game framework written in JavaScript. Just a fair warning ahead.

Another downside I think there is to the book is the intended audience as it states. Personally I don’t think this book is much use without having prior programming knowledge. If you have none, you’ll end up with a working game nonetheless, but I doubt you’ll understand why, how to change it or to build your own in any reasonable fashion.

Finally, usage of stats to analyze players behaviors is stressed, however, the examples may have been a bit more clear (I’m pretty much a GA noob)

Impact

Without having used the software, it seems like a real nice environment to work with. It comes with a good map editor, several debugging and profiling features. To help with the game mechanics there’s collision detection and particle systems and most needed features of the box so you can focus on the creative process.

Concluding

I’d by the book if you want to do some JavaScript game dev, especially if it involves platform games. If you have no programming experience I would get some basics done first but I guess it all depends on your individual talent to pick up programming.
It is a quick read and gets you up to speed with Impact in about a day (or two).

Get HTML5 Game Development


26
Feb 12

Hack, slash & play with kinect at FITC Amsterdam 2012

Today the workshops of FITC 2012 took place. I visited Koen De Weggheleire en Wouter Verweirder their Kinect workshop.

Koen and Wouter are developers of AIRKinect of which version two is almost to be released. Unfortunately my lovely new MacBook refused to install some of the drivers despite Wouter’s persistence. Fortunately they had a spare laptop to use (thanks!).

I’d seen demos and fooled around with the depth image before, but the next version of AIRKinect, used as native extension offers lots more then I’d ever seen possible in AIR (may of course be my ignorance).

Some of the features of the 2.0 preview we got to play with were:

  • depth image
  • point cloud
  • point cloud regions
  • skeletons
  • poses

Depth image

The depth image shows the image the IR camera registers in greyscale. Nearby white, far black. My first ever experiment was that I used this to, pixel by pixel, reconstruct a 2.5D image with Flash’s z-property of sprites. But…

Point cloud

The point cloud is a ByteArray with for each “pixel” an x-, y-, and z-position. This allows for precise tracking of, for instance, the closest thing the IR camera registers. Extend your arm and move stuff around, the famous Minority Report interface in the making.

Point cloud regions

Point cloud regions allow use of hotspots. If a certain region (a box) contains more than a set number of points from the cloud (the count is done by the extension), you could start whatever action you see fit. Du du, du du, du du, du du, ta ta! I can feel it coming in the air tonight … Drum like Phil Collins for instance.

Skeletons

The skeletons you may have seen before. AIRKinect supports 4 skeletons and then some additional center of mass registrations. With the skeletons you have access to the main joints, their position in 3D space, position projected onto the webcam image, orientation and more.

Poses

With the skeletons you can create poses, this is actually not done in the extension, but with a few classes in which you can define poses like assertions: right elbow, above, right shoulder. Combine a few of these rules and you can create complex poses which are easy to check.

There is no doubt more, but the distraction of and annoyance over the failures of installing macports probably made me miss out on some…

All together it requires a somewhat elaborate install sequence (which they will no doubt publish at due time) on the Mac, mine being the odd one out resisting all attempts to get it running. On windows it’s a bit lot less elaborate. Definitely will try at home to get it running on my desktop. When I succeed, hours of fun will be waiting :)

Pointcloud