Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
LAPORAN PRAKTIKUM BAHASA PEMOGRAMAN VISUAL Kelompok 3 Puguh Sasmito 150533604893 Wenda Aditama 150533604429 Yudha Adhenda J. A 150533605242 S1 PTI D 2015 UNIVERSITAS NEGERI MALANG FAKULTAS TEKNIK ELEKTRO PROGRAM STUDI PENDIDIKAN TEKNIK INFORMATIKA APRIL 2017 LABORATORIUM KOMPUTER Jurusan Teknik Elektro – Fakultas Teknik Universitas Negeri Malang Jl.Surabaya G4 Lantai 2,Malang, Jawa Timur GRAPHIC Nama Kelompok 3 1. Puguh Sasmito 2. Wenda Aditama 3. Yudha Adhenda J. A Nim 1. 150533604893 2. 150533604429 3. 150533605242 Prodi S1 Pendidikan Teknik Informatika 2015 Off D Dosen Pembimbing Azhar Ahmad Smaragdina, M.Pd. GRAPHIC A. TUJUAN 1. Mahasiswa dapat memahami mengenai prmrograman graphic 2. Mahasiswa mampu membuat graphic sederhana menggunakan VB 3. Mahasiswa mampu membuat graphic menggunakan GDI (Graphic Device Interface) B. DASAR TEORI Seluruh form yang ada pada VB mempunyai sebuah koordinat. Koordinat ini berguna untuk menentukan posisi gambar atau graphic pada form, apakah dikiri, tengah, atas, dan sebagainya. Koordinat sebuah form terdiri atas dua bagian yaitu koordinat horizontal (x) dan koordinat vertikal (y). Gambar 1 Contoh koordinat graphic Posisi koordinat dari komponen picturebox dapat dengan mudah diatur secara manual pada properties location picturebox sesuai gambar berikut: Gambar 2 Properties Koordinat CLR menggunakan implementasi tingkat lanjutdari antarmuka grafik windows (GDI) yang disebut dengan GDI+. GDI+ mengijinkan kita untuk membuat grafik menggambar teks, atau memanipulasi image grafik sebagai objek. Sebelum menggambar garis dan bentuk, merender teks, dan menampilkan gambar dengan GDI+ objek graphics harus dibuat terlebih dahulu. Objek graphics merepresentasikan permukaan gambar GDI+ yaitu objek yang digunakan untuk membuat gambar grafis. Ada dua langkah dalam pemrograman grafik: 1. Membuat gambar graphics 2. Menggunakan objek graphic untuk menggambar garis dan bentuk, render teks, atau menampilkan gambar. • Pembuatan Objek Graphics Sebuah objek graphics dapat dibuat dengan cara: ✓ Menerima sebuah reference ke sebuah objek graphics sebagai bagian dari PaintEventArgs pada event Paint dari sebuah form atau control. ✓ Dengan cara memanggil method CreateGraphics dari sebuah control atau form untuk memperoleh sebuah reference ke sebuah objek Graphics yang merepresentasikan permukaan gambar ✓ Membuat sebuah objekGraphics dari objek yang diturunkan dari image.Pendekatan ni berguna ketika ingin menambahkan/memodifikasi gambar yang sudah ada. Untuk memperoleh sebuah reference ke objek Graphics dan PaintEventArgs pada pain Event: ✓ Deklarasi objek Graphics ✓ Berikan variable untuk mereference ke objek Graphics yang dilewati sebagai bagian dari PaintEventArgs ✓ Masukkan kode untuk menggambar ke form atau control Kode berikut contoh bagaimana merefer sebuah objek Graphics dari PaintEventArgs pada event paint: Private Sub Form1_Paint(sender As Object,pe As PaintEventArgs) Handles MyBase.Paint ‘Deklarasi objek Graphics dan set ke objek Graphics pada PaintEventArgs Dim g As Graphics = pe.Graphics ‘Masukkan kode untuk menggambar ke form di sini End Sub • Method CreateGraphics Untuk membuat sebuah graphic pada vb tentukan lebih dahulu container yang mendeklarasikan dimana graphic tersebut diletakkan misalnya dalam form, panel, dan sebagainya dengan menggunakan method createGraphics. CreateGraphics dari form atau control yang anda ingin gambar. Contoh method creategraphics pada form: Dim pic As System.Drawing.Graphics Pic = Me.CreateGraphics Contoh method creategraphics pada picturebox: Dim pic As System.Drawing.Graphics Pic = PictureBox1.CreateGraphics Membuat dari objek Image Sebagai tambahan, pembuatan objek Graphics dari objek yang diturunkan dari kelas Image dengan cara memanggil method Graphics.FormImage. Dim myBitmap as New Bitmap(“C:\myPic.bmp”) Dim g as Graphics=Graphics.FormImage(myBitmap) Menggambar dan manipulasi bentuk dan image Setelah dibuat objek Graphics bias digunakan untuk menggambar garis dan bentuk, render teks, ataumenampilkan gambar. Objek yang diperlukan untuk digunakan pada objek Graphics adalah : • Kelas Pen, digunakan untuk menggambar garis, bentuk, atau menggambar • bentuk geometris lainnya. • bentuk, gambar atau teks. • Kelas Brush,digunakan untuk mengisi area graphics, seperti mengisi Kelas Font, digunakan untuk menentukan font dari teks. Structure Color,digunakan untuk mengeset warna yang akan ditampilkan. GDI+ dapat digunakan untuk menggambar image yang berada pada sebuah file pada aplikasi dengan membuat sebuah objek baru sebagaikelas image(seperti bitmap),membuat objek Graphics yang merefer permukaan gambar yang ingin digunakan, dan memanggil method DrawImage dari objek Graphics. Untuk menggambar sebuah image dengan GDI+ langkahnya sebagai berikut: • Buat sebuah objek yang merepresentasikan image yang ingin ditampilkan. Objek harus sebuah anggota dari sebuah kelas yang diturunkan dari image seperti bitmap atau metafile. Sebagai contoh berikut: • Dim mybitmap as new Bitmap(“C:/MyImages/TestImages.bmp”) Buat sebuah objek Graphics yang merepresentasikan permukaan gambar yang ingin digunakan. • Dim g as Graphics=Button1.createGraphics Panggil method Graphics.DrawImage dari objek graphics anda untuk menggambar image. Image yang akan digambar dan koordinat dimana akan digambar harus ditentukan. g.DrawImage(myBitmap,1,1) • Menggambar Garis dan Bentuk dengan GDI+ Objek graphics menyediakan method untuk menggambar berbagai jenis garis atau bentuk. Bentuk yang simple maupun komplek dapat digambar menggunakan warna yang transparan atau solid, garis, kurva, dan bentuk lainnya dapat digambar menggunakan objek pen. Untuk mengisi sebuah area seperti segi empat atau curve tertutup, objek brush digunakan. Untuk menggambar garis atau bentuk garisan lain : 1. Ambil sebuah reference atau objek Graphics yang akan digunakan Dim g as graphics = Button1.CreateGraphics 2. Buat instance dari kelas Pen yang diinginkan untuk menggambar garis dan set property lainnya. Dim mypen as new Pen(Color.Red) myPen.width=5 3. Panggil method yang sesuai untuk bentuk yang anda inginkan, beserta parameter lain yang dibutuhkan. Tabel berikut berisi daftar method yang umum digunakan: Method Shape Graphics.DrawLine Line: membutuhkan koordinat mengidentifikasi titik awal dan akhir Graphics.DrawPolygon Bentuk complex: membutuhkan array koordinat Graphics.DrawRectangle Rectangle: membutuhkan 1 atau lebih objek sebagai parameter g.DrawLine(myPen, 1, 1, 45, 65) g.DrawBezier(myPen, 15, 15, 30, 30, 45, 87, 20) g.DrawEllipse(myPen, New Rectangle ( 33, 45, 40, 50)) g.DrawPolygon(myPen,New PointF(){ New PointF(1, 1),_ New PointF(200, 50), New PointF(39, 45)}) • Menggambar Bentuk Berisi ✓ ✓ Ambil sebuah referensi ke objek grafik Buat sebuah instance dari Brush yang ingin digunakan untuk menggambar bentuk Dim g as Graphics= Button1.CreateGraphics ✓ Dim myBrush as new SolidBrush(Color.Red) Panggil method yang sesuai dengan bentuk yang diinginkan. Sebagai contoh untuk FillPolygon dibutuhkan array titik untuk menjelaskan bentuknya. Method lain seperti FillRectangle atau FillPath, dibutuhkan sebuah objek yang menjelaskan area yang akan diisi. g.FillPolygon(myBrush, New PointF() {New PointF(20,20), New PointF(50,100), New PointF(60,10), New PointF(200,4), New PointF(0,0), New PointF(20,20)}) g.FillRectangle(myBrush, New RectangleF(50,50,100,100)) g.FillPie(myBrush, New Rectangle(110,110,300,300),0,90) C. LATIHAN A. Latihan 1 Untuk memperjelas beberapa hal yang dibahas pada dasar teori maka langsung saja dimulai dengan contoh pembuatan graphic sederhana yaitu menggambar sebuah garis. Contoh method untuk menentukan warna garis dan tebal garis Dim namavariabel as New Pen(warnagaris, tebalgaris) Method yang digunakan untuk menggambar garis: Pic.DrawLine(pena,x,y,lebar,tinggi) Buat sebuah form baru dan tambahkan event paint pada form ini, ketikkan didalamnya beberapa script dibawah ini: Public Class Form1 Private Sub Form1_Paint(ByVal sender As System.Object, ByVal ByValue As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim gmbr As System.Drawing.Graphics Dim pena As New Pen(Color.Blue, 4) gmbr = Me.CreateGraphics gmbr.DrawLine(pena, 40, 60, 250, 60) End Sub End Class Hasilnya sebagai berikut: Gambar 3 Latihan 1 B. Latihan 2 • Gambarlah sebuah persegi dengan panjang sama dengan 40 pixel, lebar samadengan 70 pixel, koordinat x sama dengan 50, dan koordinat y sama dengan 80 Method yang digunakan: Pic.DrawRectangle.(pena,x,y,lebar,panjang) Lengkapi kode programnya. Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gambar As System.Drawing.Graphics Dim pena1 As New Pen(Color.Red, 6) gambar = Me.CreateGraphics gambar.DrawRectangle(pena1, 50, 80, 40, 70) End Sub End Class Hasilnya: Gambar 4 Output Latihan 2 C. Latihan 3 • Gambarlah sebuah lingkaran dengan panjang sama dengan 120 pixel, lebar sama dengan 100 pixel, koordinat x sama dengan 30, dan koordinat y sama dengan 20 Method yang digunakan: Pic.DrawEllipse.(pena,x,y,lebar,panjang) Tulislah kode program berikut: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gambar As System.Drawing.Graphics Dim pena1 As New Pen(Color.Brown, 6) gambar = Me.CreateGraphics gambar.DrawEllipse(pena1, 30, 20, 100, 120) End Sub End Class Hasilnya: Gambar 5 Output Latihan 3 D. Latihan 4 • Gambarlah sebuah teks “I LOVE VB” Method yang digunakan: Pic.DrawString.(“text”,jenishuruf,warna,x,y) Tulislah kode program berikut: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gambar As System.Drawing.Graphics Dim pena1 As New Pen(Color.Brown, 6) Dim jenishuruf As New Font("Arial", 15, FontStyle.Bold, FontStyle.Italic) gambar = Me.CreateGraphics gambar.DrawString("I LOVE VB", jenishuruf, Brushes.Blue, 40, 100) End Sub End Class Hasilnya: Gambar 6 Output Latihan 4 E. Latihan 4 Ketikkan kode program berikut: Imports System.Drawing.Graphics Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim G As Graphics G = PictureBox1.CreateGraphics Dim points() As Point = {New Point(20, 20), New Point(120, 230), New Point(320, 120), New Point(420, 220)} G.DrawCurve(Pens.Black, points, 0.1) G.DrawCurve(Pens.AliceBlue, points, 0.5) G.DrawCurve(Pens.Yellow, points, 1) G.DrawCurve(Pens.Red, points, 1.5) End Sub End Class Hasilnya: Gambar 7 Output Latihan 5 F. Latihan 6 Buatlah sebuah lingkaran 2dimensi dengan warna hitam sebagai berikut: Gambar 8 Output Latihan 6 Ketikkan kode program berikut pada class: Public Class Class1 Public Class FillPath Public Shared Sub Main() Application.Run(New Form1) End Sub End Class End Class Ketikkan kode program berikut pada form: Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim graphPath As New GraphicsPath graphPath.AddEllipse(50, 50, 150, 200) Dim blackBrush As New SolidBrush(Color.Black) e.Graphics.FillPath(blackBrush, graphPath) End Sub End Class G. Latihan 7 Menggambar Grafik Buatlah sebuah diagram lingkaran seperti gambar berikut: Public Class Form1 Public Sub DrawPieChart(ByVal percents() As Integer, ByVal colors() As Color, ByVal surface As Graphics, ByVal location As Point, ByVal pieSize As Size) Dim sum As Integer = 0 For Each percent As Integer In percents sum += percent Next Dim percentTotal As Integer = 0 For percent As Integer = 0 To percents.Length() - 1 surface.FillPie(New SolidBrush(colors(percent)), New Rectangle(location, pieSize), CType(percentTotal * 360 / 100, Single), CType(percents(percent) * 360 / 100, Single)) percentTotal += percents(percent) Next Return End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim percents() As Integer = {TextBox1.Text, TextBox2.Text, TextBox3.Text} Dim colors() As Color = {Color.Blue, Color.Green, Color.Black} Dim graphics As Graphics = Me.CreateGraphics Dim location As Point = New Point(0, 0) Dim size As Size = New Size(200, 200) DrawPieChart(percents, colors, graphics, location, size) End Sub End Class Hasilnya: Gambar 9 Output Latihan 7 D. HASIL PRAKTIKUM DAN TUGAS RUMAH a. Praktikum 1 • Gambarlah sebuah lingkaran dengan panjang sama dengan 420 pixel, lebar sama dengan 170 pixel, koordinat x sama dengan 50, dan koordinat y sama dengan 5 Sintaks: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ling As System.Drawing.Graphics Dim pena As New Pen(Color.Green, 6) ling = Me.CreateGraphics ling.DrawEllipse(pena, 50, 5, 420, 170) End Sub End Class Tampilan: Gambar 10 Tampilan Debug praktikum 1 b. Praktikum 2 • Gambarlah sebuah teks sebagai berikut: Nama-nama tokoh dalam kartun doraemon (cambria,12, bold, italic , underline): Doremi (times new roman, 14, blue) Nobita(arial,15, yellow, underline) Shizuka(algerian,16, black,italic) Jayen(batang,18,green,bold) Suneo(centaur,20,red,italic) Doraemon(dotum,22,brown,underline) Degisugi(kalinga,24,orange,bold) Sintaks: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tokoh As System.Drawing.Graphics Dim pena As New Pen(Color.Red, 6) Dim kartun As New Font("Cambria", 12, FontStyle.Bold, FontStyle.Italic, FontStyle.Underline) Dim doremi As New Font("Times New Roman", 14, FontStyle.Underline) Dim shizuka As New Font("Algerian", 15, FontStyle.Bold, FontStyle.Italic) Dim nobita As New Font("Arial", 15, FontStyle.Bold, FontStyle.Italic) Dim jayen As New Font("Batang", 18, FontStyle.Bold) Dim suneo As New Font("Centaur", 20, FontStyle.Italic) Dim doraemon As New Font("Dotum", 22, FontStyle.Underline) Dim degisugi As New Font("Kalinga", 24, FontStyle.Bold) tokoh = Me.CreateGraphics tokoh.DrawString("Tokoh Kartun Doraemon", kartun, Brushes.Black, 40, 20) tokoh.DrawString("Doremi", doremi, Brushes.Blue, 40, 40) tokoh.DrawString("Nobita", nobita, Brushes.Yellow, 40, 60) tokoh.DrawString("Shizuka", shizuka, Brushes.Black, 40, 80) tokoh.DrawString("Jayen", jayen, Brushes.Green, 40, 100) tokoh.DrawString("Suneo", suneo, Brushes.Red, 40, 120) tokoh.DrawString("Doraemon", doraemon, Brushes.Brown, 40, 140) tokoh.DrawString("Degisugi", degisugi, Brushes.Orange, 40, 160) End Sub End Class Tampilan: Gambar 11 Tampilan Debug praktikum 2 c. Praktikum 3 Sintaks: Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics Dim color1 As New Pen(Color.Yellow, 2) Dim color2 As New Pen(Color.Green, 2) Dim color3 As New Pen(Color.Black, 2) Dim color4 As New Pen(Color.Red, 2) g = Me.CreateGraphics g.DrawRectangle(color1, g.DrawRectangle(color2, g.DrawRectangle(color3, g.DrawRectangle(color4, 1, 1, 50, 50) 25, 25, 75, 75) 50, 50, 100, 100) 100, 100, 125, 125) Dim g1 As Graphics = e.Graphics Dim graphicpath As New GraphicsPath Dim kotak As New Rectangle(25, 25, 25, 25) graphicpath.AddRectangle(kotak) Dim color5 As New SolidBrush(Color.Blue) e.Graphics.FillPath(color5, graphicpath) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class Tampilan: Gambar 12 Tampilan Debug praktikum 3 d. Praktikum 4 Sintaks: Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim grap As Graphics = e.Graphics Dim graphicpath As New GraphicsPath Dim kotak As New Rectangle(5, 5, 45, 45) graphicpath.AddRectangle(kotak) Dim color As New SolidBrush(Drawing.Color.Green) e.Graphics.FillPath(color, graphicpath) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class Tampilan: Gambar 13 Tampilan Debug praktikum 4 e. Praktikum 5 Sintaks: Public Class Form1 Inherits System.Windows.Forms.Form Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim p As System.Drawing.Graphics p = Me.CreateGraphics Dim point() As Point = {New Point(20, 30), New Point(200, 200), New Point(198, 32)} p.DrawCurve(Pens.Purple, point, 0.5) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class Tampilan: Gambar 14 Tampilan Debug praktikum 5 f. Praktikum 6 Sintaks: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim gambar As System.Drawing.Graphics Dim pena1 As New Pen(Color.Cyan, 2) Dim pena3 As New Pen(Color.Red, 2) gambar = Me.CreateGraphics gambar.DrawRectangle(pena1, 5, 5, 150, 275) gambar.DrawRectangle(pena3, 200, 80, 250, 150) Dim gambar1 As System.Drawing.Graphics Dim pena2 As New Pen(Color.Yellow, 2) Dim pena4 As New Pen(Color.Cyan, 2) gambar1 = Me.CreateGraphics gambar1.DrawEllipse(pena2, 5, 5, 150, 275) gambar1.DrawEllipse(pena4, 200, 80, 250, 150) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Refresh() Dim G As Graphics G = Me.CreateGraphics Dim points() As Point = {New Point(20, 20), New Point(100, 200), New Point(250, 100), New Point(350, 200)} G.DrawCurve(Pens.Black, points, 0.1) G.DrawCurve(Pens.GreenYellow, points, 0.5) G.DrawCurve(Pens.Green, points, 1) G.DrawCurve(Pens.Red, points, 1.5) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Refresh() Dim G As Graphics Dim blackpen As New Pen(Color.Blue, 2) Dim Dim Dim Dim start As control1 control2 [end] As New Point(40, 100) As New Point(150, 10) As New Point(240, 20) New Point(380, 80) Dim Dim Dim Dim start1 As New Point(40, 100) control4 As New Point(100, 40) control3 As New Point(200, 60) [end1] As New Point(300, 80) Dim Dim Dim Dim start2 As New Point(40, 100) control5 As New Point(100, 60) control6 As New Point(250, 140) [end2] As New Point(300, 80) Dim Dim Dim Dim start3 As New Point(40, 100) control7 As New Point(100, 80) control8 As New Point(250, 180) [end3] As New Point(300, 80) G = Me.CreateGraphics G.DrawBezier((blackpen), G.DrawBezier((blackpen), G.DrawBezier((blackpen), G.DrawBezier((blackpen), End Sub End Class Tampilan: start, control1, control2, [end]) start1, control4, control3, [end1]) start2, control5, control6, [end2]) start3, control7, control8, [end3]) Gambar 15 Tampilan Debug praktikum 6 g. Tugas Rumah 1 Sintaks: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim kata As System.Drawing.Graphics Dim spidol As New SolidBrush(Color.FromArgb(128, 0, 0, 255)) Dim spidol1 As New SolidBrush(Color.FromArgb(255, 0, 0, 255)) Dim font As New Font("Comic Sans MS", 32, FontStyle.Bold, FontStyle.Italic) kata = Me.CreateGraphics kata.DrawString("Belajar Visual Basic.NET", font, spidol, 10, 153) kata.CompositingQuality = Drawing2D.CompositingQuality.GammaCorrected kata.DrawString("Belajar Visual Basic.NET", font, spidol1, 10, 150) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim gambar As System.Drawing.Graphics Dim pena As New Pen(Color.Green, 2) gambar = Me.CreateGraphics gambar.DrawRectangle(pena, 100, 80, 500, 300) Dim kata As System.Drawing.Graphics Dim spidol As New Pen(Color.Green, 6) Dim font As New Font("ComicSans", 22, FontStyle.Bold, FontStyle.Italic) kata = Me.CreateGraphics kata.DrawString("Saya lagi belajar Buku VB.NET", font, Brushes.Green, 190, 85) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim line As System.Drawing.Graphics Dim bulpen As New Pen(Color.Yellow, 2) line = Me.CreateGraphics line.DrawLine(bulpen, 350, 0, 350, 300) line.DrawLine(bulpen, 0, 125, 700, 125) Dim gambar As System.Drawing.Graphics Dim pena As New Pen(Color.Purple, 2) gambar = Me.CreateGraphics gambar.DrawRectangle(pena, 175, 105, 350, 35) Dim kata As System.Drawing.Graphics Dim spidol As New Pen(Color.Lavender, 6) Dim font As New Font("ComicSans", 22, FontStyle.Bold, FontStyle.Italic) kata = Me.CreateGraphics kata.DrawString("Kuasai Visual Basic .NET", font, Brushes.Red, 190, 110) End Sub End Class Tampilan: Gambar 16 Tampilan Debug Tugas Rumah 1 h. Tugas Rumah 2 Sintaks: Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form Public Sub DrawPieChart(ByVal percents() As Integer, ByVal colors() As Color, ByVal surface As Graphics, ByVal location As Point, ByVal pieSize As Size) Dim sum As Integer = 0 For Each percent As Integer In percents sum += percent Next Dim percentTotal As Integer = 0 For percent As Integer = 0 To percents.Length() - 1 surface.FillPie( _ New SolidBrush(colors(percent)), _ New Rectangle(location, pieSize), CType(percentTotal * 360 / 100, Single), _ CType(percents(percent) * 360 / 100, Single)) percentTotal += percents(percent) Next Return End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As Integer = CInt(Me.TextBox1.Text) Dim y As Integer = CInt(Me.TextBox2.Text) Dim z As Integer = CInt(Me.TextBox3.Text) Dim Dim Dim Dim Dim Dim Dim Dim g As Graphics = Me.CreateGraphics graphicPath As New GraphicsPath graphicPath2 As New GraphicsPath graphicPath3 As New GraphicsPath graphicPath4 As New GraphicsPath kotak As New Rectangle(350, 200 - x, 40, x) kotak2 As New Rectangle(450, 200 - y, 40, y) kotak3 As New Rectangle(550, 200 - z, 40, z) Dim kotak4 As New Rectangle(340, 200, 260, 1) graphicPath.AddRectangle(kotak) graphicPath2.AddRectangle(kotak2) graphicPath3.AddRectangle(kotak3) graphicPath4.AddRectangle(kotak4) Dim colour As New SolidBrush(Color.Red) Dim colour2 As New SolidBrush(Color.Yellow) Dim colour3 As New SolidBrush(Color.Green) Dim colour4 As New SolidBrush(Color.Black) g.FillPath(colour, graphicPath) g.FillPath(colour2, graphicPath2) g.FillPath(colour3, graphicPath3) g.FillPath(colour4, graphicPath4) Dim percents() As Integer = {TextBox1.Text, TextBox2.Text, TextBox3.Text} Dim colors() As Color = {Color.Red, Color.Yellow, Color.Green} Dim graphics As Graphics = Me.CreateGraphics Dim location As Point = New Point(0, 0) Dim size As Size = New Size(200, 200) DrawPieChart(percents, colors, graphics, location, size) End Sub End Class Tampilan: Gambar 17 Tampilan Debug Tugas Rumah 2 i. Tugas Rumah 3 Sintaks: Imports System.Drawing.Drawing2D Imports System.Drawing Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim g As Graphics = Me.CreateGraphics Dim br As New SolidBrush(Color.FromArgb(160, Color.Red)) Dim rect As New Rectangle rect.X = 20 rect.Y = 100 rect.Width = 100 rect.Height = 100 g.FillRectangle(br, rect) br.Dispose() br = New SolidBrush(Color.FromArgb(160, Color.Yellow)) rect.X += (rect.Width \ 4) rect.Y += (rect.Height \ 4) g.FillRectangle(br, rect) br.Dispose() 'Gradient Rectangle Dim br2 As New LinearGradientBrush(rect, Color.Red, Color.Yellow, LinearGradientMode.ForwardDiagonal) rect.X = 400 rect.Y = 370 g.FillRectangle(br2, rect) 'Ellipse bergaris Dim br3 As New HatchBrush(HatchStyle.ForwardDiagonal, Color.Green, Color.Yellow) rect.X = 400 rect.Y = 100 g.FillEllipse(br3, rect) 'Rectangle miring Dim br4 As New SolidBrush(Color.DarkBlue) Dim point() As Point = {New Point(250, 150), New Point(200, 200), New Point(290, 290), New Point(340, 240)} g.FillPolygon(br4, point) 'Layang-layang Dim br5 As New LinearGradientBrush(rect, Color.Green, Color.Orange, LinearGradientMode.Horizontal) Dim point1() As Point = {New Point(80, 255), New Point(90, 430), New Point(10, 280), New Point(30, 245)} g.FillPolygon(br5, point1, 0) br5.Dispose() End Sub End Class Tampilan: Gambar 18 Tampilan Debug Tugas Rumah 3 E. DAFTAR PUSTAKA Dosen. 2017. Modul 9 Graphic Pemrograman Visual. Malang: Universitas Negeri Malang