Visual Basic Interface

Selasa, 17 Agustus 2010

3D Graphics Visual Basic 2008 Express Edition


Aplikasi kali ini saya akan memvisualisasikan Graphic 3D Form Paint. Baru-baru ini, saya iseng-iseng mencari tutorial programming Graphic 3D dan menemukan contoh script programnya. Source Code Tutorialnya ===>>> Klik Disini, mengamati coding script programming-nya membuat kepala Nyut-nyutan,....

Kok bisa yahhhh programmer neh coding script kayak beginiannnn......dan Saya sangat berharap menemukan suatu celah atau inspirasi untuk dikembangkan menjadi graphic 3D yang lebih aplikative (harapannya sehh........). Graphic 3D yang ditampilkan berupa Cube 3D.

Sekarang saya coba menampilkan hasil visual dari Script VB.net dari Source Code ===>> Disini Klik Neh.... Tutorialnya. Hasil visualnya perhatikan gambar di atas.

ToolBox yang saya pergunakan, perhatikan tabel di bawah ini:

ToolBox
Properties
1 UserFormName: UserForm1
Text: Programming Graphics 3D V. Hutabalian's Blog

Desain Form dari tabel ToolBox di atas, perhatikan gambar di bawah ini.



Setelah selesai mempersiapkan desain Form, dengan mensetting properties Form sesuai dengan yang saya inginkan. Kemudian klik kanan pada Form, pilih View Code saya mengetikkan Source Program di bawah ini.

Script Visual Basic 2008 Express Edition:

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
'3D Programming Graphics Visual Basic Express Edition'
'======================================================================='
' Source code Tutorial===>>> Klik Disini'
' Berbagi ilmu Sensasi Kepuasan Tersendiri '
' Visual By: Verynandus Hutabalian'
' Publish to V. Hutabalian's Blog 18 Agustus 2010 '
'+++++++++++++++++++++++========================++++++++++++++++++++++++'

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Enum RotateHorizontal
Left = -1
Center = 0
Right = 1
End Enum

Public Enum RotateVertical
Up = -1
Center = 0
Down = 1
End Enum

Public Enum CubeSides
Left
Right
Top
Bottom
Front
Back
End Enum

Public Structure Cube
Private FLocation As Point
Private FHeight As Integer
Private FWidth As Integer
Private FDepth As Integer
Private FCenter As Point
Private FPath As GraphicsPath
Private FRotateX As RotateHorizontal
Private FRotateY As RotateVertical

Public Property Location() As Point
Get
Return FLocation
End Get
Set(ByVal Value As Point)
FLocation = Value
Changed()
End Set
End Property

Public Property Height() As Integer
Get
Return FHeight
End Get
Set(ByVal Value As Integer)
FHeight = Value
Changed()
End Set
End Property

Public Property Width() As Integer
Get
Return FWidth
End Get
Set(ByVal Value As Integer)
FWidth = Value
Changed()
End Set
End Property

Public Property Depth() As Integer
Get
Return FDepth
End Get
Set(ByVal Value As Integer)
FDepth = Value
Changed()
End Set
End Property

Public Property Center() As Point
Get
Return FCenter
End Get
Set(ByVal Value As Point)
FCenter = Value
Changed()
End Set
End Property

Public ReadOnly Property Path() As GraphicsPath
Get
Return FPath
End Get
End Property

Public Property RotateX() As RotateHorizontal
Get
Return FRotateX
End Get
Set(ByVal Value As RotateHorizontal)
FRotateX = Value
Changed()
End Set
End Property

Public Property RotateY() As RotateVertical
Get
Return FRotateY
End Get
Set(ByVal Value As RotateVertical)
FRotateY = Value
Changed()
End Set
End Property

Public ReadOnly Property X() As Integer
Get
Return FLocation.X
End Get
End Property

Public ReadOnly Property Y() As Integer
Get
Return FLocation.Y
End Get
End Property

