VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H00643200&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   9390
   ClientLeft      =   5205
   ClientTop       =   3015
   ClientWidth     =   10650
   ForeColor       =   &H8000000E&
   LinkTopic       =   "Form1"
   ScaleHeight     =   626
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   710
   ShowInTaskbar   =   0   'False
   WindowState     =   2  'Maximized
   Begin VB.CommandButton Command3 
      Caption         =   "e"
      Height          =   375
      Left            =   2040
      TabIndex        =   2
      Top             =   240
      Width           =   495
   End
   Begin VB.CommandButton Command2 
      Caption         =   "clear"
      Height          =   375
      Left            =   1080
      TabIndex        =   1
      Top             =   240
      Width           =   855
   End
   Begin VB.Timer tmGraph 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   2640
      Top             =   240
   End
   Begin VB.CommandButton Command1 
      Caption         =   "graph"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'==================================================================================='
'Code by Jeremy Miller, modified 9/27/03
'==================================================================================='


'this basically works by defining two sets of points and then drawing a line between them
'if the code looks a little shoddy it's cause i wrote it a while ago when i wasn't that good
'and have only recently come back to it

Dim baseStep As Double 'the amount the angle(in rads) is increased per loop, defined in form_load
Dim CurStep As Long 'the current increment number of the basestep
Dim x1 As Double
Dim x2 As Double
Dim y1 As Double
Dim y2 As Double
Private Const ScreenCenterX = 640  'use these to put the graph in the center of the screen
Private Const ScreenCenterY = 512
Private Const Done As Long = 22000 'how many increments to do, varies upon how big you want the graph
Dim LastColor As Integer

Private Sub graph()
Do
'change the color of the graph based on current step
DecideColor CurStep
'get the coordinates, angle = basestep * curstep
'note that these points will always be the same as the x2 y2 points from the previous operation
'so that each point will be connected with the point behind it, not just the next one
x1 = detX(detRad(baseStep * CurStep))
y1 = detY(detRad(baseStep * CurStep))
'increment angle
CurStep = CurStep + 1
'get points from the next step
x2 = detX(detRad(baseStep * CurStep))
y2 = detY(detRad(baseStep * CurStep))
'draw line from previous step to new step
Line (x1, y1)-(x2, y2)
DoEvents
Loop Until CurStep >= Done
CurStep = 0
End Sub


'next two functions define the polar coords
Private Function detX(radius As Double) As Double
detX = radius * Math.Cos(baseStep * CurStep) + ScreenCenterX
End Function

Private Function detY(radius As Double) As Double
detY = radius * Math.Sin(baseStep * CurStep) + ScreenCenterY
End Function

'this function determines the radius, this is the function you modify
'to make all the hella sweet graphs
Private Function detRad(Angle As Double) As Double
'detRad = Angle * (Math.Cos(3 * Angle) ^ 2 + Math.Sin(2 * Angle) ^ 2) 'graph2
detRad = Angle * (Math.Abs(Math.Cos(3 * Angle) ^ 3) - Math.Sin(Angle) ^ 2) 'graph4
End Function

Private Sub Command1_Click()
graph
End Sub

Private Sub Command2_Click()
Form1.Cls
x2 = Empty
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
'basestep here is defined as pi/160, so that means it takes 320 steps to complete a full circle
'the number of steps really isn't important with most graphs, because the cool ones all
'have an infinite period because the radius is multiplied by the angle
'but if you wanted to draw a function with a period that was say, 2pi, you would use 320 steps, as long as it's defined as pi/160 basestep
'the problem could be solved by saying angle = angle + pi/160, instead of the curStep thing, but like i said i wrote this a while ago
baseStep = 3.14159265359 / 160 'the lower the number, the smoother the graph
CurStep = 1
LastColor = -1
End Sub

Private Sub tmGraph_Timer()
graph
End Sub

Private Sub DecideColor(CurStep As Long)
    'this is the function that makes the graphs look really really cool
    'it uses the percentage done of the graph (curstep/totalsteps) and multiplies that percentage
    'by 255 to obtain an rgb value, here i have it reversed so white comes when the percent is 0
    'you can modify this to make the graphs fade through different colors too
    Dim PercentDone As Double
    Dim Color As Double
    PercentDone = CurStep / Done
    Color = PercentDone * 255
    'reverse colors
    Color = 255 - Color
    'dont make call unless color is different
    If Not (Color = LastColor) Then
        'Form1.ForeColor = RGB(Color, Color / 2, Color / 3) 'halloween colors
        'use a grey scale, (r g and b the same)
        Form1.ForeColor = RGB(Color, Color, Color)
        LastColor = Color
    End If
End Sub
