Draw Hexagon : Hexagon « 2D Graphics « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » 2D Graphics » Hexagon 
17.9.1.Draw Hexagon
Draw Hexagon
'Visual Basic.Net JingCai Programming 100 Examples
'Author: Yong Zhang
'Publisher: Water Publisher China
'ISBN: 750841156


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class DrawHexagon
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class


Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.SystemColors.Window
        Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Top
        Me.PictureBox1.Location = New System.Drawing.Point(00)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(504304)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(160320)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(8032)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Hexagon"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(296320)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(8032)
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "Circle"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(504366)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.PictureBox1)
        Me.ResumeLayout(False)

    End Sub

    Dim pen1 As New System.Drawing.Pen(Color.Green, 0.4)
    Dim As System.Drawing.Graphics
    Const Max = 20
    Const pi = 3.1415926
    Dim dx(Max), dy(MaxAs Double
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
        g = PictureBox1.CreateGraphics
        PictureBox1.Refresh()
        Dim As Integer
        Dim s, r As Double
        i = 6
        s = 80
        r = 0.34
        setdate(6)
        snow(200.0#, 180.0#, 6, i, s, r)
    End Sub

    Private Sub Sixth(ByVal x, ByVal y, ByVal n, ByVal s)
        Dim i, j, x1, x2, y1, y2 As Integer
        For i = To n
            If i = n Then
                j = 1
            Else
                j = i + 1
            End If
            x1 = Int(x + dx(i* s50
            y1 = Int(y + dy(i* s55
            x2 = Int(x + dx(j* s50
            y2 = Int(y + dy(j* s55
            g.DrawLine(pen1, x1, y1, x2, y2)
        Next
    End Sub

    Private Sub snow(ByVal x, ByVal y, ByVal n, ByVal i, ByVal s, ByVal r)
        Dim t, t1 As Integer
        Dim xx, yy, s1 As Double
        If i > Then
            For t = To n
                xx = x + dx(t* s
                yy = y + dy(t* s
                t1 = i - 1
                s1 = s * r
                snow(xx, yy, n, t1, s1, r)
            Next
        End If
        Sixth(x, y, n, s)
    End Sub

    Private Sub setdate(ByVal n)
        Dim As Integer
        Dim theta As Double
        dx(i0.0#
        dy(i0.0#
        theta = 2.0# * pi / n
        For i = To n
            dx(i= Math.Sin(i * theta)
            dy(i= Math.Cos(i * theta)
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button2.Click
        PictureBox1.Refresh()
        g = PictureBox1.CreateGraphics
        Dim n, i As Integer
        Dim r, r1, c As Single
        Dim As Double = 0.8
        Dim As Double = 0.2
        c = 40.0#
        n = 6
        r1 = 0.5 1000 (- f(- p)
        r = r1 / c
        g.DrawEllipse(pen1, 200 - r, 150 - r, * r, * r)
        circle(200150, r, n + 1)
    End Sub
    Private Sub circle(ByVal x, ByVal y, ByVal r, ByVal n)
        Dim tcos(100), tsin(100As Single
        Dim i, ns As Integer
        Dim theta As Double
        Dim As Single = 0.3!
        Dim As Double = 2
        ns = 10
        theta = * pi / ns
        Dim n1, f1 As Single
        n1 = n - 1
        f1 = f * r
        If n1 > Then
            For i = To ns
                tcos(i= c * Math.Cos(i * theta)
                tsin(i= c * Math.Sin(i * theta)
                g.DrawEllipse(pen1, x + r * tcos(i- f1, y + r * tsin(i- f1, * f1, * f1)
                circle(x + r * tcos(i), y + r * tsin(i), f1, n1)
            Next
        End If
    End Sub
End Class
17.9.Hexagon
17.9.1.Draw HexagonDraw Hexagon
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.