Images!
Goals:
- Extend your knowledge of sprites to include working with images
Coding Snippets:
- Use
wearto select an image for a sprite. The optional second argument controls its height. - Use
slideto move a sprite to the right or left without turning. Add a second argument afterslideto simultaneously move forward or backwards. mirrorflips the image across the sprite's main axis.
Math and Computer Concepts:
-
Pencil Code searches for images from a public database. Preface the search term with t-to have it return an image with a transparent background. The example on the right shows the results from'fish'and't-fish', both drawn on a blue background. - Specify an image of your choice by referencing a string showing its web address, or URL (Uniform Resource Locator) as the argument to the
Spriteconstructor orwearfunction. The URL must reference ajpg,png, orsvgfile. - The variables
onandoffare aliases for the Boolean valuestrueandfalse. An alias is simply a second name for something. In this case,onandoffare useful because they are easier to read.
Activities:
Save each of the following in a folder called Images.
-
Code a DogAndCat program which loads images for 't-dog'and't-cat', making the cat half as tall as the dog. Then replace these images with images from the web that you like better. - Find images of hair without a face (such as from pngall.com) and add it to a sprite. Size and position the hair on top of your CrazyFace sprite, or an image of a real person, saving the result as Hairdos.
Create a SharkTank containing an image of a shark. Use slideandmirrorto make the shark swim back and forth realistically. Also, usegrowto make the shark appear to move closer and further away.- Using images, either create a Seascape with a variety of sprites for sea life in front of an image of water and sand; or generate a HauntedHouse by superimposing images of ghosts or other spooky characters in front of a suitable background image; or come up with an analagous concept of your own design. Whatever your choice, be sure to move sprites around realistically using
slideandmirror.



