home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH6 / SRC / CIRCLE2.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-01  |  4.9 KB  |  176 lines

  1. VERSION 4.00
  2. Begin VB.Form CircleForm 
  3.    Caption         =   "Circle 2"
  4.    ClientHeight    =   5670
  5.    ClientLeft      =   2115
  6.    ClientTop       =   945
  7.    ClientWidth     =   4830
  8.    Height          =   6360
  9.    Left            =   2055
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   378
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   322
  14.    Top             =   315
  15.    Width           =   4950
  16.    Begin VB.TextBox YscaleText 
  17.       Height          =   285
  18.       Left            =   2160
  19.       TabIndex        =   9
  20.       Text            =   "0.5"
  21.       Top             =   480
  22.       Width           =   615
  23.    End
  24.    Begin VB.TextBox XscaleText 
  25.       Height          =   285
  26.       Left            =   600
  27.       TabIndex        =   7
  28.       Text            =   "1.0"
  29.       Top             =   480
  30.       Width           =   615
  31.    End
  32.    Begin VB.TextBox DtText 
  33.       Height          =   285
  34.       Left            =   2160
  35.       TabIndex        =   6
  36.       Text            =   "0.1"
  37.       Top             =   45
  38.       Width           =   615
  39.    End
  40.    Begin VB.TextBox TminText 
  41.       Height          =   285
  42.       Left            =   0
  43.       TabIndex        =   4
  44.       Text            =   "0"
  45.       Top             =   45
  46.       Width           =   615
  47.    End
  48.    Begin VB.CommandButton CmdGo 
  49.       Caption         =   "Go"
  50.       Default         =   -1  'True
  51.       Height          =   375
  52.       Left            =   4200
  53.       TabIndex        =   3
  54.       Top             =   0
  55.       Width           =   615
  56.    End
  57.    Begin VB.TextBox TmaxText 
  58.       Height          =   285
  59.       Left            =   1200
  60.       TabIndex        =   2
  61.       Text            =   "6.2832"
  62.       Top             =   45
  63.       Width           =   615
  64.    End
  65.    Begin VB.PictureBox Canvas 
  66.       AutoRedraw      =   -1  'True
  67.       Height          =   4815
  68.       Left            =   0
  69.       ScaleHeight     =   -2.2
  70.       ScaleLeft       =   -1.1
  71.       ScaleMode       =   0  'User
  72.       ScaleTop        =   1.1
  73.       ScaleWidth      =   2.2
  74.       TabIndex        =   0
  75.       Top             =   840
  76.       Width           =   4815
  77.    End
  78.    Begin VB.Label Label1 
  79.       Caption         =   "Y scale"
  80.       Height          =   255
  81.       Index           =   3
  82.       Left            =   1560
  83.       TabIndex        =   10
  84.       Top             =   540
  85.       Width           =   615
  86.    End
  87.    Begin VB.Label Label1 
  88.       Caption         =   "X scale"
  89.       Height          =   255
  90.       Index           =   2
  91.       Left            =   0
  92.       TabIndex        =   8
  93.       Top             =   540
  94.       Width           =   615
  95.    End
  96.    Begin VB.Label Label1 
  97.       Caption         =   "dt"
  98.       Height          =   255
  99.       Index           =   1
  100.       Left            =   1920
  101.       TabIndex        =   5
  102.       Top             =   60
  103.       Width           =   255
  104.    End
  105.    Begin VB.Label Label1 
  106.       Caption         =   "<= t <="
  107.       Height          =   255
  108.       Index           =   0
  109.       Left            =   645
  110.       TabIndex        =   1
  111.       Top             =   60
  112.       Width           =   495
  113.    End
  114.    Begin VB.Menu mnuFile 
  115.       Caption         =   "&File"
  116.       Begin VB.Menu mnuFileExit 
  117.          Caption         =   "E&xit"
  118.       End
  119.    End
  120. Attribute VB_Name = "CircleForm"
  121. Attribute VB_Creatable = False
  122. Attribute VB_Exposed = False
  123. Option Explicit
  124. Const PI = 3.14159
  125. ' ************************************************
  126. ' Draw the curve on the indicated picture box.
  127. ' ************************************************
  128. Sub DrawCurve(pic As PictureBox, start_t As Single, stop_t As Single, dt As Single, xscale As Single, yscale As Single)
  129. Dim x1 As Single
  130. Dim y1 As Single
  131. Dim t As Single
  132.     x1 = xscale * X(start_t)
  133.     y1 = yscale * Y(start_t)
  134.     pic.Cls
  135.     pic.CurrentX = x1
  136.     pic.CurrentY = y1
  137.     t = start_t + dt
  138.     Do While t < stop_t
  139.         x1 = xscale * X(t)
  140.         y1 = yscale * Y(t)
  141.         pic.Line -(x1, y1)
  142.         t = t + dt
  143.     Loop
  144.     x1 = xscale * X(stop_t)
  145.     y1 = yscale * Y(stop_t)
  146.     pic.Line -(x1, y1)
  147. End Sub
  148. ' ************************************************
  149. ' The parametric function Y(t).
  150. ' ************************************************
  151. Function Y(t As Single) As Single
  152.     Y = Sin(t)
  153. End Function
  154. ' ************************************************
  155. ' The parametric function X(t).
  156. ' ************************************************
  157. Function X(t As Single) As Single
  158.     X = Cos(t)
  159. End Function
  160. Private Sub CmdGo_Click()
  161. Dim tmin As Single
  162. Dim tmax As Single
  163. Dim dt As Single
  164. Dim xscale As Single
  165. Dim yscale As Single
  166.     tmin = CSng(TminText.Text)
  167.     tmax = CSng(TmaxText.Text)
  168.     dt = CSng(DtText.Text)
  169.     xscale = CSng(XscaleText.Text)
  170.     yscale = CSng(YscaleText.Text)
  171.     DrawCurve Canvas, tmin, tmax, dt, xscale, yscale
  172. End Sub
  173. Private Sub mnuFileExit_Click()
  174.     Unload Me
  175. End Sub
  176.