Your SlideShare is downloading. ×
0
Microsoft® Small Basic<br />Graphics Window<br />Estimated time to complete this lesson: 1 hour<br />
Graphics Window<br />In this lesson, you will learn about:<br />Statements using the GraphicsWindow object.<br />Propertie...
Introducing the Graphics Window <br />So far, you have used the text window to understand the fundamentals of programming ...
Properties of the Graphics Window<br />You use the GraphicsWindow object to display a graphics window and draw colorful sh...
Properties of the Graphics Window<br /><ul><li>MouseX—You can use this property to find the x-position of the mouse relati...
MouseY—You can use this property to find the y-position of the mouse relative to the graphics window.
PenColor—You can use this property to change the color with which shapes are drawn on the graphics window.
PenWidth—You can use thisproperty to change the width of the pen used to draw shapes on the graphics window.
BrushColor—You can use thisproperty to change the color used to fill shapes drawn on the graphics window.</li></ul>Certain...
Operations on the Graphics Window<br />Some of the operations available for the GraphicsWindow object are:<br /><ul><li>Dr...
DrawEllipse
DrawLine
Upcoming SlideShare
Loading in...5
×

2.1 graphics window

2,053

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,053
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • You can choose from a variety of colors supported by Small Basic, categorized by their base hue. In your code, you can either specify the name of the color, or the hex color code.
  • In addition drawing shapes, you can also create colorful designs in your program by using conditions and loops for your shapes. For example, take a look at the displayed example. You use a For loop to create a barcode-like design with lines. You also use the GetRandomColoroperation to randomize the color of the lines. Another useful operation for the GraphicsWindow object is ShowMessage.WithShowMessage,you can display a message box in your program. You just needto provide two parameters—the message to be displayed and the title for the message box.On clicking the Run button on the toolbar or pressing F5 on the keyboard, the program is executed. Notice that along with your graphics window, a message box is displayed. The graphics window displays the random-colored barcode-like design that we defined in the code.Code:GraphicsWindow.Title = &quot;Graphics Window&quot;GraphicsWindow.BackgroundColor = &quot;White&quot;GraphicsWindow.Width = 325GraphicsWindow.Height = 200For i = 1 To 15GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()GraphicsWindow.PenWidth = iGraphicsWindow.DrawLine(i * 20, 20, i * 20, 180)EndForGraphicsWindow.ShowMessage(&quot;Create wonderful designs and shapes in Small Basic&quot;, &quot;Message&quot;)
  • You can insert images in your program by using the DrawImage operation of the GraphicsWindow object. The parameters for DrawImagerequire the image name, and the x- and y-coordinates of the points where the image is to be drawn. You can also insert resized images in your program by using the DrawResizedImage operation of the GraphicsWindow object. The parameters for DrawResizedImagerequire the image name, and the x- and y-coordinates of the points where the image is to be drawn, and the width and height of the image. You also have to define the image path. If the image is stored on a Web site or server, you can specify the URL. If the image is stored on your computer, simply specify the path to the image.When you click the Run button on the toolbar or press F5 on the keyboard, the program is executed. Notice that your graphics window is displayed, along with the resized image, at the set pixel location.You can also use the SetPixeloperation to draw a pixel on the graphics window at the location specified by the x- and y-coordinates.Code:GraphicsWindow.Title = &quot;Graphics Window&quot;GraphicsWindow.Width = 800GraphicsWindow.Height = 600image1 = &quot;C:Small BasicSunset.jpg&quot;GraphicsWindow.DrawImage(image1, 0, 0)image2 = &quot;C:Small BasicWinter.jpg&quot;GraphicsWindow.DrawResizedImage(image2, 100, 100, 200, 200)
  • Please Note: Ensure that the image exists at the location specified in the code.Solution:  GraphicsWindow.Show()GraphicsWindow.Title = &quot;A Graphics Window&quot;GraphicsWindow.Height = 640GraphicsWindow.Width = 800GraphicsWindow.BackgroundColor = &quot;Black&quot;GraphicsWindow.PenWidth = 10GraphicsWindow.PenColor =GraphicsWindow.PenColor = “Gold&quot;GraphicsWindow.DrawLine(65, 100, 65, 370)GraphicsWindow.PenColor =GraphicsWindow.PenColor = “Black&quot;GraphicsWindow.BrushColor =GraphicsWindow.BrushColor = “Cyan&quot;GraphicsWindow.DrawEllipse(70, 250, 100, 100)GraphicsWindow.FillEllipse(70, 250, 100, 100)For i = 1 To 10GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()GraphicsWindow.PenWidth = 2GraphicsWindow.Drawrectangle(100, i * 20, 50, 10)EndForimage1 = &quot;C:Small BasicWinter.jpg&quot;GraphicsWindow.DrawResizedImage(image1, 200, 100, 500, 500)GraphicsWindow.ShowMessage(&quot;Have a nice day!&quot;, &quot;Message&quot;)
  • Transcript of "2.1 graphics window"

    1. 1. Microsoft® Small Basic<br />Graphics Window<br />Estimated time to complete this lesson: 1 hour<br />
    2. 2. Graphics Window<br />In this lesson, you will learn about:<br />Statements using the GraphicsWindow object.<br />Properties of the GraphicsWindow object.<br />Operations of the GraphicsWindow object.<br />
    3. 3. Introducing the Graphics Window <br />So far, you have used the text window to understand the fundamentals of programming using Small Basic.<br />This lesson exposes you to some exciting graphic capabilities offered by Small Basic. <br />You start with a graphics window that you can display by using the GraphicsWindow object. <br />
    4. 4. Properties of the Graphics Window<br />You use the GraphicsWindow object to display a graphics window and draw colorful shapes in it. To display the graphics window on your screen, you use the Show operation.<br />Let’s see how to use different properties of the GraphicsWindow object in a program…<br />You can also define the properties of the graphics window, such as its title, height, width, and background color.<br />output<br />
    5. 5. Properties of the Graphics Window<br /><ul><li>MouseX—You can use this property to find the x-position of the mouse relative to the graphics window.
    6. 6. MouseY—You can use this property to find the y-position of the mouse relative to the graphics window.
    7. 7. PenColor—You can use this property to change the color with which shapes are drawn on the graphics window.
    8. 8. PenWidth—You can use thisproperty to change the width of the pen used to draw shapes on the graphics window.
    9. 9. BrushColor—You can use thisproperty to change the color used to fill shapes drawn on the graphics window.</li></ul>Certain properties of the GraphicsWindow object help you enhance the shapes your create. Some of these properties are:<br />
    10. 10. Operations on the Graphics Window<br />Some of the operations available for the GraphicsWindow object are:<br /><ul><li>DrawRectangle
    11. 11. DrawEllipse
    12. 12. DrawLine
    13. 13. FillRectangle
    14. 14. GetRandomColor
    15. 15. SetPixel
    16. 16. ShowMessage
    17. 17. DrawResizedImage</li></ul>You can use operations along with properties to create colorful shapes in your program.<br />
    18. 18. Exploring the Graphics Window<br />Let’s explore the different properties and operations of the GraphicsWindow object by writing a program to create shapes.<br />output<br />
    19. 19. Using Colors in the Graphics Window<br />You can use a range of colors in the graphics window to create colorful shapes. Let’s take a look at a few colors supported by Small Basic.<br />You can also choose from a variety of other colors such as pink, orange, yellow, purple, brown, white, and gray.<br />
    20. 20. Exploring the Graphics Window<br />Let’s take a look at another example that explores some more properties and operations of the GraphicsWindow object.<br />The output in this example displays a graphics window with a random-colored barcode-like design, accompanied by a secondary window—a message box. <br />
    21. 21. Exploring the Graphics Window<br />Other operations used by the GraphicsWindow object include DrawImage and DrawResizedImage. Let’s look at an example…<br />The DrawResizedImage operation draws the specified image onto the screen, in the size specified. <br />The DrawImage operation draws the specified image onto the screen. <br />
    22. 22. Let’s Summarize…<br />Congratulations! Now you know how to:<br />Write statements relevant to the GraphicsWindow object.<br />Use various properties of the GraphicsWindow object.<br />Perform different operations using the GraphicsWindow object.<br />
    23. 23. It’s Time to Apply Your Learning…<br />Write a program to display a graphics window and perform the following steps to explore your creativity:<br /><ul><li>Set the height and width of the graphics window to 640 and 800 pixels, respectively.
    24. 24. Insert two differently colored shapes partially overlapping each other.
    25. 25. Draw multiple rectangles in random colors.
    26. 26. Insert a resized image at a suitable location on the screen.
    27. 27. Display a message box with the message "Have a nice day!"</li>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×