The need for input values is shown by sockets on the right edge of the command. For example, call Sound1.Vibrate needs to know the number of milliseconds to vibrate, set Label1.BackgroundColor needs to know the new background color of the label, and set Label1.text needs to know the new text string for the label. Some commands require one or more input values (also known as parameters or arguments) to completely specify their action. Here are some sample commands, some of which you may recognize from building HelloPurr: Most command blocks are purple or blue in color. A command is a block that specifies an action to be performed on the phone (e.g., playing sounds). When an event handler fires, it executes a sequence of commands in its body. When an event occurs on a phone, the corresponding event handler is said to fire, which means it is executed. Here are some examples of event handlers. Most event handlers are green in color and are stored at the top part of each drawer. E.g., when Button1.Click and when AccelerometerSensor1.Shaking in HelloPurr. This is specified by event handler blocks, which used the word when. Event HandlersĪpp Inventor programs describe how the phone should respond to certain events: a button has been pressed, the phone is being shaked, the user is dragging her finger over a canvas, etc. We will then use the Sharing.ShareFile to share the file at the path.This page explains how basic blocks work. When the function Canvas.save called, it will return the path where your drawing will be saved. We will able to create a rectangle using Canvas.DrawShape function by providing a list of all four points of a rectangle as below: Share Drawing Rectangle ToolĬreate a function named drawRectangle, that takes two diagonal points as arguments. In this example, we created a function named calculateRadius, calculate the result and return it as an argument for the Canvas.DrawCircle function. Then, calculate the radius by finding distance between two coordinates using formula below: We will use the coordinate of touch down as the center of circle and the coordinate of touch up as the edge of circle. To draw a circle using Canvas.DrawCircle function, we need to provide a value for circle radius. When user release their touch on the canvas, join the coordinate at that point with the initial stored coordinate to form a line. First, use variables to store the coordinate when the user touch down on the canvas.
Line tool is used to create a straight line on the canvas.
However, we can simulate the eraser effect by drawing lines with the paint colour set to the colour of your canvas. In MIT App Inventor, there isn’t any function to erase paint on canvas. The clear button will clear the canvas which can be implement easily by simply calling the Canvas.Clear function. Call the Canvas.DrawLine function if the tool in use is “pen”. When your user interacts with the canvas by dragging their finger on it, the Canvas.Dragged event will be triggered.
#Adding inputs to blocs app inventor update
Update the tool variable when PenButton is clicked. The variable tool is created to keep track of the drawing tool we are using so the functionality of each tool will not overlap. In the project, three sliders are used to modify the intensity of each colour and when the value of any slider changed, we will display the resulting colour using the ColourButton and update the canvas paint colour at the same time. Each colour’s intensity is represented using a value between 0 and 255. All colours can be produced by combining red, green and blue.