2.2   turtle graphics
Upcoming SlideShare
Loading in...5
×
 

2.2 turtle graphics

on

  • 2,739 views

 

Statistics

Views

Total Views
2,739
Views on SlideShare
2,362
Embed Views
377

Actions

Likes
2
Downloads
29
Comments
0

1 Embed 377

http://moodle.jwheatley.ac.uk 377

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 2.2 turtle graphics Presentation Transcript

  • Microsoft® Small Basic
    Turtle Graphics
    Estimated time to complete this lesson: 1 hour
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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
  • 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.
  • 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.
    • Use the Turtle to draw two star-shaped graphics on the screen.
    • Format the stars to be separate and colorful.