Aplikasi kali ini saya akan menampilkan Graphic Sinus, Cosinus dan Tangen pada PictureBox. Nilai Amplitudo & Frekuesi Graphic dapat di atur dan Graphic tersebut dapat ditampilkan satu persatu atau sekaligus. Hasil tampilannya perhatikan Gambar di atas.
ToolBox yang saya pergunakan, perhatikan tabel di bawah ini.
1 UserForm | Name: UserForm1 Text: Graph Sin, Cos, Tan V. Hutabalian's Blog |
1 PictureBox | Name: PictureBox1 |
2 Label | Name:Label1 & 2 Text Label1: Amplitudo Text Label2: Frekuensi |
3 RadioButton | Name1:Sinus Name2:Cosinus Name3:Tangent Text Sinus: Sinus Graph Text Cosinus: Cosinus Graph Text Tangent: Tangen Graph |
2 Button | Name:Button1& 2 |
2 ComboBox | Name:ComboBox1& 2 |
Desain Form table Toolbox di atas perhatikan gambar di bawah ini:
Setelah selesai mendesain Form dengan mengatur semua object propertis Toolbox. Ketikkan source program di bawah ini dengan mengarahkan kursor pada design Form, Klik kanan lalu pilih View Code.
Script Graph Sin, Cos, Tan with VB 2008 Express Edition:
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
'Graph Sin, Cos, Tan V. Hutabalian's Blog'
'======================================================================='
' '
' Berbagi ilmu Sensasi Kepuasan Tersendiri '
' Programing By: Verynandus Hutabalian'
' Publish to V. Hutabalian's Blog 11 Agustus 2010 '
' Copyright © ==>>> Verynandus Hutabalian '
'+++++++++++++++++++++++========================++++++++++++++++++++++++'
Public Class Form1
Dim dat As Integer
Public x As Double
Public y As Double
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ix As Integer = PictureBox1.Width
Dim iy As Integer = PictureBox1.Height
Dim Values(ix) As Double
Dim OldPoint = New Point(0, PictureBox1.Height \ 2)
If Sinus.Checked = True Then
For Me.x = 0 To Values.GetUpperBound(0)
y = iy \ 2 + ComboBox1.Text * 15 * Math.Sin(2 * 3.14159 * ComboBox2.Text * x / 3.5)
Dim NewPoint = New Point(x, y)
PictureBox1.CreateGraphics.DrawLine(Pens.Yellow, OldPoint, NewPoint)
OldPoint = NewPoint
Next x
Else
If Cosinus.Checked Then
For Me.x = 0 To Values.GetUpperBound(0)
y = iy \ 2 + ComboBox1.Text * 15 * Math.Cos(2 * 3.14159 * ComboBox2.Text * x / 3.5)
Dim NewPoint = New Point(x, y)
PictureBox1.CreateGraphics.DrawLine(Pens.Yellow, OldPoint, NewPoint)
OldPoint = NewPoint
Next x
Else
If Tangent.Checked Then
For Me.x = 0 To Values.GetUpperBound(0)
y = iy \ 2 + ComboBox1.Text * 15 * Math.Tan(2 * 3.14159 * ComboBox2.Text * x / 3.5)
Dim NewPoint = New Point(x, y)
PictureBox1.CreateGraphics.DrawLine(Pens.Yellow, OldPoint, NewPoint)
OldPoint = NewPoint
Next
End If
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ComboBox1.Text = 1
ComboBox2.Text = 0.1
Dim dat1 As Double
For i As Integer = 1 To 10 Step 1
dat = i
ComboBox1.Items.Add(dat)
ComboBox1.Refresh()
Next
For k As Double = 0.1 To 1 Step 0.1
dat1 = k
ComboBox2.Items.Add(dat1)
ComboBox2.Refresh()
Next
PictureBox1.BackColor = Color.Black
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim L_Skala As Double = PictureBox1.Width
Dim T_Skala As Double = PictureBox1.Height
Dim V_Grid As Double = 40
Dim V_Grid1 As Double = L_Skala / V_Grid
Dim H_Grid As Double = 8
Dim H_Grid1 As Double = L_Skala / H_Grid
Dim Label_T = 50
Dim Lbl_Grid As Double = L_Skala / Label_T
Dim Label_T1 = 40
Dim Lbl_Grid1 As Double = L_Skala / Label_T
Dim TickSP As New Point(PictureBox1.Width - 5, PictureBox1.Height - 175)
Dim TickEP As New Point(PictureBox1.Width - 5, PictureBox1.Height - 65)
Dim TickSP1 As New Point(PictureBox1.Width - 5, PictureBox1.Height - 17)
Dim TickEP1 As New Point(PictureBox1.Width - 5, PictureBox1.Height - 65)
Dim TextStartX As Integer = CInt(PictureBox1.Width - L_Skala + 357)
Dim TextBrsh As Brush = New SolidBrush(Color.GreenYellow)
Dim TextStartX1 As Integer = CInt(PictureBox1.Width - L_Skala - 5)
For k As Single = 1 To 10 Step 1
e.Graphics.DrawString(CStr(k), New Font("Verdana", 8, FontStyle.Regular), Brushes.Red, 340, TickSP.Y)
TickSP.Y -= Lbl_Grid
TickEP.Y -= Lbl_Grid
Next
For j As Single = -10 To -1 Step 1
e.Graphics.DrawString(CStr(j), New Font("Verdana", 8, FontStyle.Regular), Brushes.Red, 335, TickSP1.Y)
TickSP1.Y -= Lbl_Grid1
TickEP1.Y -= Lbl_Grid1
Next
For i As Integer = 1 To 20 Step 1
e.Graphics.DrawString(CStr(i), New Font("Verdana", 8, FontStyle.Regular), TextBrsh, TextStartX, CInt(PictureBox1.Height - 155))
TextStartX += V_Grid1
Next
For i As Integer = -20 To -1 Step 1
e.Graphics.DrawString(CStr(i), New Font("Verdana", 8, FontStyle.Regular), TextBrsh, TextStartX1, CInt(PictureBox1.Height - 155))
TextStartX1 += V_Grid1
Next
e.Graphics.DrawString("V. Hutabalian's Blog Graphic Sin, Cos, Tan", New Font("Verdana", 10, FontStyle.Regular), Brushes.Silver, 5, 5)
End Sub
End Class
Setelah Anda mengetikkan listing source program diatas tekan F5, maka hasil tampilan visualnya seperti gambar di bawah ini.
Kemudian pilih Graph mana yang ingin ditampilkan dengan menentukan Amplitudo dan Frekuensi.
Graph Sinus:
Graph Cosinus:
Graph Tangen:
Graph Sinus, Cosinus, Tangen:
Pengembangan lebih lanjut, Butuh kreatifitas Anda untuk mengoprek dan mengotak-atik sampai menemukan yang Anda inginkan.
Selamat mencoba Guys! Nantikan Tips Aplikasi Cantik Lainnya by Verynandus Hutabalian.
2 komentar:
Ito,rajin amat sih nulis yang beginiannn...apa nih aku sudah tak mengerti Ito....apalah gunanya kuliah 6 tahun sedang ilmunya menguap semuaaaa..huwaaaa(nangis dulu yah..) huuuuuuhh.............
Aku juga sedihhhh neh.... semangat & Ilmuku juga tinggal menunggu waktu untuk menguap........
Paling ga aku sedikit berbagi, semoga dapat membantu...... beberapa pembaca Blog sederhana ini..... Thanks atas kunjungannya Ito........ Keep your spirit..
V. Hutabalian
Posting Komentar