BTC640/ProcessingTextImages
Contents
Lecture
This week we'll be looking at how to work with text and images with processing.js.
Text
Support for text in processing.js is pretty flaky, and the best you can rely on is that you can set the size of the font. Probably support for other fonts will be improved in future releases.
None of the HTML tags you're used to, nor CSS will work in processing.js. All the text is displayed literally - including anyting that looks like an HTML tag.
The documentation for text API functions is not as good as for other functions in processing.js but it's good enough and there are examples that you can relatively easily figure out how to use it.
Images
You should preload images before the sketch starts animating so that there wouldn't be a huge delay in the middle of an animation while an image is being downloaded from the server (remember that processing.js code is client side code). The syntax for this is similar to Java annotations, and looks like this:
/* @pjs preload="myimage.png"; */
You should put that in front of your setup. Processing.js is very picky about the syntax of this statement, including spaces and the types of comments, so just copy-paste the above (or from a reference page).
Lab
We're going to make a simple slideshow with processing.js. You can use images from anywhere you like, or if you don't have your own set you can use these:
- http://littlesvr.ca/misc/lacloche/images/01-lumsdenlake-small.jpg
- http://littlesvr.ca/misc/lacloche/images/02-bf-tn-portage-small.jpg
- http://littlesvr.ca/misc/lacloche/images/03-threenarrows-from-south-small.jpg
- http://littlesvr.ca/misc/lacloche/images/04-deer-small.jpg
- http://littlesvr.ca/misc/lacloche/images/05-treeonrock-small.jpg
- http://littlesvr.ca/misc/lacloche/images/06-lily-small.jpg
- http://littlesvr.ca/misc/lacloche/images/07-swampflowers-small.jpg
- http://littlesvr.ca/misc/lacloche/images/08-narrowwater-small.jpg
- http://littlesvr.ca/misc/lacloche/images/09-cabin-small.jpg
- http://littlesvr.ca/misc/lacloche/images/10-abovefog1-small.jpg
- http://littlesvr.ca/misc/lacloche/images/11-abovefog2-small.jpg
- http://littlesvr.ca/misc/lacloche/images/12-lookingsouth-small.jpg
- http://littlesvr.ca/misc/lacloche/images/13-lookingsouth2-small.jpg
- http://littlesvr.ca/misc/lacloche/images/14-lookingsouth3-small.jpg
- http://littlesvr.ca/misc/lacloche/images/15-littlemountainlake1-small.jpg
- http://littlesvr.ca/misc/lacloche/images/16-littlemountainlake2-small.jpg
- http://littlesvr.ca/misc/lacloche/images/17-boundaryswamp1-small.jpg
- http://littlesvr.ca/misc/lacloche/images/18-boundaryswamp2-small.jpg
- http://littlesvr.ca/misc/lacloche/images/19-smalllake-small.jpg
- http://littlesvr.ca/misc/lacloche/images/19-smalllake.jpg
- http://littlesvr.ca/misc/lacloche/images/20-south-of-silver-small.jpg
- http://littlesvr.ca/misc/lacloche/images/21-norwestlake-small.jpg
- http://littlesvr.ca/misc/lacloche/images/22-acrosslake-small.jpg
- http://littlesvr.ca/misc/lacloche/images/23-lastseriousclimb-small.jpg
Here's what you need to do (everyone):
- The images are all 300x200
- Make sure your canvas is as big as will fit in the browser page.
- Figure out how to use the requestImage() function. This will load the image asynchronously so that you can display one image while another is loading. Using my images would be good here because my server's connection is slow and it will take visible time to download the images.
- Display the images one at a time for a couple of seconds at a random position in the canvas, but make sure they are fully visible and not clipped.
- When switching the images first fade out the old one (same way as I did in the lecture).
Degree students (optional for diploma students):
- Display the filename (not the entire URL) of the image floating over it, you may need a rect behind the text (but in front of the image) to make sure the text is readable.
Submit
Submit your html file and the pde file (if your code is in a separate file) to Moodle (Lab 8).