0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

2.2 turtle graphics

2,575

Published on

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
2,575
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
33
0
Likes
2
Embeds 0
No embeds

No notes for slide
• 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 = &quot;Turtle Graphics&quot;GraphicsWindow.Height = 320GraphicsWindow.Width = 300GraphicsWindow.PenColor = &quot;purple&quot;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 = &quot;Turtle Graphics&quot;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
• Transcript

• 1. Microsoft® Small Basic
Turtle Graphics
Estimated time to complete this lesson: 1 hour
• 2. Turtle Graphics
In this lesson, you will learn about:
Using the Turtle object to move the Turtle on the screen.
Using the various properties and operations of the Turtle object to create graphics.
Drawing colorful designs by using the Turtle object in For..EndFor loops.
• 3. Meet the Turtle
The Turtle is displayed on the screen.
Meet your new friend in Small Basic—the Turtle! The Turtle helps you draw interesting graphics on the graphics window.
You can display the Turtle by using the Show operation.
Click the button on the toolbar.
• 4. Properties and Operations of the Turtle Object
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…
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.
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.
To draw with the Turtle, you use the PenDown operation. If you want the Turtle to stop drawing on the screen, use the PenUpoperation.
• 5. Properties and Operations of the Turtle Object
Let’s have a look at some more functions…
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.
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.
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.
• 6. Making the Turtle Move
Let us start by making the Turtle draw a simple triangle on the screen.
output
Click the button on the toolbar.
• 7. Having Fun with the Turtle
Now that you know how to communicate with the Turtle, let’s use it for some fun activities.
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.
You can use the PenColor property of the GraphicsWindow object to add color to your design.
• 8. Having Fun with the Turtle
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.
output
• 9. Let’s Summarize…
Congratulations! Now you know how to:
Use the Turtle object to move the Turtle on the screen.
Use the various properties and operations of the Turtle object to create graphics.
Draw colorful designs by using the Turtle object in For..EndFor loops.
• 10. It’s Time to Apply Your Learning…
Write a program to display a Turtle and use it to draw colorful graphics by performing the following steps:
• 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.