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 it forward or backwards. mirrorflips the image across its main axis.
Math and Computer Concepts:
-
Pencil Code searches for images from Wikimedia Commons. Preface the search with t-to seek an image with a transparent background. The example on the right contrasts the results from searches on'fish'and't-fish'. - 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 an image file such asjpg,png, orsvg. - The variables
onandoffare aliases for the Boolean valuestrueandfalse. An alias is simply a second name for something.
Activities:
Save each of the following in a folder called Images.
The
slidefunction allows us to easily draw an infinite variety of triangles without having to worry about computing angles. Capitalize on this fact to create some cool TrianglesArt:-
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. Animate the sprites usingslide.
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.