'Return the rectangle that bounds the entire polygon
'representing the cube
Public ReadOnly Property BoundsRect() As Rectangle
Get
If (FPath Is Nothing) Then
Return New Rectangle(0, 0, 0, 0)
Else
Dim r As RectangleF = Path.GetBounds()
' Implicit conversion from single to integer,
' really only available in VB
Return New Rectangle(r.X, r.Y, r.Width, r.Height)
End If
End Get
End Property



Public ReadOnly Property Item(ByVal index As CubeSides) As Point()
Get
Select Case index
Case CubeSides.Back
Return Back
Case CubeSides.Front
Return Front
Case CubeSides.Left
Return Left
Case CubeSides.Right
Return Right
Case CubeSides.Top
Return Top
Case CubeSides.Bottom
Return Bottom
Case Else
Return Front
End Select
End Get
End Property

Public ReadOnly Property Top() As Point()
Get
Return GetTop(Location, Height, Width, Depth, _
RotateX, RotateY)
End Get
End Property

Public ReadOnly Property Bottom() As Point()
Get
Return GetBottom(Location, Height, Width, Depth, _
RotateX, RotateY)
End Get
End Property

Public ReadOnly Property Left() As Point()
Get
Return GetLeft(Location, Height, Width, Depth, _
RotateX, RotateY)
End Get
End Property

Public ReadOnly Property Right() As Point()
Get
Return GetRight(Location, Height, Width, Depth, _
RotateX, RotateY)
End Get
End Property

Public ReadOnly Property Front() As Point()
Get
Return GetFront(Location, Height, Width, Depth, _
RotateX, RotateY)
End Get
End Property

Public ReadOnly Property Back() As Point()
Get
Return GetBack(Location, Height, Width, Depth, _
RotateX, RotateY)
End Get
End Property

Public Sub New(ByVal x As Integer, ByVal Y As Integer, _
ByVal height As Integer, ByVal width As Integer, _
ByVal depth As Integer, ByVal rotateX As RotateHorizontal, _
ByVal rotateY As RotateVertical)

FPath = New GraphicsPath
FLocation = New Point(x, Y)
FHeight = height
FWidth = width
FDepth = depth
FRotateX = rotateX
FRotateY = rotateY
FCenter = New Point(Location.X + (width + depth / 2 * _
rotateX) / 2, _
Location.Y + (height + depth / 2 * rotateY) / 2)

ConstructPath()

End Sub

Public Sub New(ByVal x As Integer, ByVal Y As Integer, _
ByVal height As Integer, ByVal width As Integer, _
ByVal depth As Integer)

FPath = New GraphicsPath
FLocation = New Point(x, Y)
FHeight = height
FWidth = width
FDepth = depth
FRotateX = RotateHorizontal.Right
FRotateY = RotateVertical.Up
FCenter = New Point(Location.X + (width + depth / 2 * _
RotateX) / 2, _
Location.Y + (height + depth / 2 * RotateY) / 2)

ConstructPath()

End Sub

Public Sub New(ByVal point As Point, _
ByVal height As Integer, ByVal width As Integer, _
ByVal depth As Integer)

FPath = New GraphicsPath
FLocation = point
FHeight = height
FWidth = width
FDepth = depth
FRotateX = RotateHorizontal.Right
FRotateY = RotateVertical.Up
FCenter = New Point(Location.X + (width + depth / 2 * _
RotateX) / 2, _
Location.Y + (height + depth / 2 * RotateY) / 2)

ConstructPath()

End Sub


Private Sub Changed()
ConstructPath()
End Sub

Private Sub ConstructPath()
FPath = New GraphicsPath
Path.AddLines(GetBack(Location, Height, Width, Depth, _
RotateX, RotateY))
Path.AddLines(GetFront(Location, Height, Width, Depth, _
RotateX, RotateY))
Path.AddLines(GetTop(Location, Height, Width, Depth, _
RotateX, RotateY))
Path.AddLines(GetBottom(Location, Height, Width, Depth, _
RotateX, RotateY))
Path.AddLines(GetLeft(Location, Height, Width, Depth, _
RotateX, RotateY))
Path.AddLines(GetRight(Location, Height, Width, Depth, _
RotateX, RotateY))
End Sub

