PencilCoder

Images!

Goals:

  • Extend your knowledge of sprites to include working with images

Coding Snippets:

  • coding snippets
  • Use wear to select an image for a sprite. The optional second argument controls its height.
  • Use slide to move a sprite to the right or left without turning. Add a second argument after slide to simultaneously move forward or backwards.
  • mirror flips the image across the sprite's main axis.

Math and Computer Concepts:

  • FishesPencil 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 Sprite constructor or wear function. The URL must reference a jpg, png, or svg file.
  • The variables on and off are aliases for the Boolean values true and false. An alias is simply a second name for something. In this case, on and off are useful because they are easier to read.

Activities:

Save each of the following in a folder called Images.

  • Coding ExampleCode 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.
  • Shark TankCreate a SharkTank containing an image of a shark. Use slide and mirror to make the shark swim back and forth realistically. Also, use grow to 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 slide and mirror.