Last year, I had worked on a page that tested the basics of shaking an image using a canvas. It wasn't very impressive and didn't really capture what I was trying to do. Over winter break I started to work on a page that properly shook the images within the canvas.
canvas_shake2.html
It generates a set number of canvases (at the time of writing it's 10, but on the actual implementation it will probably be higher). Each of these canvases is assigned a random image from a pool of possible images. A tick function called using the javascript setInterval() function updates the canvases every 30 milliseconds. Each frame loads the image at a different position:Please try out the different buttons on the page and see what they do!
The main limitation of this method is that gifs no longer render past the first frame because javascript doesn't offer an easy way to choose which frame in a gif is drawn to a canvas using the drawImage() method. A lot of the shaker elements are gifs, so that's a big problem.
canvas_spritesheet.html
To work around this limitation, I started working on a canvas implementation that would create an animation using a spritesheet, an image with all the frames of a gif lined up like a film strip.
Please try out the different buttons on the page and see what they do!
Also, if your sound isn't on, turn it on! I set up the javascript so that it seamless(ish)ly loops a part of a song.
For both of these pages, there's a link to the proper github page where you can see the relevant code with proper syntax highlighting.
Wow! You're going to be a huge asset to whoever is fortunate enough to hire you in the future, Mr. Hirschberg, because you bring together a set of skills that are not often found in one person, a high level of programming skills combined with top notch communication skills.
ReplyDeleteI'm glad I told you I wanted to wait until the weekend to read this post when you tried to get me to look at it on Monday, since I needed the time I have now to give it its proper due.
You've created a fantastic tutorial here. Would you consider releasing it under an open content license? If you would, I would want to make a modified copy of it to put on the Open Book Project site.