13

I came across this awesome website made in HTML5 and javascript. The heart of the website is the birds flying around randomly. I have little experience with canvas and Html5. I can take another object, some simple may be circle or something and move it randomly like this. However I won't get this natural effect. If you observe carefully the birds go away from each other, then come near each other, while they are flying up high in the sky they flap their wings very fast whereas when they are flying in horizontal direction they don't flap their wings and keep it straight. It looks amazing.

I want to know only 2 things in this website i.e

1) Whether the bird is a image or created using path in html5

2) How are wings of the bird flapping? What logic he must have written? Do I need to study some physics book for this?

I've downloaded the entire website to see what code he must have written but the js file removes all the spaces and so it is as close as encrypted ;) and also I didn't find any image of the bird.

I am truly amazed with this simple yet so beautiful design. Hats off to it's creators.

Update: I am so absent minded, I forgot to put the link. Extremely extremely sorry ;)

http://thewildernessdowntown.com/

TCM
  • 16,780
  • 43
  • 156
  • 254
  • 1
    Hard to say without seeing the bird. – Bart Kiers Aug 12 '11 at 05:30
  • Can you provide a link to the web page? – Rami A. Aug 12 '11 at 05:31
  • @Bart and Rami: Sorry, see my updated post. – TCM Aug 12 '11 at 05:32
  • @Anthony that looks like someones hard work. I'd ask them. – James Khoury Aug 12 '11 at 05:35
  • @James: Yes they are from Google (as the site says). They can do anything ;). Turning impossible into possible is their habit. – TCM Aug 12 '11 at 05:37
  • @Anthony I don't think it is all google. on the about page of chromeexperiments it says "All of them were made and submitted by talented artists and programmers from around the world." and at the end of the credits page it says "A Milk+Koblin Project" – James Khoury Aug 12 '11 at 05:41
  • @Anthony http://www.chromeexperiments.com/arcadefire/ has some details on it. – James Khoury Aug 12 '11 at 05:43
  • @Anthony, see: http://stackoverflow.com/questions/5457898/animation-options-html5-canvas-css3-jquery – Bart Kiers Aug 12 '11 at 05:45
  • @James: I found the creator of this site: http://www.aaronkoblin.com/info.html However looking at his face it doesn't seem he will be ready to teach how he did :p – TCM Aug 12 '11 at 05:47
  • 1
    @ Anthony have a good read over at mr doob's blog: http://mrdoob.com/blog/post/705 which lead me to http://www.openprocessing.org/visuals/?visualID=6910 .... I'm sure you can do the rest ;) – James Khoury Aug 12 '11 at 05:47
  • 1
    @James: Thanks. Let me read them. – TCM Aug 12 '11 at 05:51
  • 4
    Not sure if they used it, but it looks very similar to the birds demo of three.js: http://mrdoob.github.com/three.js/examples/canvas_geometry_birds.html – Felix Kling Aug 12 '11 at 07:18
  • @Felix King: The classes and everything resemble the three js library. I think it is made using that only. – TCM Aug 12 '11 at 07:56
  • Yeah, somehow I had in mind that they used this, but I couldn't find a reference anymore.... well, now you know how they did it :) – Felix Kling Aug 12 '11 at 08:05

6 Answers6

8

The birds are created using sprites, if you search through the source you can find references to them: 1, 2, 3, 4.

As for the movement, it looks like some sort of swarming algorithm, combined with some (apparently) faux-3D effect. There are 3 swarms altogether, moving separately.

The code which handles the sprite for each individual bird (as well as other things), is the sprite-class:

function sprite() {}
sprite.prototype = {
    create: function(c, b, f) {
        this.image = new Image();
        var a = this;
        this.image.onload = function() {
            a.onImage()
        };
        var e = new Date();
        this.image.src = c + "?" + e.getTime();
        this.step = 0;
        this.running = true;
        this.framerate = f;
        this.size = b;
        this.off_x = 0;
        this.off_y = 0;
        this.loop = true;
        this.offset = 0
    },
    onImage: function() {
        this.steps = this.image.height / this.size
    },
    blit: function(a, c, b, f) {
        if (!this.image.complete) {
            return
        }
        if (this.loop) {
            var e = ((f + this.offset) % 1);
            this.step = Math.floor(e * this.framerate) % this.steps
        } else {
            this.step = Math.floor(f * this.framerate);
            if (this.step > (this.steps - 1)) {
                this.step = this.steps - 1
            }
        }
        a.drawImage(this.image, 0, this.step * this.size, this.image.width, this.size, c - this.image.width / 2 + this.off_x, b - this.size / 2 + this.off_y, this.image.width, this.size)
    },
    start: function() {
        this.running = true
    },
    stop: function() {
        this.running = false;
        this.step = 0
    }
};

