Example of using Word VBA graphics drawing library

Ilustration of a function

The following example is a modification of the program for Gnuplot on p. 136, " Practical Fortran 95 programming" by Tanabe & Hirayama.

Sub Draw_Function()
  
  Const PI = 3.14159265358979
  Const W = 2.5
  Dim t, R, x1, y1, x2, y2
  Dim i As Integer

  InitializeGraphics
  SetViewPort 85, 99, 510, 372     ' use the top half area of portrait A4 size paper
  SetGraphicsWindow -W, W, W, -W
  DrawAxis W, W

  gLineColor = vbBlue
  x1 = 1.7
  y1 = 0#
  Move x1, y1
  
  For i = 1 To 100
    t = 2# * PI / 100 * i
    R = 1.5 * Cos(3# * t) + 0.2
    x2 = R * Cos(t)
    y2 = R * Sin(t)
    DrawLine x1, y1, x2, y2
    x1 = x2
    y1 = y2
  Next i
  
  gLineColor = vbGreen
  x1 = -2#
  y1 = -2#
  Move x1, y1
  
  For i = 1 To 100
    x2 = -2# + 4# / 100# * i
    y2 = x2 ^ 3 - 3 * x2
    DrawLine x1, y1, x2, y2
    x1 = x2
    y1 = y2
  Next i

End Sub

Sub DrawAxis(x_max, y_max)

  DrawLine -x_max, 0, x_max, 0
  DrawLine 0, y_max, 0, -y_max

End Sub

Ilustration of a function

Download source program