Imports System.Drawing.Printing
Imports System.IO
Public Class Form2
Inherits System.Windows.Forms.Form
Dim int_X0, int_Y0, int_i As Integer
Dim single_Xa, single_Xe, single_Ya, single_Ye As Integer
Dim x_Array(), y_Array(), Xa, Xe, Ya, Ye As Single
Dim int_color As System.Drawing.Pen
Private Sub Drawing_load(ByVal sender As Object,ByValAsSystem.EventArgs) Handles Me.Load
XA = Val(Form1.TextBox1.Text)
Xe = Val(Form1.TextBox2.Text)
Ya = Val(Form1.TextBox3.Text)
Ye = Val(Form1.TextBox4.Text)
If Form1.ComboBox1.Text = "Sinus" Then
main()
ElseIf Form1.ComboBox1.Text = "Tan" Then
main1()
End If
'PictureBox1.Image = bmp
End Sub
Sub main()
ReDim x_Array(628), y_Array(628)
For int_i = 0 To UBound(x_Array) Step 1
x_Array(int_i) = int_i / 100 - 5
Next
Sinus(x_Array)
'Tan(x_Array)
Plot(x_Array, y_Array, Pens.Gold, Xa, Xe, Ya, Ye)
End Sub
Sub main1()
ReDim x_Array(628), y_Array(628)
For int_i = 0 To UBound(x_Array) Step 1
x_Array(int_i) = int_i / 100 - 5
Next
Tan(x_Array)
Plot(x_Array, y_Array, Pens.Gold, Xa, Xe, Ya, Ye)
End Sub
Function Tan(ByVal x_Array)
For int_i = 0 To UBound(x_Array) Step 1
y_Array(int_i) = Math.Tan(x_Array(int_i))
Next
Return y_Array
End Function
Function Sinus(ByVal x_Array)
For int_i = 0 To UBound(x_Array) Step 1
y_Array(int_i) = Math.Sin(x_Array(int_i))
Next
Return y_Array
End Function
Function Plot(ByVal x_Array, ByVal y_Array, ByVal int_color, ByVal single_Xa, ByVal single_Xe, ByVal single_Ya, ByVal single_Ye)
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim g As System.Drawing.Graphics = Graphics.FromImage(bmp)
int_X0 = 50
int_Y0 = 600
g.TranslateTransform(int_X0, int_Y0)
Dim P1 As New System.Drawing.Point(0, 0)
Dim P2 As New System.Drawing.Point(600, 0)
Dim P3 As New System.Drawing.Point(0, -600)
g.DrawLine(New Pen(Color.Black, 2), P1, P2)
g.DrawLine(New Pen(Color.Black, 2), P1, P3)
Dim z1 As Single = 600 \ (single_Xe - single_Xa)
For int_i = 0 To 600 Step z1
g.DrawLine(New Pen(Color.AliceBlue, 1), int_i + z1, 0, int_i + z1, -600)
g.DrawLine(New Pen(Color.Black, 2), int_i, 0, int_i, -10)
g.DrawLine(New Pen(Color.Black, 1), int_i + z1 \ 2, 0, int_i + z1 \ 2, -5)
g.DrawString(int_i \ z1 + single_Xa, New Font("Arial", 10), Brushes.Black, int_i - 5, 0)
Next
Dim z2 As Single = 600 \ (single_Ye - single_Ya)
For int_i = 0 To -600 Step -z2
g.DrawLine(New Pen(Color.AliceBlue, 1), 0, int_i - z2, 600, int_i - z2)
g.DrawLine(New Pen(Color.Black, 2), 0, int_i, 10, int_i)
g.DrawLine(New Pen(Color.Black, 1), 0, int_i - z2 \ 2, 5, int_i - z2 \ 2)
g.DrawString(-(int_i \ z2 - single_Ya), New Font("Arial", 10), Brushes.Black, -20, int_i - 7)
Next
If single_Xa > x_Array(0) Then
For int_i = 0 To UBound(x_Array) - 1 Step 1
If x_Array(int_i) > single_Xa Then
If y_Array(int_i) > -single_Ye Then
If y_Array(int_i) < single_Ye Then
g.DrawLine(int_color, x_Array(int_i) * z1 - z1 * single_Xa, -y_Array(int_i) * z2 + z2 * single_Ya, x_Array(int_i + 1) * z1 - z1 * single_Xa, -y_Array(int_i + 1) * z2 + z2 * single_Ya)
End If
End If
End If
Next
Else
For int_i = 0 To UBound(x_Array) - 1 Step 1
If y_Array(int_i) > -single_Ye Then
If y_Array(int_i) < single_Ye Then
g.DrawLine(int_color, x_Array(int_i) * z1 - z1 * single_Xa, -y_Array(int_i) * z2 + z2 * single_Ya, x_Array(int_i + 1) * z1 - z1 * single_Xa, -y_Array(int_i + 1) * z2 + z2 * single_Ya)
End If
End If
Next
End If
PictureBox1.Image = bmp
Return single_Xa
End Function
End Class