Can You Draw A Triangle With This Set Of Logo Commands? Discuss How Or Why Not.
iv.iv.1. Introduction and Goals¶
| In this lesson y'all will design, implement, and test algorithms to depict unproblematic shapes. For example, you lot will write an algorithm to draw a face fabricated up of squares and lines similar the 1 in the video below. In our implementation of Logo, nosotros've replaced the Turtle with an Android. Here are the cartoon commands yous can utilize:
| |
| (Instructor Tube version) | Learning Objectives: I volition learn to
Language Objectives: I will be able to
|
4.4.2. Learning Activities¶
- text-version
- |
- short handout
- |
- YouTube video
- graph newspaper
- |
- AP CSP reference sheet
- |
- TeacherTube video
Introduction
Logo is a programming language that was invented in the 1960s by Seymour Papert primarily for educational utilize. Papert believed that we learn best when we are building our ain knowledge and ideas – when we build tangible objects that help us create our own mental models to empathise the world around us.
In this lesson the tangible objects you will build are algorithms for drawing simple shapes.
Logo's best known feature is its turtle, an actual picture of a turtle, that the user tin control by telling it how to move. As the turtle moves it leaves behind a trail, in other words it draws. Imagine the trail left behind by an beast equally it moves around in the sand on a embankment. Logo can be used to create very sophisticated algorithms and very sophisticated drawings, such every bit the pattern on the left.
Logo Commands
The Logo programming language consists of a prepare of archaic commands that control the turtle. You saw something similar these commands in the Blockly Maze exercises that you did. Taken together these commands constitute an brainchild – a language – for drawing shapes. The App Inventor template below has these Logo Commands already written for you.
Existing code segments that you can utilise are often called libraries. A software library contains procedures that may be used in creating new programs. The use of libraries already written for you simplifies the task of creating complex programs. You lot can too write your ain libraries of code to utilize in other App Inventor projects using the haversack feature to share them.
In this lesson nosotros take deliberately created a fairly weak abstraction – one that lets you draw shapes, but only with some difficulty. As you're working on the shapes, think about how you would improve the drawing language; that is, assistance us retrieve about a better abstraction for drawing shapes.
Tutorial
To get started, open App Inventor with the Logo i Template in a separate tab and follow along with the tutorial below. If the template does not open, download the .aia file, go to App Inventor and practise File/Import and import in the downloaded .aia file. If yous are using iOS companion, please change the Canvas Height property to Fill Parent instead of 100% so information technology does not embrace the buttons.
When the template opens, you lot volition see a lot of collapsed blocks. Practice NOT OPEN OR EDIT THESE BLOCKS!
You tin either watch the video tutorial, read the text tutorial or use the curt handout.
(Instructor Tube version)
There are three basic types of control structures in designing algorithms: sequence, selection, and repetition. But most any algorithm you can call up of can be built using these three types of controls. Equally you lot saw in the tutorial, procedures and loops made drawing a square much easier than using a list of commands. Note the big divergence between the 2 algorithms below. The algorithm on the left uses a elementary sequence with copies of the forward and turn blocks to depict a foursquare, whereas the algorithm on the right uses repetition, a for-each counting loop, a much more applied and general approach. The for-each block in this case repeats the statements in its practise-slot iv times.
Exercises (Pair Programming)
After doing the tutorial in a higher place, you have drawn 20x20 square using a loop and then refactored the lawmaking to use procedural abstraction to create the procedure square20.
For these exercises below, earlier coding your solution in App Inventor, it would be a good thought to start write out the solution in pseudocode and hash out it with your coding partner. Download and print this graph paper to apply when designing your algorithms in the post-obit exercises.
- 40x40 Square: Pattern an algorithm for drawing a 40-by-40 square. And so implement your algorithm past defining a procedure named square40 that draws a twoscore-by-40 foursquare. Then alter the ButtonDraw.Click handler and so that it calls the square40 procedure. To simplify this algorithm, use a for-each loop to repeat the commands needed to describe a square.
- Line40: Define a procedure proper name line40 that draws a line of length twoscore. Test it by calling it from the ButtonDraw.Click handler.
- Refactor your square40 process to utilise a for-each loop and the line40 procedure to draw a 40-past-40 square. As nosotros learned in an earlier lesson, refactoring means to revise your code without irresolute the basic functionality of your app. Test your algorithm by calling information technology from the ButtonDraw.Click handler.
- Triangle: Can you draw a triangle with this prepare of Logo commands? Talk over with your partner how the programmer who designed this Logo app could alter some of the basic commands so that it would be possible to draw a triangle and other shapes.
-
Describe a Face: Design an algorithm for drawing a face with a large foursquare for the head, 2 small squares for eyes, and a line for the oral cavity, as shown below. Design and define whatsoever other procedures you need to help simplify this problem -- e.1000., the outline of the caput, the eyes, and so on. Make advisable apply of loops in your algorithm.
Blueprint showtime, and so code: This algorithm will be quite a flake more than circuitous than any of the others yous've done. You lot'll have to utilise the penUp process to elevator the Android off of the drawing sheet. And you'll have to plan how far to movement forward to get the optics and rima oris placed properly. You will definitely desire to plan and test this algorithm on newspaper or on the board earlier trying to program it. Utilise your graph newspaper to help figure the distances.
Once y'all've designed a correct algorithm, implement information technology by defining a procedure named drawFace that draws the face. And so test your code to make certain y'all got it right. Post a screenshot of your face drawing on your portfolio.
Here is a plan to follow:- First, draw a scale model of your confront. For this y'all need to decide what each square on the graph paper represents -- e.k., is each square x pixels? v pixels?
- Based on your model, write out the commands for drawing the face up using pencil and paper -- i.due east., write out your algorithm correct on the graph paper.
- Code your face-drawing algorithm and exam it. Define a procedure named drawFace and call it in the ButtonDraw.Click procedure. Go on testing and refining your algorithm until it correctly draws a face.
- Brainchild: In one case you can successfully drawn the face, refactor your code to make practiced apply of procedures that break the confront into parts, e.g., head, left eye, correct middle, oral cavity, moves.
- Refactor your drawFace procedure by breaking it upward into smaller procedures. This will arrive easier to understand. For example, here'southward a possible algorithm you might utilise:
As their names advise, the sub-procedures will include the various penUp, penDown, and movement commands to position the optics and oral fissure correctly and to return the Android to its starting position (at the bottom left corner of the face). Recollect: Ideally, your algorithms should get out the Android in the same state when it is finished drawing the head equally when information technology started.To drawFace practice: square100 positionAndDrawLeftEye positionAndDrawRightEye positionAndDrawMouth returnToStartOfFace
AP CSP Pseudocode: Control Structures
In the AP CSP exam, there are questions that involve a robot moving in a grid following elementary commands similar to our Logo App. The commands used in the exam are:
- MOVE_FORWARD() : The robot moves 1 foursquare forward in the management it is facing.
- ROTATE_RIGHT() : The robot turns correct xc degrees, staying in the same foursquare but facing right.
- ROTATE_LEFT() : The robot turns left 90 degrees, staying in the same foursquare but facing left.
- CAN_MOVE( management ) : This command can be used with 4 possible directions: left, right, forward, and backward. It returns true if at that place is an open up square in the specified direction from the square that the robot is in.
The AP CS Principles Exam uses a text-based and a cake-based pseudocode for questions that involve lawmaking. The AP CSP reference sheet is provided during the exam describing this pseudocode. The AP CSP pseudocode for basic control structures compared to App Inventor blocks is shown below:
| Function | Text Way | Block Way | App Inventor |
|---|---|---|---|
| Assignment | a ← expression | | |
| Display | Brandish(expression) | | |
| Expressions | a + b, a - b, a * b, a/b, a mod b | | |
| Selection (else optional) | IF (condition) { block of statements } ELSE { cake of statements } | | |
| Condition | a = b, a ≠ b, a < b, a > b,a <= b,a >= b Non(condition), (status AND status), (condition OR condition) | | |
| Repetition | Echo n times { block of statements } | | |
| Repetition | Repeat UNTIL (status) { block of statements } | | |
The AP pseudocode robot navigation commands tin exist used within pick and repetition control structures similar below:
Repeat UNTIL ( GoalReached() ) { IF (CAN_MOVE(forrad)) { MOVE_FORWARD() } } In the Repeat UNTIL(condition) loop:
- The code inside the loop is repeated until the boolean condition evaluates to true.
- If the status evaluates to true initially, the loop body is not executed at all.
- There can be an infinite loop if the ending condition never evaluatea to truthful.
Annotation that the curly brackets { } are used to indicate the start and terminate of a block of code, for example the repetition control construction. The parenthesis () are used later a procedure name to indicate that information technology is a procedure and to give information technology whatsoever data it might need inside the parentheses. Some practice bug using these commands are below.
iv.four.3. Summary¶
In this lesson, you lot learned how to:
iv.4.iv. Self-Check¶
Q-2: What is the name of the calculator language that uses a turtle to implement drawing algorithms? Type your answer into the textbox (spelling counts).
- True
- Mistakes are welcome here! Try reviewing this...An algorithm can indeed be expressed in a programming language, such as App Inventor or Logo, but it can also be expressed in English or pseudocode.
- False
- Correct. An algorithm can indeed be expressed in a programming language, such as App Inventor or Logo, merely it can also exist expressed in English language or pseudocode.
Q-3: True or False? An algorithm is a precise sequence of statements that must be expressed in a computer language.
- A foursquare
- Don't worry, it's hard! Allow's go dorsum and try it again. Discover that there are ii forwards followed by a turn followed past ane forward and so on. This algorithm draws a rectangle.
- A right angle
- Don't worry, information technology's hard! Let's go back and endeavour it over again. This algorithm draws a rectangle.
- A rectangle
- That's correct. This algorithm would draw a rectangle whose length is twice as long as its width.
- A circle
- Don't worry, information technology'south hard! Let'due south go dorsum and try information technology once more. This algorithm draws a rectangle.
Q-4:
Bold that forward tells the Android to move forrard past x pixels and turn tells information technology to plough right past 90 degrees, what shape would be fatigued by this algorithm?
forwardforward
plow
forward
turn
frontwards
forward
turn
forwards
turn
Q-five:
Given the post-obit lawmaking segment, which value of 10 would cause an space loop?
Echo UNTIL (x > 0) { 10 ← x - 1 } 4.4.5. Sample AP CSP Questions¶
Q-8:
The post-obit question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom left square of the grid and facing right.
Consider the following lawmaking segment, which moves the robot in the grid.
Which of the post-obit shows the location of the robot afterwards running the code segment?
Q-ten:
AP 2022 Sample Question: The following process is intended to return the number of times the value val appears in the list myList. The process does not work as intended.
Line ane: PROCEDURE countNumOccurences(myList, val) Line 2: { Line iii: FOR EACH item IN myList Line 4: { Line 5: count 0 Line vi: IF(item = val) Line seven: { Line 8: count count + i Line 9: } Line 10: } Line xi: RETURN(count) Line 12: } Which of the following changes tin be made so that the procedure will work every bit intended?
Q-11:
AP 2022 Sample Question: Consider the following process.
| Procedure Call | Explanation |
|---|---|
| drawCircle(xPos, yPos, rad) | Draws a circle on a coordinate grid with middle (xPos, yPos) and radius rad |
The drawCircle process is to exist used to describe the following figure on a coordinate grid.
Which of the post-obit code segments can be used to draw the figure?
Select two answers.
4.four.half dozen. Reflection: For Your Portfolio¶
Reply the following portfolio reflection questions equally directed by your instructor. Questions are also bachelor in this Google Dr. where y'all may utilize File/Brand a Copy to make your own editable copy.
Source: https://runestone.academy/ns/books/published/mobilecsp/Unit4-Animation-Simulation-Modeling/Logo-Part-I.html
Posted by: hammittlever2000.blogspot.com

0 Response to "Can You Draw A Triangle With This Set Of Logo Commands? Discuss How Or Why Not."
Post a Comment