Private Function GetXFromCenter(ByVal newCenter As Point) _
As Integer
Return newCenter.X - (FWidth + FDepth / 2 * FRotateX) / 2
End Function

Private Function GetYFromCenter(ByVal newCenter As Point) _
As Integer
Return newCenter.Y - (FHeight + FDepth / 2 * FRotateY) / 2
End Function

Public Sub FilleRectangle(ByVal boundingRect As Rectangle)
Dim x As Integer
If (FRotateX = RotateHorizontal.Right) Then
x = 0
Else
x = Math.Abs(Depth / 2 * FRotateX)
End If

Dim y As Integer
If (FRotateY = RotateVertical.Down) Then
y = 0
Else
y = Math.Abs(Depth / 2 * RotateY)
End If

FLocation = New Point(x, y)
FWidth = boundingRect.Width - Depth / 2 - 1
FHeight = boundingRect.Height - Depth / 2 - 1
ConstructPath()
End Sub

Public Function GetCube() As GraphicsPath
Return FPath
End Function

Public Function GetSides(ByVal theseSides As CubeSides()) _
As GraphicsPath
Dim newPath As GraphicsPath = New GraphicsPath
Dim I As Integer
For I = 0 To theseSides.Length - 1
newPath.AddLines(Item(theseSides(I)))
Next I

Return newPath
End Function

Public Shared Function GetXOffset(ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal) As Integer

Return depth / 2 * rotateX
End Function

Public Shared Function GetYOffset(ByVal depth As Integer, _
ByVal rotateY As RotateVertical) As Integer

Return depth / 2 * rotateY
End Function

Public Shared Function GetTop(ByVal point As Point, _
ByVal height As Integer, _
ByVal width As Integer, _
ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal, _
ByVal rotateY As RotateVertical) _
As Point()

Return New Point() { _
New Point(point.X, point.Y), _
New Point(point.X + GetXOffset(depth, rotateX), point.Y + _
GetYOffset(depth, rotateY)), _
New Point(point.X + width + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY)), _
New Point(point.X + width, point.Y), _
New Point(point.X, point.Y)}
End Function

Public Shared Function GetLeft(ByVal point As Point, _
ByVal height As Integer, _
ByVal width As Integer, ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal, _
ByVal rotateY As RotateVertical)

Return New Point() {New Point(point.X, point.Y), _
New Point(point.X + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY)), _
New Point(point.X + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY) + height), _
New Point(point.X, point.Y + height), _
New Point(point.X, point.Y)}
End Function

Public Shared Function GetRight(ByVal point As Point, _
ByVal height As Integer, _
ByVal width As Integer, ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal, ByVal rotateY _
As RotateVertical)

Return New Point() {New Point(point.X + width, point.Y), _
New Point(point.X + width + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY)), _
New Point(point.X + width + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY) + height), _
New Point(point.X + width, point.Y + height), _
New Point(point.X + width, point.Y)}
End Function

Public Shared Function GetBottom(ByVal point As Point, _
ByVal height As Integer, _
ByVal width As Integer, ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal, _
ByVal rotateY As RotateVertical) As Point()


Return New Point() {New Point(point.X, point.Y + height), _
New Point(point.X + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY) + height), _
New Point(point.X + width + GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY) + height), _
New Point(point.X + width, point.Y + height), _
New Point(point.X, point.Y + height)}
End Function

Public Shared Function GetFront(ByVal point As Point, _
ByVal height As Integer, _
ByVal width As Integer, ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal, ByVal rotateY _
As RotateVertical) As Point()

Return New Point() {point, New Point(point.X + width, point.Y), _
New Point(point.X + width, point.Y + height), _
New Point(point.X, point.Y + height), point}

