2.3 exploring shapes
DESCRIPTION
TRANSCRIPT
Microsoft® Small Basic
Exploring Shapes
Estimated time to complete this lesson: 1 hour
In 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.
Exploring Shapes
Introduction to the Shapes Object
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.
So far, you have learned to use the GraphicsWindow and the Turtle objects to draw patterns in Small Basic.
You can color your shapes by using specific properties of the GraphicsWindow object.
Operations of the Shapes Object
Using 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
Zoom
Operations of the Shapes Object
Let’s look at an example to demonstrate these operations…
In this example, we have used the ShowShape, HideShape and SetOpacity operations of the Shapes object to perform various actions on the rectangle shape.
OUTPUT
Operations of the Shapes Object
Now let’s understand these operations in detail…
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.
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.
Operations of the Shapes Object
Let’s look at another example to demonstrate some more operations…
In this example, we have used the AddImage operation to insert an image on the screen. Next, we have used the Move, Animate and Zoom operations to perform various actions on the image.
Operations of the Shapes Object
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.
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.
Move—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.
AddImage—Using this operation, you can insert an image on the graphics window.
You 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…
Operations of the Shape Object
Click the button on the toolbar.
Animating a Shape
Let’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.
Rotating a Shape
Let’s explore some more operations of the Shapes object by writing a program to rotate a shape.
OUTPUT
In this example, you use a For loop to rotate a shape along its original position on the graphics window.
Click the button on the toolbar.
When you execute the program, the rectangle rotates on the graphics window.
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, you can use a For loop to create multiple rectangles in random colors…
Fun with Shapes
OUTPUT
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.
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.
Set the color, size, and location for the shapes as required.
Animate the circle so that it moves from the left side of the graphics window to the right, on top of the line.