You are on page 1of 6

Time Lens – Code Week

snap.berkeley.edu/run
PUBLIC For Beginners

A Project about Global Warming.

Imagine a magical lens that lets you look back in time to examine how
what’s on a photograph used to look like a hundred years ago. Brace
yourself for surprising and unsettling discoveries!

This course material was developed under the Creative Commons Attribution-ShareAlike 4.0 International License CC BY-SA 4.0.
An interactive project about Global Warming. Create a magical lens that lets you look into
the past behind a photograph to discover a lost glacier.

Begin with editing this starter project that we’ve prepared for you:

https://tinyurl.com/CWTimeStarter

In this starter project you’ll find a sprite with two costumes showing the same scene as it is
today and a hundred years ago:

First, let’s make this project yours. Click on the file menu and save the project under a new
name:

2
Let’s also rename the “Sprite” to something more meaningful, like “Canvas”:

And don’t forget to make the sprite undraggable by unselecting the checkbox that says
“draggable”:

Now let’s make the magical lens! Click on the paint brush button to draw a new sprite:

In the paint editor, draw a solid circle:

3
Remember to also rename your new sprite to something better, like “Lens”, and to also
make it undraggable:

If you want, you can also rename the “circle” costume that you’ve just drawn to something
more verbose. We suggest you rename it to “clear”.

Now your framework is ready. You should have two sprites, one named “Canvas” with
pictures of landscapes in it, and another named “Lens” with your solid circle. Both sprites
should be undraggable, and the “Lens” sprite should be on top of the “Canvas” sprite:

Is this what you have? Great! Then you’re ready for the magic code!

4
Code!

Go to the “Lens” sprite’s scripting area and make the Lens follow the mouse while you
keep the mouse button pressed:

Note that you need to change the hat block from “clicked” to “pressed”. Click on the input
slot and select “pressed” in the drop-down menu.

Also note that this code assumes that the solid circle costume that you’ve painted for the
“Lens” sprite is named “clear”. If it has a different name, no problem! Simply select it in the
SWITCH block’s drop-down menu!

The last block inside the REPEAT loop broadcasts a message that other sprites can react
to. Make sure to edit the input slot to add a message name. We suggest you name it
“update”.

Now go to the “Canvas” sprite’s scripting area and let it paste the picture of a hundred
years ago on your magical lens:

Now try it! Drag the “Lens” sprite around, can you look into the past? Can you discover the
lost glacier?

Finally, have a hard look at the code for both sprites. Just two little scripts. Do you
understand what’s happening? Can you explain in your own words how this “magic”
works?

5
Take it further!

How about using your magical time lens on more “Now & Then” photographs?

The USGS Denver Library Photographic Collection is a great resource for such photos. You
can access it here:

https://library.usgs.gov/photo/
You can find “Then and Now” photos by filtering for “repeat photography”. If you’re interested in
more photos of receding glaciers, you can also add a filter for “glaciers”

Another resource for “Then and Now” photographs of Alaskan Glaciers can be found at

https://www.alaska.org/advice/alaska-glaciers-then-now

How can you make this project even more interesting?

Here are a few ideas:

• Add different shapes for lenses. Try what happens if you import the picture of Alonzo or an animal as
costume for the “Lens” sprite!
• Use the webcam to take two pictures of yourself, one in which you look normal, and another in which you
make a goofy face. Now try the magic lens on those two pics!
• Can you add controls to change the size of the magic lens? You could make it grow when you press the
“+” key, and shrink when you press “-“.
• Can you improve the dragging of the lens? Right now the lens always centers on the mouse-pointer. Can
you make it so the lens doesn’t move when you press the mouse button over it and keeps the offset as
you drag it around?

If you’re stuck

You can access a working version of the project at

https://tinyurl.com/CWTimeLens

You might also like