2.3   exploring shapes
Upcoming SlideShare
Loading in...5
×
 

2.3 exploring shapes

on

  • 1,139 views

 

Statistics

Views

Total Views
1,139
Views on SlideShare
1,139
Embed Views
0

Actions

Likes
0
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

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 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
  • 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
  • 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)

2.3   exploring shapes 2.3 exploring shapes Presentation Transcript

  • Microsoft® Small Basic
    Exploring Shapes
    Estimated time to complete this lesson: 1 hour
  • Exploring Shapes
    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.
  • Introduction to the Shapes Object
    So 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.
    View slide
  • 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 View slide
    • AddRectangle
    • HideShape
    • ShowShape
    • SetOpacity
    • GetOpacity
    • Move
    • Animate
    • Zoom
  • Operations of the Shapes Object
    Let’s look at an example to demonstrate these operations…
    output
    In 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 Object
    Now 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 Object
    Let’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.
  • Operations of the Shapes Object
    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.
    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.
  • Operations of the Shape Object
    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…
    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
    When 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.
  • Fun with Shapes
    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…
    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.