SlideShare a Scribd company logo
Microsoft® Small BasicExploring ShapesEstimated time to complete this lesson: 1 hour
Exploring ShapesIn this lesson, you will learn about:Creating shapes by using the Shapes object.Using various operations of the Shapes object.Animating shapes on the screen.
Introduction to the Shapes ObjectSo far, you have learned to use the GraphicsWindow and the Turtle objects to draw patterns in Small Basic.This lesson introduces you to the Shapes object offered by Small Basic! You can use the Shapes object to add, rotate, and animate the shapes in the graphics window. You can color your shapes by using specific properties of the GraphicsWindow object.
Operations of the Shapes ObjectUsing certain operations of the Shapes object, you can give a vibrant look and feel to the shapes you create. Some of these operations are:AddImage
AddRectangle
HideShape
ShowShape
SetOpacity
GetOpacity
Move
Animate
ZoomOperations of the Shapes ObjectLet’s look at an example to demonstrate these operations…outputIn this example, we have used the ShowShape, HideShape and SetOpacity operations of the Shapes object to perform various actions on the rectangle shape.
Operations of the Shapes ObjectNow let’s understand these operations in detail…HideShape—This operation allows you to hide a shape displayed on the graphics window.ShowShape—This operation allows you to display a shape on the graphics window.AddRectangle—Using this operation, you can draw a rectangle on the graphics window. SetOpacity—You can set the opacity of a shape by using the SetOpacity operation. You must specify the name of the shape and an opacity level from 0 to 100.GetOpacity—This operation gets the opacity of a shape. You must specify the name of the shape as a parameter to this operation.
Operations of the Shapes ObjectLet’s look at another example to demonstrate some more operations…In this example, we have used the AddImageoperation to insert an image on the screen. Next, we have used the Move, Animate and Zoom operations to perform various actions on the image.

More Related Content

2.3 exploring shapes

  • 1. Microsoft® Small BasicExploring ShapesEstimated time to complete this lesson: 1 hour
  • 2. Exploring ShapesIn this lesson, you will learn about:Creating shapes by using the Shapes object.Using various operations of the Shapes object.Animating shapes on the screen.
  • 3. Introduction to the Shapes ObjectSo far, you have learned to use the GraphicsWindow and the Turtle objects to draw patterns in Small Basic.This lesson introduces you to the Shapes object offered by Small Basic! You can use the Shapes object to add, rotate, and animate the shapes in the graphics window. You can color your shapes by using specific properties of the GraphicsWindow object.
  • 4. Operations of the Shapes ObjectUsing certain operations of the Shapes object, you can give a vibrant look and feel to the shapes you create. Some of these operations are:AddImage
  • 10. Move
  • 12. ZoomOperations of the Shapes ObjectLet’s look at an example to demonstrate these operations…outputIn this example, we have used the ShowShape, HideShape and SetOpacity operations of the Shapes object to perform various actions on the rectangle shape.
  • 13. Operations of the Shapes ObjectNow let’s understand these operations in detail…HideShape—This operation allows you to hide a shape displayed on the graphics window.ShowShape—This operation allows you to display a shape on the graphics window.AddRectangle—Using this operation, you can draw a rectangle on the graphics window. SetOpacity—You can set the opacity of a shape by using the SetOpacity operation. You must specify the name of the shape and an opacity level from 0 to 100.GetOpacity—This operation gets the opacity of a shape. You must specify the name of the shape as a parameter to this operation.
  • 14. Operations of the Shapes ObjectLet’s look at another example to demonstrate some more operations…In this example, we have used the AddImageoperation to insert an image on the screen. Next, we have used the Move, Animate and Zoom operations to perform various actions on the image.
  • 15. Operations of the Shapes ObjectMove—Using this operation, you can set the new location of the shape on the graphics window. You must specify the name of the shape, and the x- and y-coordinates of the new location.Animate—This operation animates a shape to a new position. You must specify the name of the shape, the x- and y-coordinates of the new position, and the duration of the animation.AddImage—Using this operation, you can insert an image on the graphics window. Zoom—The Zoom operation scales a shape by using a particular zoom level. You must specify the name of the shape and select a zoom level between 0.1 and 20.
  • 16. Operations of the Shape ObjectYou can use the Shapes object to add different types of shapes in your program.You can then perform various operations on the Shapes object, such as moving the shape, setting its opacity, or adding a zoom effect. Now, let’s look at an example…Click the button on the toolbar.
  • 17. Animating a ShapeLet’s see an example to animate a shape by using the Shapes object.In this example, you animate a shape from its original position to a new position and back to its original position on the graphics window.
  • 18. Rotating a ShapeLet’s explore some more operations of the Shapes object by writing a program to rotate a shape.outputWhen you execute the program, the rectangle rotates on the graphics window.Click the button on the toolbar.In this example, you use a For loop to rotate a shape along its original position on the graphics window.
  • 19. Fun with ShapesIn addition to drawing shapes of different styles and sizes, you can also create unique shape designs by using conditions and loops in your program.For example, you can use a For loop to create multiple rectangles in random colors…output
  • 20. Let’s Summarize…Congratulations! Now you know how to:Create shapes by using the Shapes object.Use various operations of the Shapes object.Animate the shapes on the screen.
  • 21. It’s Time to Apply Your Learning…Write a program to display a graphics window, and perform the following steps:Add a line and a circle to the graphics window.
  • 22. Set the color, size, and location for the shapes as required.
  • 23. Animate the circle so that it moves from the left side of the graphics window to the right, on top of the line.

