home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH6 / SRC / SPIRAL.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-28  |  3.7 KB  |  130 lines

  1. VERSION 4.00
  2. Begin VB.Form SpiralForm 
  3.    Caption         =   "Spiral"
  4.    ClientHeight    =   5310
  5.    ClientLeft      =   2115
  6.    ClientTop       =   1095
  7.    ClientWidth     =   4830
  8.    Height          =   6000
  9.    Left            =   2055
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   354
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   322
  14.    Top             =   465
  15.    Width           =   4950
  16.    Begin VB.TextBox DtText 
  17.       Height          =   285
  18.       Left            =   2160
  19.       TabIndex        =   6
  20.       Text            =   "0.1"
  21.       Top             =   45
  22.       Width           =   615
  23.    End
  24.    Begin VB.TextBox TminText 
  25.       Height          =   285
  26.       Left            =   0
  27.       TabIndex        =   4
  28.       Text            =   "0"
  29.       Top             =   45
  30.       Width           =   615
  31.    End
  32.    Begin VB.CommandButton CmdGo 
  33.       Caption         =   "Go"
  34.       Default         =   -1  'True
  35.       Height          =   375
  36.       Left            =   4200
  37.       TabIndex        =   3
  38.       Top             =   0
  39.       Width           =   615
  40.    End
  41.    Begin VB.TextBox TmaxText 
  42.       Height          =   285
  43.       Left            =   1200
  44.       TabIndex        =   2
  45.       Text            =   "18.85"
  46.       Top             =   45
  47.       Width           =   615
  48.    End
  49.    Begin VB.PictureBox Canvas 
  50.       AutoRedraw      =   -1  'True
  51.       Height          =   4815
  52.       Left            =   0
  53.       ScaleHeight     =   -2.2
  54.       ScaleLeft       =   -1.1
  55.       ScaleMode       =   0  'User
  56.       ScaleTop        =   1.1
  57.       ScaleWidth      =   2.2
  58.       TabIndex        =   0
  59.       Top             =   480
  60.       Width           =   4815
  61.    End
  62.    Begin VB.Label Label1 
  63.       Caption         =   "dt"
  64.       Height          =   255
  65.       Index           =   1
  66.       Left            =   1920
  67.       TabIndex        =   5
  68.       Top             =   60
  69.       Width           =   255
  70.    End
  71.    Begin VB.Label Label1 
  72.       Caption         =   "<= t <="
  73.       Height          =   255
  74.       Index           =   0
  75.       Left            =   645
  76.       TabIndex        =   1
  77.       Top             =   60
  78.       Width           =   495
  79.    End
  80.    Begin VB.Menu mnuFile 
  81.       Caption         =   "&File"
  82.       Begin VB.Menu mnuFileExit 
  83.          Caption         =   "E&xit"
  84.       End
  85.    End
  86. Attribute VB_Name = "SpiralForm"
  87. Attribute VB_Creatable = False
  88. Attribute VB_Exposed = False
  89. Option Explicit
  90. Const PI = 3.14159
  91. ' ************************************************
  92. ' Draw the curve on the indicated picture box.
  93. ' ************************************************
  94. Sub DrawCurve(pic As PictureBox, start_t As Single, stop_t As Single, dt As Single)
  95. Dim t As Single
  96.     pic.Cls
  97.     pic.CurrentX = X(start_t)
  98.     pic.CurrentY = Y(start_t)
  99.     t = start_t + dt
  100.     Do While t < stop_t
  101.         pic.Line -(X(t), Y(t))
  102.         t = t + dt
  103.     Loop
  104.     pic.Line -(X(stop_t), Y(stop_t))
  105. End Sub
  106. ' ************************************************
  107. ' The parametric function Y(t).
  108. ' ************************************************
  109. Function Y(t As Single) As Single
  110.     Y = t * t / 350 * Sin(t)
  111. End Function
  112. ' ************************************************
  113. ' The parametric function X(t).
  114. ' ************************************************
  115. Function X(t As Single) As Single
  116.     X = t * t / 350 * Cos(t)
  117. End Function
  118. Private Sub CmdGo_Click()
  119. Dim tmin As Single
  120. Dim tmax As Single
  121. Dim dt As Single
  122.     tmin = CSng(TminText.Text)
  123.     tmax = CSng(TmaxText.Text)
  124.     dt = CSng(DtText.Text)
  125.     DrawCurve Canvas, tmin, tmax, dt
  126. End Sub
  127. Private Sub mnuFileExit_Click()
  128.     Unload Me
  129. End Sub
  130.