Graphics and Procedures Programming Right from the Start with Visual Basic.NET 1/e 5
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 2 Objectives Learn the Visual Logic graphics commands and how they work Appreciate the concept of structured design Know the process for creating procedures
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 3 Objectives (cont.) Understand the role of procedure arguments Realize the difference between formal arguments and actual arguments Develop and evaluate solutions that utilize graphics and procedures
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall Graphics Visual Logic graphics are a variation on Logo Programming Language, which has been used in educational settings for over three decades.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 5 Forward and Turn Right The Forward command moves the pen a specified number of units. The Turn Right command rotates the drawing direction a specified number of degrees.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 6 Using Loops Two Patterns Emerge… –Repetition of the commands Forward and Turn Right –The degrees the drawing direction must turn right are different for each shape and are based on the number of sides in the shape
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall Working with Color The pen draws with black ink and is 1 unit in width. Visual Logic provides commands for changing the pen’s color and width.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 8 Set Color and Pen Width The Set Color command allows the developer to select any color from the standard color dialog box. The Pen Width command changes the thickness of the drawing pen.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 9 Color Forward The Color Forward command moves the pen through the three base colors of red, green, and blue. The Color Forward command typically occurs inside a loop.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall Structured Design Using Procedures Structured design means a problem is broken into smaller pieces, each of which is solved individually. A procedure is a series of instructions that are grouped together and treated as a single unit.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall Structured Design Using Procedures (cont.)
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 12 Rotating Flags Problem
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 13 Rotating Flags Problem (cont.)
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall Procedures with Arguments An argument (or parameter) is a piece of information that is communicated between the calling code and the procedure. The argument is referred to as an actual argument at the time of the call and as a formal argument in the called procedure.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 15 Rotating Shapes Program
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 16 Visual Logic Implementation
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall Recursion A recursive procedure is a procedure that calls itself. To prevent infinite recursion, a recursive procedure typically first performs a test on one of its arguments to check for a base case.
Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 18 Chapter Summary Visual Logic graphics include commands, such as Forward and Right, that move a virtual pen across the screen. Procedures allow code to be written once and called many times. An actual argument is a value or reference passed from the calling code to a procedure.
Graphics and Procedures Programming Right from the Start with Visual Basic.NET 1/e 5