March 19, 2012

Finding a square root of a number

Normally, you may had come across situations in which you may have to find square roots of some 10 digit numbers.The syntax of finding a square root -
                                                    SQR ( N )
where,
         N = the number of which you need to find the square root.

Example-
1)  Finding square root of 25
      CLS
      PRINT SQR (25)
      END

  Rejoice !!!
  You can also find square roots of non-square numbers upto four decimal digits.

March 07, 2012

Drawing a circle

Let's learn how to draw a circle and arcs-
              First of all, don't forget to type " Screen 9" because normally Q basic is in default screen 1 in which figures cannot be drawn.

The syntax for drawing a circle or an arc-
                     CIRCLE ( X, Y ) , R , C , SA , EA
where,
         ( X , Y ) =  the coordinate of the center of the circle.
         R           =  the radius of the circle
         C           =  the colour code which is optional
         SA         =  the starting angle if you want to draw an arc
         EA         = the ending angle of the arc

Examples-
1. Drawing a circle-
                         CLS
                        SCREEN  9
                        CIRCLE  ( 60 , 60 ), 20 , 9
                        END
This draws a circle with radius 20 pixels at the pixel pointed (60,60)  in blue.

               Don't just draw circles, try concentric circles, intersecting circles and complex figures and pictures using circle and line commands.

Drawing a Line

Today, let's learn to draw a line -

        Before all , remember that you have to type "SCREEN 9" in the type area of Q basic.
The syntax of the command to draw a line-
                 LINE  ( X1 , Y1 ) - ( X2 , Y2 ), C , ( B , (F))
Where,
      ( X1 , Y1 ) = the coordinate of the starting point of line
      ( X2 , Y2 ) = the coordinate of the ending point of line
       C = the color code
       B and BF = used to draw an empty or filled rectangle respectively in which ( X1 , Y1)-( X2, Y2) specify diagonally opposite corners.

   X1, X2 represent the column number
   Y1, Y2 represent the row number.

Examples-
     1.  Drawing a line-
                   CLS
                   SCREEN 9
                   LINE (10,10)-(100,100), 9
                   END
            This draws a line from the pixel pointed 10,10 to the pixel pointed 100,100 in blue.  

               Don't just draw a line and feel happy seeing it.
               Try complex figures and matrixes.