End Function

Public Shared Function GetBack(ByVal point As Point, _
ByVal height As Integer, _
ByVal width As Integer, ByVal depth As Integer, _
ByVal rotateX As RotateHorizontal, _
ByVal rotateY As RotateVertical) As Point()

Dim topLeft As Point = New Point(point.X + _
GetXOffset(depth, rotateX), _
point.Y + GetYOffset(depth, rotateY))

Dim topRight As Point = New Point(point.X + width + _
GetXOffset(depth, rotateX), point.Y + _
GetYOffset(depth, rotateY))

Dim bottomRight As Point = New Point(point.X + width + _
GetXOffset(depth, rotateX), point.Y + height + _
GetYOffset(depth, rotateY))

Dim bottomLeft As Point = New Point(point.X + _
GetXOffset(depth, rotateX), point.Y + height + _
GetYOffset(depth, rotateY))

Return New Point() {topLeft, topRight, bottomRight, _
bottomLeft, topLeft}

End Function

End Structure
Public Class Form1
Inherits System.Windows.Forms.Form

Private cube As Cube = New Cube(100, 100, 100, 200, 50)

Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
e.Graphics.DrawPath(Pens.Red, cube.GetCube())
End Sub
End Class


Setelah Anda mengetikkan listing source program diatas tekan F5, maka hasil tampilan visualnya seperti gambar di bawah ini.



Saya sangat berharap bisa mempelajari dan mengembangkan script programming Tutorial Graphics 3D di atas dalam bentuk yang aplikative... Untuk sekarang masih di Plototin Doang......Bagi rekan-rekan yang lebih berpengalaman di tunggu saran-sarannya dan kreativitasnya... Semoga dapat Berguna.

Selamat mencoba Guys! Nantikan Tips Aplikasi Cantik Lainnya by Verynandus Hutabalian.

0 komentar:

Dunia Science Terkini

  1. Untaian Genom Dalam 3D
  2. Robot Pelompat
  3. Burung Pertama Bukan Burung
  4. Cincin Terbesar Planet Saturnus
  5. Miliarder Kanada Kembali Dari Luar Angkas
  6. Asteroid Terbesar Kedua di Bimasakti
  7. 32 Planet Terbaru
  8. Planet Terbaru Mengandung Molekul Organik
  9. Tuak Sebagai Energi Alternatif
