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 it forward or backwards.
  • mirror flips the image across its main axis.

Math and Computer Concepts:

  • FishesPencil 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 Sprite constructor or wear function. The URL must reference an image file such as jpg, png, or svg.
  • The variables on and off are aliases for the Boolean values true and false. An alias is simply a second name for something.

Activities:

Save each of the following in a folder called Images.

  • The slide function 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:

  • 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. Animate the sprites using slide.
  • 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.