home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH7 / SRC / DISTORT.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-14  |  3.6 KB  |  131 lines

  1. VERSION 4.00
  2. Begin VB.Form DistortForm 
  3.    Caption         =   "Distort"
  4.    ClientHeight    =   2925
  5.    ClientLeft      =   2805
  6.    ClientTop       =   1395
  7.    ClientWidth     =   2910
  8.    Height          =   3615
  9.    Left            =   2745
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2925
  12.    ScaleWidth      =   2910
  13.    Top             =   765
  14.    Width           =   3030
  15.    Begin VB.PictureBox Canvas 
  16.       Height          =   2895
  17.       Left            =   0
  18.       ScaleHeight     =   2835
  19.       ScaleWidth      =   2835
  20.       TabIndex        =   0
  21.       Top             =   0
  22.       Width           =   2895
  23.    End
  24.    Begin VB.Menu mnuFile 
  25.       Caption         =   "&File"
  26.       Begin VB.Menu mnuFileExit 
  27.          Caption         =   "E&xit"
  28.       End
  29.    End
  30.    Begin VB.Menu mnuTrans 
  31.       Caption         =   "&Transformation"
  32.       Begin VB.Menu mnuTransChoice 
  33.          Caption         =   "&None"
  34.          Checked         =   -1  'True
  35.          Index           =   0
  36.          Shortcut        =   ^N
  37.       End
  38.       Begin VB.Menu mnuTransChoice 
  39.          Caption         =   "&Sines"
  40.          Index           =   1
  41.          Shortcut        =   ^S
  42.       End
  43.       Begin VB.Menu mnuTransChoice 
  44.          Caption         =   "&Twist"
  45.          Index           =   2
  46.          Shortcut        =   ^T
  47.       End
  48.       Begin VB.Menu mnuTransChoice 
  49.          Caption         =   "&Circle"
  50.          Index           =   3
  51.          Shortcut        =   ^C
  52.       End
  53.    End
  54. Attribute VB_Name = "DistortForm"
  55. Attribute VB_Creatable = False
  56. Attribute VB_Exposed = False
  57. Option Explicit
  58. Dim ThePicture As ObjPicture
  59. Dim Filename As String
  60. Dim xmid As Single
  61. Dim ymid As Single
  62. Dim wid As Single
  63. Private Sub canvas_Paint()
  64.     If Not ThePicture Is Nothing Then _
  65.         ThePicture.Draw canvas
  66. End Sub
  67. Private Sub Form_Load()
  68.     LoadLines
  69. End Sub
  70. Private Sub mnuFileExit_Click()
  71.     Unload Me
  72. End Sub
  73. Sub LoadLines()
  74. Const gap = 250
  75. Dim poly As ObjPolygon
  76. Dim i As Integer
  77. Dim j As Integer
  78.     Set ThePicture = New ObjPicture
  79.     For i = 1 To 10
  80.         ' Horizontal line.
  81.         Set poly = New ObjPolygon
  82.         ThePicture.Objects.Add poly
  83.         poly.NumPoints = 10
  84.         For j = 1 To 10
  85.             poly.SetPoint j, j * gap, i * gap
  86.         Next j
  87.         
  88.         ' Vertical line.
  89.         Set poly = New ObjPolygon
  90.         ThePicture.Objects.Add poly
  91.         poly.NumPoints = 10
  92.         For j = 1 To 10
  93.             poly.SetPoint j, i * gap, j * gap
  94.         Next j
  95.     Next i
  96.     xmid = 5.5 * gap
  97.     ymid = xmid
  98.     wid = 5 * gap
  99. End Sub
  100. Private Sub mnuTransChoice_Click(Index As Integer)
  101. Dim trans As Object
  102. Dim i As Integer
  103.     ' Check the selected transformation.
  104.     For i = 0 To 3
  105.         mnuTransChoice(i).Checked = False
  106.     Next i
  107.     mnuTransChoice(Index).Checked = True
  108.     ' Reload the data.
  109.     LoadLines
  110.     ' Load the correct transformation.
  111.     Select Case Index
  112.         Case 1  ' Sines.
  113.             Set trans = New DistortSines
  114.             trans.amplitude = 100
  115.             trans.period = 2500
  116.         Case 2  ' Twist.
  117.             Set trans = New DistortTwist
  118.             trans.cx = xmid
  119.             trans.cy = ymid
  120.         Case 3  ' Circle.
  121.             Set trans = New DistortCircle
  122.             trans.cx = xmid
  123.             trans.cy = ymid
  124.             trans.radius = wid * 2
  125.     End Select
  126.     ' If the transformation is not none, apply it.
  127.     If Index > 0 Then ThePicture.Distort trans
  128.     ' Redraw the picture.
  129.     canvas.Refresh
  130. End Sub
  131.