home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / graphics / autoredo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-05-16  |  2.4 KB  |  77 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "AutoRedraw Demo"
  6.    ClientHeight    =   2880
  7.    ClientLeft      =   1185
  8.    ClientTop       =   1800
  9.    ClientWidth     =   3960
  10.    ClipControls    =   0   'False
  11.    Height          =   3285
  12.    Left            =   1125
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   192
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   264
  18.    Top             =   1455
  19.    Width           =   4080
  20. Option Explicit
  21. Const PIXEL = 3
  22. Dim PI As Double
  23. Dim DegreesPerRadian As Double
  24. Dim RadiansPerDegree As Double
  25. 'This next constant should generally be a power of 2.
  26. Const SECTORCOUNT = 8
  27. Sub Form_Activate ()
  28.     Const DELTA = 400
  29.     Const RADIUS = 1
  30.     Dim i As Integer
  31.     Dim theta As Double
  32.     Dim x1 As Single, y1 As Single
  33.     form1.Height = form1.Width + DELTA
  34.     form1.ScaleMode = PIXEL
  35.     'Scale requires the coordinates of the upper left and lower right.
  36.     Scale (-1, 1)-(1, -1)
  37.     'To make the circle and the lines persistant,
  38.     'set AutoRedraw to True before drawing them.
  39.     form1.AutoRedraw = True
  40.     'Draw a unit circle.
  41.     Circle (0, 0), RADIUS
  42.     'Draw the lines as needed.
  43.     For i = 1 To SECTORCOUNT
  44.     y1 = Sin(theta)
  45.     x1 = Cos(theta)
  46.     Line (x1, y1)-(0, 0)
  47.     theta = theta + PI / (SECTORCOUNT / 2)
  48.     Next i
  49.     form1.AutoRedraw = False
  50. End Sub
  51. Sub Form_Load ()
  52.     'Let the computer determine a value for PI.
  53.     PI = 4# * Atn(1)
  54.     DegreesPerRadian = 180# / PI
  55.     RadiansPerDegree = PI / 180#
  56. End Sub
  57. Sub Form_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
  58.     Dim sector As Integer
  59.     Dim radians As Double
  60.     Dim degrees As Double
  61.     Dim hypotenuse As Double
  62.     'Only allow clicking inside the circle.
  63.     hypotenuse = Sqr(x * x + y * y)
  64.     If hypotenuse > 1# Then
  65.     Exit Sub
  66.     End If
  67.     radians = Atn(y / x)
  68.     degrees = radians * DegreesPerRadian
  69.     If x < 0# Then
  70.     degrees = 180# + degrees              '2nd & 3rd quadrant
  71.     ElseIf y < 0# Then
  72.         degrees = 360# + degrees          '4th quadrant
  73.     End If
  74.     sector = Int(degrees / (360# / SECTORCOUNT)) + 1
  75.     MsgBox "You clicked in sector #" + Str$(sector) + "."
  76. End Sub
  77.