You have learned how to use the text window and the graphics window. You have also learned about various statements, properties, and operations. Now, meet your new friend in Small Basic—the Turtle. With the help of the Turtle, you can draw shapes and graphics on the screen. You can hide the Turtle by using the Hide operation.Code:Turtle.Show()
When you click Run on the Toolbar or press F5 on the keyboard, the Turtle draws a colored, square graphical design on the screen.Code:GraphicsWindow.Title = "Turtle Graphics"GraphicsWindow.Height = 320GraphicsWindow.Width = 300GraphicsWindow.PenColor = "purple"Turtle.Show()Turtle.Speed = 8Turtle.X = 150Turtle.Y = 150For i = 0 To 200 Step 5 Turtle.Move(i) Turtle.Turn(90)EndFor
Solution: GraphicsWindow.Height = 400GraphicsWindow.Width = 400GraphicsWindow.Title = "Turtle Graphics"Turtle.Show()Turtle.Speed = 10Turtle.X = 100Turtle.Y = 200For i = 0 To 200 Step 5 GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()Turtle.Move(i) Turtle.Turn(150)EndForTurtle.PenUp()Turtle.Move(300)Turtle.Turn(105)Turtle.Move(150)Turtle.PenDown()For i = 0 To 200 Step 5 GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()Turtle.Move(i) Turtle.Turn(150)EndFor
2.2 turtle graphics
1.
Microsoft® Small Basic<br />Turtle Graphics<br />Estimated time to complete this lesson: 1 hour<br />
2.
Turtle Graphics<br />In this lesson, you will learn about:<br />Using the Turtle object to move the Turtle on the screen.<br />Using the various properties and operations of the Turtle object to create graphics.<br />Drawing colorful designs by using the Turtle object in For..EndFor loops.<br />
3.
Meet the Turtle <br />The Turtle is displayed on the screen.<br />Meet your new friend in Small Basic—the Turtle! The Turtle helps you draw interesting graphics on the graphics window.<br />You can display the Turtle by using the Show operation. <br />Click the button on the toolbar.<br />
4.
Properties and Operations of the Turtle Object<br />You can give commands to the Turtle by using the Turtle object. In turn, the Turtle draws graphics on the screen. Let’s look at some of these functions…<br />To set the location of the Turtle on the screen, you can specify the x- and y-coordinates by using the X and Y properties of the Turtle object. <br />To move the Turtle for a particular distance, you can use the Move operation. Similarly, you can use the MoveTo operation, and specify the x- and y-coordinates of the location where you want the Turtle to move. <br />To draw with the Turtle, you use the PenDown operation. If you want the Turtle to stop drawing on the screen, use the PenUpoperation.<br />
5.
Properties and Operations of the Turtle Object<br />Let’s have a look at some more functions…<br />To set the speed of the Turtle, you use the Speed property. You can choose a value from 1 to 10, 1 being the slowest and 10 being the fastest.<br />To turn the Turtle, use the Turn operation. When using this operation, you define an angle in degrees. Alternatively, you can also use the TurnRightandTurnLeftoperations, which turn the Turtle by 90 degrees to the right and left, respectively.<br />To turn the Turtle by a specific angle of rotation, you can use the Angle property and define the angle of rotation in degrees. The default angle of the Turtle is 0 degrees. An angle of 0 degrees means the turtle is facing up on the screen.<br />
6.
Making the Turtle Move<br />Let us start by making the Turtle draw a simple triangle on the screen.<br />output<br />Click the button on the toolbar.<br />
7.
Having Fun with the Turtle<br />Now that you know how to communicate with the Turtle, let’s use it for some fun activities.<br />Let’s use the For loop and instruct the Turtle to move and turn at specific distances and angles, creating a unique graphical design in the process.<br />You can use the PenColor property of the GraphicsWindow object to add color to your design.<br />
8.
Having Fun with the Turtle<br />You can also use the Turtle to create multiple, colorful graphics on the screen. Let’s look at a program that provides our desired output.<br />output<br />
9.
Let’s Summarize…<br />Congratulations! Now you know how to:<br />Use the Turtle object to move the Turtle on the screen.<br />Use the various properties and operations of the Turtle object to create graphics.<br />Draw colorful designs by using the Turtle object in For..EndFor loops.<br />
10.
It’s Time to Apply Your Learning…<br />Write a program to display a Turtle and use it to draw colorful graphics by performing the following steps:<br /><ul><li>Set the height and width of the graphics window to 400.
11.
Use the Turtle to draw two star-shaped graphics on the screen.
12.
Format the stars to be separate and colorful.</li>
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.
Be the first to comment