10. Cumi-Cumi Raksasa Teluk Meksiko
11. Fosil Gajah Purba Teridentifikasi
12. "Ardi" Nenek Moyang Pertama Manusia
13. Konserfasi Gading Gajah Purba Sembarangan
14. Jejak Dinosaurus Terbesar
15. Apakah Manusia Berevolusi
16. Fondasi Kuno 1300 Tahun Lalu Ditemukan
17. Fosil Telur Dinosaurus India
18. Pecahan Keramik Abad XII
19. Penemuan Terbaru Putra Indonesia
20. Udang Tanpa Mata
21. Menguak Misteri Si Raja Laut
22. Goa Terbesar Di Dunia
23. Nobel Fisika Diraih 3 Ilmuan AS
24. Tiga Peneliti Ribosom Raih Nobel
25. Kemungkinan Asteroid Menabrak Bumi
26. 24 Pulau Indonesia Hilang
27. 50 Perusahaan Kategori Hitam
28. Anak SMP Pencipta Antivirus
29. Apakah Manusia Berevolusi
30. Ida, Potongan Jejak Evolusi Primata
31. Nasa Sukses Uju Coba Protipe Ares I-X
32. Monster Laut Inggris Lebih Garang dari T-Rex
33. Ledakan Bone Adalah Asteroid Jatuh
34. Ledakan Meteor Di Bone Lampui Bom Atom
35. Dinosaurus Lapis Baja Ditemukan
36. Retakan Besar di Afrika Bakal Menjadi Samudera Baru
37. Batu Megalitikum Usia Ribuan Tahun
38. Jejak Kaki Dinosaurus Di Selandia Baru
39. Kudus Lacak Tengkorak Homo Erectus
40. Fosil Spesies Baru Dinosaurus Jurassic
41. Di Indonesia Peningkatan Kasus AIDS 8 Kali Lipat
42. 270 Ribu Penduduk Tertular HIV/AIDS
43. Awas, Operasi Permak Miss V tak Aman
44. Manfaat Rokok Hanyalah Sugesti dan Mitos
45. Teknik Pembenaman Karbon Dikaji
46. 2012, Matahari dan Bosscha
47. Bunga Bangkai Raksasa Mekar di Mekarsari
48. Fosil Kepala Gajah Purba Seberat 1 Kuintal
49. Menelusuri Jejak Lava Gunung Pra-Sunda
50. Legenda "Pengisap Darah" Chupacabra
51. Adanya Harapan Kanker Bisa Diobati
52. Sedot Lemak Menggunakan Gelombang Radio
53. NASA Persiapkan Atlantis untuk Misi ke ISS
54. 25 Galon Air Muncrat dari Permukaan Bulan
55. Peluncuran Pesawat Ulang Alik Atlantis
56. Sebuah Sumur Kerajaan Mataram Kuno
57. Seekor Anak Ikan Purba Terekam Kamera
58. Buaya Purba Bergigi Babi Hutan, Tikus & Moncong Lebar
59. Kemungkinan Penyakit Menjangkit di Bulan Desember
60. Kafan Yesus, Tubuh Dalam Kafan Melayang
61. Misteri Berkas Tulisan Kain Kafan Yesus
62. Jemari dan Gigi dari Jenazah Galileo Galilei
63. Ribuan Makhluk Aneh Di Dasar Samudera
64. Akademisi Memperingati 150 Tahun Karya Darwin
65. Peningkatan Tertinggi Gas Rumah Kaca 2008
66. Pemanasan Global Lebih Buruk Dari Perkiraan
67. Ternyata, Kulit Bisa Mendengar
68. Makin Berlemak, Makin Sulit Berhenti Makan
69. Atlantis Menunju Bumi
70. Otak Besar, Tidak Berarti Lebih Pintar
71. 10 Ramalan Kiamat Terbukti Meleset
72. Mesin Big Bang Selidiki Misteri Alam Semesta
73. Ternyata Alien Sudah Membaur Di Bumi
74. Sejarah di Balik Legenda Vampir
75. Pesawat Ulang Alik Atlatis Mendarat Mulus
76. Perjalanan Panjang HIV/AIDS
77. Wah... Setiap Hari Ada 7.400 Kasus Baru HIV!
78. Tim Vertebrata Lanjutkan Penelitian Gajah Purba
79. Wah... Setiap Hari Ada 7.400 Kasus Baru HIV!
80. Kesepian Menular Seperti Virus
81. Militer Inggris Tutup Kuping soal UFO
82. Objek Misterius Dekat Bintang Mirip Matahari
83. Virgin Galactic Kenalkan SpaceShipTwo
84. Tetap Internetan Saat Penerbangan
85. Jepang Luncurkan Satelit Pengintai Kelima
86. Robot Kerang Bisa Ledakkan Tambang di Bawah Air
87. Mahasiswa Matematika Juarai Kompetisi "Hacker"
88. UFO di Sayap Pesawat Lion Air
89. Lima Benda Purbakala Ditemukan di Desa Tanjungsari
90. Afrika Asal Usul Suku Bangsa Asia
91. Kembaranku Robot
92. Pertikaian Microsoft Vs Uni Eropa Berakhir
93. Kopi Tunda Alzheimer Parah
94. Gen Penyebab Alzheimer Berhasil Ditemukan
95. Ada Kaitan Alzheimer dengan Hormon Nafsu Makan
96. Ditemukan Planet Serupa Bumi yang Memiliki Air