none
graphics commands in small basic RRS feed

  • Question

  • why are the graphics commands in small basic counter-intuitive?

    the x and y co-ordinates in the drawellipse operation do not refer to the center of the ellipse. you lose control over the program because you don't know where the ellipse is  going to appear.

    in the accompanying manual "introduction to small basic" there is a program illustrating subroutines on page 48. The code is as follows:

    GraphicsWindow.BackgroundColor = "Black"
    GraphicsWindow.PenColor = "LightBlue"
    GraphicsWindow.Width = 480
    For i = 0 To 6.4 Step 0.17
    x = Math.Sin(i) * 100 + 200
    y = Math.Cos(i) * 100 + 200
    DrawCircleUsingCenter()
    EndFor
    Sub DrawCircleUsingCenter
    startX = x - 40
    startY = y - 40
    GraphicsWindow.DrawEllipse(startX, startY, 120, 120)
    EndSub

    the output image is figure. 46 in the same book

    but as i examined the code and the output, the startX and startY are NOT the centers of the drawn images.

    am i missing something?

    Friday, July 2, 2010 4:32 AM

Answers

  • Gosho,

    I'm not sure why Oskariot's was marked as 'the answer', but the answer to your question is...

    startX and startY are NOT the centers of the circle, as you say. The are the top left corner of a conceptual box in which the circle is drawn.

    the real center of the circles is X and Y, which then have 40 subtracted from them to find that 'top left corner'.

    the problem with the code you gave is in the DrawEllipse line.  We are only subtracting 40 from the centre positions, but then drawing a circle with a diameter of 120, which makes X and Y look like they are not in the center.  

    To fix it, either subtract 60 (half of 120) from X and Y, or DrawEllipse(startX, startY, 80, 80)

    • Marked as answer by gosho Saturday, July 3, 2010 8:19 AM
    Friday, July 2, 2010 8:03 AM
  • In Small Basic X is left position of your shape and Y is top of your shape.


    Sorry My Bad English
    Friday, July 2, 2010 4:59 AM

All replies

  • In Small Basic X is left position of your shape and Y is top of your shape.


    Sorry My Bad English
    Friday, July 2, 2010 4:59 AM
  • Gosho,

    I'm not sure why Oskariot's was marked as 'the answer', but the answer to your question is...

    startX and startY are NOT the centers of the circle, as you say. The are the top left corner of a conceptual box in which the circle is drawn.

    the real center of the circles is X and Y, which then have 40 subtracted from them to find that 'top left corner'.

    the problem with the code you gave is in the DrawEllipse line.  We are only subtracting 40 from the centre positions, but then drawing a circle with a diameter of 120, which makes X and Y look like they are not in the center.  

    To fix it, either subtract 60 (half of 120) from X and Y, or DrawEllipse(startX, startY, 80, 80)

    • Marked as answer by gosho Saturday, July 3, 2010 8:19 AM
    Friday, July 2, 2010 8:03 AM
  • Thanks Davey-Wavey and Oskariok.

    I tried what you suggested Davey-Wavey. You're right.

    All in all Small Basic is a wonderful language. I like the overall structure:

    OBJECTS-PROPERTIES-OPERATIONS-KEYWORDS.

     

    The reason for the graphics command structure in small basic is that it is a beginner's language, If you use formal mathematical equations for geometry, beginners(like me) will face great difficulty in writing code. Isn't it simpler and also fundamental for a beginner to know 1. a circle is a type of ellipse and 2. that an ellipse is a function of diameter. All this is encapsulated in the small basic command GraphicsWindow.DrawEllipse(x,y,width,height).

    Given this fact, the language offers many other features that allow a student to overcome and ignore this quirk.

    • Edited by gosho Saturday, July 10, 2010 4:47 AM eureka
    Friday, July 2, 2010 10:57 AM