Add a drawing to the values journal: a Drawing object on the Describe screen, its picture kept in a variable when you click Add, and an Image on the Journal screen that shows it. Find out why the order of two actions matters, and what the journal still can't do.
Some things are easier to draw than to say. Apps let you draw, take photos and record sounds; each makes a picture or sound the app can keep and show somewhere else.
The values journal from the last lesson keeps what you wrote. Today it also keeps a drawing of what you did.
Describe: a space to draw in, under the typing box.
Journal: the drawing you just made, under the list.
A drawing is something the app makes while it runs, like a photo or a recording. The app keeps it as a picture, and a variable can hold it, just as a variable holds a number or some text.
How this lesson works: See it, Build, Check, Make it yours
See it: Try the finished thing first, so you know what you are building.
Build: Watch the short clip, then do the steps. Your app carries on from the step before.
Check: A quick check that the idea has stuck.
Make it yours: Change your app on purpose, then try it on someone.
Make your prediction first. Help opens once you've locked it in.
See itTry the finished thing first, so you know what you are building.
Try the finished app
Pick a value, type what you did, then draw it in the box with the mouse (or your finger). Click Add to my journal. The drawing shows on the Journal screen.
Watch LastDrawing under the variables on the left. When you click Add, it changes from "" to something like media:7f3a09c2: that's the app's name for the picture it kept.
Try it yourselfYour edits are saved in this browser.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 1: a space to draw
Open the Describe screen. We've moved Add to my journal down to make room.
Click + Add object, then Drawing. It's called Drawing1: rename it Drawing (double-click its name in the sidebar, or its ⋯ menu, Rename).
In Properties, place it under the typing box: x 229, y 184, width 342, height 280 (or drag it there).
On the Events tab, add an action to On start of screen: Drawing, Clear Drawing.
Run it from Choose and draw something. Go back to Choose and pick again: the page is clean.
A Drawing object · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
The Describe screen has a Drawing, and it's cleared each time the screen starts.
Run your program. This ticks when your code does all of the above.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 2: keep the drawing
In the sidebar, under the variables, add a variable called LastDrawing. Leave its starting value empty.
On the Describe screen, add an action to AddButton is clicked: Variables, Set variable LastDrawing to Drawing.picture
Run it, draw, and click Add. Watch LastDrawing change on the left.
Drawing.picture is the drawing as a picture. The app keeps it and gives it a name such as media:7f3a09c2, so the variable holds that name, not all the dots of the drawing.
Try it yourselfYour edits are saved in this browser.
A variable LastDrawing, and Add sets it to Drawing.picture (and still adds the entry and goes to Journal).
Run your program. This ticks when your code does all of the above.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 3: show it on the Journal
Open the Journal screen. We've made the list shorter to make room.
+ Add object, Image. Rename it LastImage, and place it under the list: x 335, y 335, width 130, height 130.
On the Events tab, add an action to On start of screen: LastImage, Set LastImage picture to the one in, value LastDrawing
Run it from Choose: pick, type, draw, Add. Your drawing is on the Journal.
There are two "set picture" actions. Set picture to picks one of the app's pictures while you design it. Set picture to the one in works it out while the app runs, from a variable or Drawing.picture.
Show a picture the app made · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
The Journal screen has an Image called LastImage, and when the screen starts it shows the picture in LastDrawing.
Run your program. This ticks when your code does all of the above.
CheckA quick check that the idea has stuck.
Check: order and what's kept
Nib wanted each entry to start with a clean page, so Nib put Clear in the Add event.
The journal keeps every entry you write. Does it keep every drawing?
Nib's Journal shows the error "There is no picture yet", even though Nib drew something. Click the line where Nib first goes wrong.
Make it yoursChange your app on purpose, then try it on someone.
Make it yours: Clear and Undo
Add a Button ClearButton (text Clear) under the drawing, moving Add down a little, and an event: ClearButton is clicked → Clear Drawing.
Add UndoButton (text Undo) beside it: UndoButton is clicked → Undo the last line on Drawing.
Want more? Set pen colour on Describe's start, with a different colour for each value (an If on Chosen).
Try it yourselfYour edits are saved in this browser.
A ClearButton on Describe clears the Drawing.
Run your program. This ticks when your code does all of the above.
An UndoButton on Describe takes back the last line.
Run your program. This ticks when your code does all of the above.
Lesson done. You've finished every step you need.
Now you can
Add a Drawing and clear it when a screen starts.
Keep what the user drew in a variable with Drawing.picture.
Show a picture the app made in an Image.
Explain why one variable keeps only the latest drawing.
Students add drawing to the values journal: a Drawing object on Describe (cleared when the screen starts), Drawing.picture kept in a variable when Add is clicked, and an Image on the Journal screen that shows it with Set picture to the one in. They find out that action order matters (Nib clears the page before keeping it) and that one variable keeps only the latest drawing, which sets up tables in Data apps. About 45 minutes.
I can add a Drawing and clear it when a screen starts.
I can keep what the user drew in a variable with Drawing.picture.
I can show a picture the app made in an Image.
I can explain why one variable keeps only the latest drawing.
Before class
This lesson starts from the finished values journal with room made for a drawing (Add moved down on Describe, the list shorter on Journal). Students who missed the journal lesson can still do it: the first step has them use the finished app.
A drawing is made while the app runs. Drawing.picture turns it into a picture the app keeps in the browser (on this device, nothing is sent) and names it, such as media:7f3a09c2. Variables, lists and tables hold that name. Drawings, not photos, so there are no faces.
If a student clicks Add without drawing anything, the Journal says "There is no picture yet". That's honest: there's nothing to show. An If (LastDrawing is not "") is a fine extra for a quick student.
The second check question is the set-up for Data apps › A journal with drawings, where a table keeps a drawing with every entry.
Handing in: drawings are made while the app runs, so a Share link carries the app but not the student's entries. To hand in entries with their drawings, students use Save and include what the app kept (a .zip).
Running the lesson
Try it: ask students to watch LastDrawing on the left as they click Add. What does media:… mean?
Build 3: checkpoint: does the drawing show on the Journal? If it says there's no picture, did they draw before Add?
Check: take a vote on the two-entries question before anyone tries it.
The hard part (on purpose)
The two picture actions look alike. Set picture to picks a picture while you design; Set picture to the one in works one out while the app runs. If students pick the first, the list of choices has no drawing in it: that's the clue.
When students get stuck
The Journal says 'There is no picture yet'. Ask: Did you draw before you clicked Add? Which runs first in your Add event: Clear or Set variable? Fix: Draw first; and keep the picture before clearing (or clear only on start of screen).
The Image shows a star, not the drawing. Ask: Which picture action did you use? Fix: Use Set LastImage picture to the one in, with LastDrawing.
The drawing from last time is still there on Describe. Ask: What happens when the Describe screen starts? Fix: Add Clear Drawing to On start of screen.
Stretch and support
Stretch: Set the pen colour by value on Describe's start: an If on Chosen, with a colour for each value (Set pen colour of Drawing to "red").
Support: Do Build 1 together on the board; pairs do Builds 2 and 3.
Where it leads
Next: Show it's done: photos, the same idea with a Photo, a picture per chore. In Data apps, A journal with drawings keeps a drawing with every entry, in a table.
What each step is for
Try the finished app: Using the finished app first shows where the drawing is made, where it's kept and where it's shown, before any of it is built.
Build 1: a space to draw: A Drawing is an object like a button, but what it holds is made by the user while the app runs.
Build 2: keep the drawing: Drawing.picture turns what's on the page into a picture the app keeps, and a variable carries it to the next screen, as Chosen carries the value.
Build 3: show it on the Journal: "Set picture to the one in" works out the picture while the app runs, so it can show something the user made, not just a picture chosen in Design.
Check: order and what's kept: Tracing when the picture is read, and what the variable holds after two entries, shows why action order matters and what a single variable can't do.
Make it yours: Clear and Undo: Clear and Undo are ordinary button events with Drawing actions, so a user can fix a drawing without starting the entry again.