Editor's Notes

  1. You can create shapes on the screen by using the Shapes object. Take a look at the example on the screen:First, you use the PenWidth, PenColor, and BrushColor properties of the GraphicsWindow object to set the color and width of the pen, and the color of the brush that you use to draw the shapes.In this example, you want to draw two rectangles of the same size, so you use the AddRectangle operation of the Shapes object, and define the parameters for the width and height of the rectangle. You set the location of the rectangles on the graphics window; use the Move operation and define the parameters for the x-coordinate and y-coordinate to where you want the rectangle to move.To set an opacity level for a rectangle, you use the SetOpacity operation with parameters that include the name of the shape and the opacity level.Next, you can zoom a rectangle, by using the Zoom operation. Simply specify the parameters for the name of the shape, and the zoom level on the x-axis and y-axis, respectively. Check the output of your program by clicking the Run button on the toolbar or pressing F5 on the keyboard. Notice the difference between the two rectangles after using operations of the Shapes object on one of the rectangles.Code:GraphicsWindow.Title = "Exploring Shapes"GraphicsWindow.Height = 350GraphicsWindow.Width = 450GraphicsWindow.PenWidth = 2GraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Purple"rectangle1 = Shapes.AddRectangle(100, 100)Shapes.Move(rectangle1, 50, 80)rectangle2 = Shapes.AddRectangle(100, 100)Shapes.Move(rectangle2, 300, 80) For i = 1 To 4Program.Delay(1000) Shapes.Zoom(rectangle1, i * 0.4, i * 0.4) Shapes.SetOpacity(rectangle1,i * 5)EndFor
  2. In addition to drawing shapes of different styles and sizes, you can also create unique shape designs by using conditions and loops in your program. For example, look at the displayed code. You use a For loop to create multiple rectangles, positioned in ascending order by size. You also use the GetRandomColoroperation of the GraphicsWindow object to randomize the color of the rectangles. When you click the Run button on the toolbar or press F5 on the keyboard, the program executes, demonstrating a colorful display of rectangles.Code:GraphicsWindow.Title = "Exploring Shapes"GraphicsWindow.Height = 500GraphicsWindow.Width = 700For i = 0 To 20GraphicsWindow.PenWidth = 0.5GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor() rectangle1 = Shapes.AddRectangle(i * 20, i * 10)Shapes.Move(rectangle1, i * 10, i * 10)EndFor
  3. Solution: GraphicsWindow.Title = "Exploring Shapes"GraphicsWindow.Height = 200GraphicsWindow.Width = 300 GraphicsWindow.PenColor = "Purple"base = Shapes.AddLine(0, 0, 300, 0)Shapes.Move(base, 0, 100)GraphicsWindow.PenColor = "Black"GraphicsWindow.BrushColor = "Cyan"circle = Shapes.AddEllipse(50, 50)Shapes.Move(circle, 0, 50)Shapes.Animate(circle, 250, 50, 1000)