If you're interested in seeing how the birds are initalized, look for addBirds1: function(), addBirds2: function() and addBirds3: function(), but that really won't get you very far since, due to the minification, the different variables' names give no clue to their significance.

nikc.org
  • 16,462
  • 6
  • 50
  • 83
  • How did you find this? This is great. I strongly believes that this has got to be image. But I downloaded the whole site as Webpage complete in Firefox and couldn't find this image. Even Naveen inspected and couldn't find this. – TCM Aug 12 '11 at 06:36
  • It is referenced in the JavaScript source, and thus will not be downloaded when saved from the browser. Suprisingly, the sprites didn't even show up in CHrome's Resources inspector. But, they're there, if you know what to look for. – nikc.org Aug 12 '11 at 06:38
  • nikc: Yes I know what to look for. I pasted code in jsbeautifer and found yet another image for big birds. http://www.thewildernessdowntown.com/files/img/birdb.png – TCM Aug 12 '11 at 06:41
  • Now I think there is no swarming algorithm. The creator has just loaded up this png for each bird and at each interval just shows particular frame from this image. – TCM Aug 12 '11 at 06:45
  • Swarming has nothing to do with the sprite animation, with swarming I refer to how the birds interact to each other. – nikc.org Aug 12 '11 at 06:52
  • thanks for this nick. i tht everything that renders will show up in resources panel? my bad for not looking at the beautified source though. – naveen Aug 12 '11 at 07:19
7

The answers for your questions as far as I know.

Whether the bird is a image or created using path in html5

Definitely no. Have checked everything inside the Resources Tab of the Inspect element. There is no such image. The sun, tree and the main logo all are pngs.

How are wings of the bird flapping? What logic he must have written? Do I need to study some physics book for this?

I am not sure about this. Its almost like a tween effect in flash.
No. you do not need to read a physics book but knowing physics is a great add on for any good animator.

You cannot learn anything else from this site as the JavaScript is minified. If you feel compelled use http://www.jsbeautifier.org to prettify the script and then walk through it. It will would be pretty difficult IMHO.

As you might have noted, this is from the show case of Chrome Experiments where you could see some pretty nifty JavaScript + HTML5 effects. There you can see balldroppings.js by Josh Nimoy. It is one of the most popular one out there. To achieve this effects he uses processing.js another wonderful library created by John Resig.

P.s: I'd say you might be wondering why I have guided you to that site. Everything will be apparent when you view source on the Ball Droppings site. The JavaScript is un minified and adequately commentd. It will be a great place to get started on learning HTML5 + CSS3 + SVG

naveen
  • 53,448
  • 46
  • 161
  • 251
  • @Anthony: even without your link i knew which site you were referring to. have been gawking at those implementations for say about an year now. also trying to learn more. :) – naveen Aug 12 '11 at 06:17
  • @naveen: That's good. I will contact you when at home ;). Today no work in office unlike yesterday so I am trying my hands at the unknown (HTML5) – TCM Aug 12 '11 at 06:21
2

The birds on the landing page (not the the ones sprited over the map) appear to be made using three.js. There's a example that looks nearly identical here: https://github.com/mrdoob/three.js/blob/master/examples/canvas_geometry_birds.html

ionelmc
  • 720
  • 2
  • 10
  • 29
0

I believe this birds are exactly the same as these on this website.

They are made using the amazing three.js

Joe Ng'ethe
  • 874
  • 2
  • 12
  • 26
0

I guess by the time you might have figured out how it works but as I cannot find a answer to your question in this post I think following will help:

This is achieved by THREEJS. If you are using it then imagination is our only limit. There is not flash or images anywhere. If you want to use it then you have to add

<canvas id='canvasID' width="1680" height="949" style="position: absolute; left: 0px; top: 0px;"></canvas>

in your html. Set z-index=-1 (minimum) for this canvas.

var canvas = document.getElementById("canvasID");
renderer = new THREE.WebGLRenderer({ canvas: canvas });

Pass the canvas to WebGlRenderer.

And you should be all set.

Ref: Post

Community
  • 1
  • 1
Tanmay
  • 746
  • 6
  • 7
-2

Here it is a tween solution, if you plan to use Flash:

Flash Tween Birds

LAOMUSIC ARTS
  • 642
  • 2
  • 10
  • 15