vb绘图
vb绘图
2-4:Imports System.Math
Public Class Form1
Private Sub Draw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Draw.Click
Dim g As Graphics
Dim p As Pen
Dim i, j, oldx, oldy As Integer
Dim r As Integer = 120
Dim pi As Single = 3.14159
Dim px(0 To 4) As Integer, py(0 To 4) As Integer
g = PictureBox1.CreateGraphics
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
p = New Pen(Color.Black)
'设定坐标系
g.TranslateTransform(160, 120)
g.ScaleTransform(0.6, -0.6) '坐标缩小并Y轴朝上 g.DrawEllipse(p, -1 * r, -1 * r, 2 * r, 2 * r)
'计算五边形顶点
For i = 0 To 4
px(i) = r * Cos(0.1 * pi + 0.4 * pi * i)
py(i) = r * Sin(0.1 * pi + 0.4 * pi * i)
Next
oldx = py(0) : oldy = py(0)
For i = 0 To 4
For j = 0 To 4
If i <> j Then
g.DrawLine(Pens.Black, px(i), py(i), px(j), py(j)) End If
Next j
Next i
倾斜矩形:Private Sub Rect_Angle(ByRef x As Object, ByRef y As Object, ByRef W As Object, ByRef H As Object, ByRef th As Object)
'x, y为旋转基点,th为倾角,W,H为矩形的长、宽
Dim x1, y1, x2, y2, x3, y3, x4, y4 As Integer '矩形的四个角点 th = th * pi / 180
x1 = x
y1 = y
x2 = Int(x1 + W * Cos(th))
y2 = Int(y1 - w * Sin(th))
x3 = Int(x2 - h * Sin(th))
y3 = Int(y2 - h * Cos(th))
x4 = Int(x3 - w * Cos(th))