Objective: Build an app allows the user to draw on an Image.
Create 3 Color Buttons
Add a Canvas with an Image
A “Wipe” Button to clear the canvas
Watch the video about the Paint Pot app you will build today.
What new component will you need to create Paint Pot?
In App Inventor, we use the "initialize global ______ to" block to create a variable. In this case, we are calling the variable dotSize.
We can give the variable an initial value, such as the number 5, the color green, or the text large.
The value of the variable can change, depending on the situation.
In today's tutorial, you will create a variable called "dotSize", which will determine the size of the dots on the canvas.
You will build buttons which will allow you to change the size of the dot by changing the value of the variable. It will look like these blocks -->
Watch how to define a variable in App Inventor:
Variables that store numbers, such as dotsize, can be used in arithmetic.
To see this, pull an addition block and a number block out of the Math drawer:
Notice that the slots in the addition block can fit values (such as 0) and variables (such as dotsize):
This creates an expression whose value is (dotsize + 0).
Since we have initialized the dotsize to 5, this expression has the value 5 because 5 + 0 = 5.
This expression block can itself be plugged into any slot that fits a value.
For example, we can plug it into dotsize’s setter block:
The value of dotsize is set to the result of the expression which is its current value + 1.
dotsize will now have the value 6.
The value of a variable can change (vary) multiple times.
In the first examples below, dotsize initializes to 5 (first line) but changes to 0 when the second line of code is executed and to 10 when the third line of code is executed (0 + 10 = 10).
Note how the value of dotsize changes as the code is executed
Test your app and check for bugs. As a reminder, here is how to do this:
Start the the MIT AI2 Companion app on your phone or tablet.
In App Inventor, click Connect and then select AI Companion. This will display a 6-letter code both as a QR code and as plain text.
On the device, scan the barcode or type in the 6-letter code and click Connect to App Inventor.
Click here for solutions
Review the code from your Paint Pot app and answer the following questions:
What events does this app respond to? Name each event and describe the response.
What do the X and Y properties represent in the when Canvas1.Touched event handler?