Post-PaintPot-Solution

These discussion questions concern the PaintPot tutorial, chapter 2 of the App Inventor book. Concepts include event-handlers, event parameters (arguments), and variables. For related reading, see chapter 2, 14 (app architecture) and 16 (an app's memory).

1. Draw the event-handlers that are involved with lines being drawn a particular color.

There are three event handlers related to the user clicking a button to change the line color (PaintColor). An example is:

   when RedButton.Click
        DrawingCanvas.PaintColor -> red

There is another event-handler which handles the user dragging to actually draw the lines:

   when DrawingCanvas.Dragged  startx, starty, prevx, prevy, currentx, currenty
        DrawingCanvas.DrawLine(prevx,prevy, currentx,currenty)

DrawLine draws in the color that is stored in the PaintColor property. So the three button events change a memory cell (the DrawingCanvas.PaintColor property) and the DrawLine function in the Dragged event looks at the property to know what color to draw.


2. Draw the event-handlers that are involved with the dots being drawn big or small.

This question is similar to the above one. In this case, the user clicks on the BigButton or SmallButton. But there is no property for "dotsize" in DrawingCanvas. Thus a variable, named dotsize, must be defined to store the 2 or the 8 (the specified sizes). The Touched event then uses the value in the dotsize variable as the radius:

when BigButton.Click
    set dotsize to 8

when DrawingCanvas.Touched x,y
    DrawingCanvas.DrawCircle(x,y, radius = dotsize)

So the variable dotsize stores the number and the function DrawCircle uses it for its radius.


3. In PaintPot, there are parameters for some events. How are event parameters different than the parameters that are part of a call to a function (e.g., Sound.Vibrate (500) ? Who sets the value of the parameter?

Event parameters provide the information about the event. They are not set by the program, but by the system. So when the user touches the screen, the Touched event has three event parameters, x,y, and touchedSprite. The programmer can use those values, but the programmer doesn't set them, as she does with function parameters.

Function parameters provide the information a function needs to do its job. The programmer specifies this information in the call to the function, e.g, in the call to DrawCircle, the programmer specifies the location (x,y) and the radius (dotsize).


4. In PaintPot you define a variable.

a. What variable do you define?

dotsize

b. How do you define it? Once you define it, what blocks appear in "My Definitions"

In the Definitions drawer, there is a variable block. After dragging it out, you can provide a name for the variable and you can plug in an initial value.

c. You don't define a variable for 'PaintColor', the color of the paint on the canvas. Why not?

PaintColor is a property of DrawingCanvas, so there's already a memory cell for it.

d. Define the term variable? How is a variable different than a property? How is a variable similar to a property.

A variable is a "named memory cell", a spreadsheet-like cell that can store numbers, text, etc. A component property is also a named memory cell. The difference is that properties are part of a component,while variables are on their own.

Comments