Sunday, November 25, 2018

SINE WAVE IN VISUAL FORTRAN



Before directly jumping into the coding, let's have some background knowledge of some of the terms used in Visual fortran Graphics. This code was written in INTEL VISUAL FORTRAN, which runs in Microsoft's Visual Studio. You can also use Comapq, Digital Fortran. No matter what IDE you use, the code remains the same.

Library used

You need to include library named dflib using the key word "Use" in the beginning of the code. This library includes how moveto(), lineto(), SETVIEWORG(), SETCOLORRGB(), etc.

dflib = Digital fortran library

Type(xycoord)

Type (xycoord) xy: It represents the physical coordinate of viewport.

Viewport

Viewport: Area of the screen where drawing, graphics appears.


SETVIEWORG

SETVIEWORG: Sets origin of viewport to new location on screen

Moveto ()

Moveto(2,3, xy): Moves current graphic position to a specific point (2,3) of the screen w.r.t. the current origin.
No drawing occurs with this code.
It’s like moving your pen/pencil to a specific position on the screen to determine the initial position to draw any graphics/ write text, etc.

Lineto ()

Lineto(10,20):  This commands draw line.
Line has two ends.
The coordinate of initial end of line is determined from moveto(), which is (2,3) in this case.
The coordinate of final end of line is determined from lineto(), which is (10,20) in this case.

For example:

Code:
MOVETO(2,3,XY)
LINETO(10,20)

Output:

             
    
                                                   
Here, moveto(2,3) moves drawing cursor to (2,3) and lineto(10,20) draws the green line from (2,3) to (10,20).

Code:
MOVETO(2,3,xy)
LINETO(10,20)
LINETO(10,50)
LINETO(20,50)

Output:
                     
                                                             
                                                                
Here, moveto(2,3,xy) brings drawing pen (drawing cursor) to (2,3) and lineto(10,20) draw the green line. Then lineto(10,50) draws line from (10,20) to (10,50) because current cursor position was at (10,20). Now current cursor position is at (10,50). So lineto(20,50) draws orange line from (10,50) to (20,50).


Now, I hope you understood above mentioned terms, which will be used in the following code. You need to include this code in the STANDARD GRAPHICS OF QWIN in VISUAL FORTRAN. For detail refer here.


Drawing sine wave

 Program SineWave
    ! Library to be used for graphics
    use dflib
    ! Declaring variables
     Integer status, x, y
     Integer result,rst,i
    real rad
     TYPE (xycoord) xy
    
    ! Program Body
   
    call SETVIEWORG(200,400,xy) !sets new origin to (200,400)
   
     Call moveto (0,0, xy)   !move to new origin
    result = SETCOLORRGB(#FF288D) !pink color for axes
    status = lineto(999,0)  ! horzontal axis
   
    call moveto(0,100,xy)     !again move to origin
    status = lineto(0,-100)  !draw vertical axis
   
    call moveto(0,100,xy)    
    result = SETCOLORRGB(#0000FF) !bright red
    status = lineto(999,100)    !draws horizontal line at negative amplitude of sine wave
   
    call moveto(0,-100,xy)
    status = lineto(999,-100)   !draws line to positive amplitude of sine wave
   
    call moveto(0,0,xy) !move to origin
   
    ! Draws Sine Wave
    do 100 i = 0,999,3 ! i is angle in degree
        result = SETCOLORRGB(#85f000)   !green color
        rad = -100*sin(3.14*i/180) ! i degree = pi* i/180 = 3.14 * i/180
        status = lineto(i,rad)  ! Draws sine curve in each loop
       
100 continue       
End 


Output:




No comments:

Post a Comment

MOST RECENT

BITUMEN, ASPHALT, COAL TAR, CUTBACK BITUMEN

Ever wondered what is Bitumen? What is Asphalt? What is difference between these two? What is MC 30 Bitumen? What is cutback bitumen? We wil...