不成熟的座標繪圖系統Coordinate

之前的Coordinate 只能話座標點,如果遇上函式確實可以慢慢描點,不過電腦可能會累死。

 

首先ArrowPen 是用來取得畫箭頭用的Pen,其參數為ArrowPen(筆的顏色)。

]Function ArrowPen(ByVal TheColor As Color) As Pen

]ArrowPen = New Pen(TheColor)

]ArrowPen.StartCap = Drawing2D.LineCap.Flat

]ArrowPen.EndCap = Drawing2D.LineCap.ArrowAnchor

]Return ArrowPen

]End Function

 

這次Coordinate 不是單單增加畫函式的功能,還有對昔日雜亂的程式碼做部分的簡化。

]Structure Coordinate

]Dim Graphic As Graphics

]Dim X As Settings

]Dim Y As Settings

]Dim Points As Point()

]Dim RealPoints As Point()

]Dim Equations As Equation()

]Dim EquationColors As Color()

]Dim Center As Point

]Dim NameSiteMovement As Double

]Dim AxisFurWidth As Integer

]

]Overloads Function IndexOf(ByVal ThePoint As Point) As Integer

]If (Points Is Nothing) Then

]Return -1

]End If

]For i1  As Integer = LBound(Points) To UBound(Points) Step 1

]If (Points(i1) = ThePoint) Then

]Return i1

]End If

]Next

]Return -1

]End Function

]

]Overloads Function IndexOf(ByVal TheEquation As Equation) As Integer

]If (Equations Is Nothing) Then

]Return -1

]End If

]For i1 As Integer = LBound(Equations) To UBound(Equations) Step 1

]If (Equations(i1).Equals(TheEquation)) Then

]Return i1

]End If

]Next

]Return -1

]End Function

]

]Function RealPoint(ByVal ThePoint As Point) As Point

]Return New Point(ThePoint.X, Y.Length - ThePoint.Y)

]End Function

]

]Function ToCenter(ByVal ThePoint As Point) As Point

]Return New Point(ThePoint.X + Center.X, ThePoint.Y - (Y.Length - Center.Y))

]End Function

]

]Function DrawAxis(Optional ByVal NameFont As String = "微軟正黑體", Optional ByVal NameSize As Integer = 9) As Boolean

]With Graphic

].DrawLine(ArrowPen(X.AxisColor), New Point(0, Center.Y), New Point(X.Length, Center.Y))

].DrawLine(ArrowPen(Y.AxisColor), New Point(Center.X, Y.Length), New Point(Center.X, 0))

].DrawString(X.Name, New Font(NameFont, NameSize), X.NameColor, X.Length * NameSiteMovement, Center.Y)

].DrawString(Y.Name, New Font(NameFont, NameSize), Y.NameColor, Center.X, 0 * NameSiteMovement)

]For i1 As Integer = 0 To X.Up Step 1

].DrawLine(New Pen(X.AxisColor), New Point(Center.X + i1 * X.Pixel, Center.Y - AxisFurWidth), New Point(Center.X + i1 * X.Pixel, Center.Y + AxisFurWidth))

]Next

]For i1 As Integer = 0 To X.Down Step -1

].DrawLine(New Pen(X.AxisColor), New Point(Center.X + i1 *X.Pixel, Center.Y - AxisFurWidth), New Point(Center.X + i1 * X.Pixel, Center.Y + AxisFurWidth))

]Next

]For i1 As Integer = 0 To Y.Up Step 1

].DrawLine(New Pen(Y.AxisColor), New Point(Center.X - AxisFurWidth, Center.Y - i1 * Y.Pixel), New Point(Center.X + AxisFurWidth, Center.Y - i1 * Y.Pixel))

]Next

]For i1 As Integer = 0 To Y.Down Step -1

].DrawLine(New Pen(Y.AxisColor), New Point(Center.X - AxisFurWidth, Center.Y - i1 * Y.Pixel), New Point(Center.X + AxisFurWidth, Center.Y - i1 * Y.Pixel))

]Next

]End With

]Return True

]End Function

]

]Function DrawPoints(ByVal PointColor As Color, Optional ByVal Width As Integer = 2) As Boolean

]If (RealPoints Is Nothing) Then

]Return False

]End If

]For i1 As Integer = LBound(RealPoints) To UBound(RealPoints) Step 1

]Graphic.DrawEllipse(New Pen(PointColor), CInt(RealPoints(i1).X - Width / 2), CInt(RealPoints(i1).Y - Width / 2), CInt(Width), CInt(Width))

]Next

]Return True

]End Function

]

]Function DrawEquations(Optional ByVal Per As Object = 0.001, Optional ByVal Compound As Integer = 0) As Boolean

]If (Equations Is Nothing) Then

]Return False

]End If

]With Graphic

]For EquationIndex As Integer = LBound(Equations) To UBound(Equations) Step 1

]For i1 As Object = 0 To X.Up Step Per

].DrawLine(New Pen(EquationColors(EquationIndex Mod (UBound(EquationColors) - LBound(EquationColors) + 1))), ToCenter(RealPoint(New Point(i1 * X.Pixel, Equations(EquationIndex).Value(i1) * Y.Pixel))), ToCenter(RealPoint(New Point((i1 + Per + Compound) * X.Pixel, Equations(EquationIndex).Value(i1 + Per + Compound) * Y.Pixel))))

]Next

]For i1 As Object = 0 To X.Down Step -Per

].DrawLine(New Pen(EquationColors(EquationIndex Mod (UBound(EquationColors) - LBound(EquationColors) + 1))), ToCenter(RealPoint(New Point(i1 * X.Pixel, Equations(EquationIndex).Value(i1) * Y.Pixel))), ToCenter(RealPoint(New Point((i1 + Per + Compound) * X.Pixel, Equations(EquationIndex).Value(i1 + Per + Compound) * Y.Pixel))))

]Next

]Next

]End With

]Return True

]End Function

]

]Sub New(ByVal MainObject As System.Object, ByVal AllColor As Color, Optional ByVal Names As String = "XY")

]With X

].Name = Names(0)

].NameColor = Brushes.Black

].AxisColor = AllColor

].Length = MainObject.Size.Width

]End With

]With Y

].Name = Names(1)

].NameColor = Brushes.Black

].AxisColor = AllColor

].Length = MainObject.Size.Height

]End With

]Graphic = MainObject.CreateGraphics

]NameSiteMovement = 0.95

]AxisFurWidth = 1

]ReDim EquationColors(0)

]EquationColors(0) = Color.Black

]End Sub

]

]Overloads Sub Push(ByVal NewPoint As Point)

]If Not(IndexOf(NewPoint) = -1) Then

]Exit Sub

]End If

]If (Points Is Nothing) Then

]ReDim Points(0)

]Else

]ReDim Preserve Points(UBound(Points) + 1)

]End If

]Points(UBound(Points)) = NewPoint

]Empire(NewPoint.X, X.Down, X.Up)

]Empire(NewPoint.Y, Y.Down, Y.Up)

]End Sub

]

]Overloads Sub Push(ByVal NewEquation As Equation)

]If Not (IndexOf(NewEquation) = -1) Then

]Exit Sub

]End If

]If (Equations Is Nothing) Then

]ReDim Equations(0)

]Else

]ReDim Preserve Equations(UBound(Equations))

]End If

]Equations(UBound(Equations)) = NewEquation

]Dim Vertexes As Object() = NewEquation.Differential.Root(New Equation(New Short() {0}))

]If (Vertexes Is Nothing) Then

]Exit Sub

]End If

]For i1 As Integer = LBound(Vertexes) To UBound(Vertexes) Step 1

]Empire(Vertexes(i1), X.Down, X.Up)

]Empire(NewEquation.Value(Vertexes(i1)), Y.Down, Y.Up)

]Next

]End Sub

]

]Overloads Sub Kill(ByVal ThePoint As Point)

]If (IndexOf(ThePoint) = -1) Then

]Exit Sub

]End If 

]For i1 As Integer = IndexOf(ThePoint) To UBound(Points) - 1 Step 1

]Points(i1) = Points(i1 + 1)

]Next

]ReDim Preserve Points(UBound(Points) - 1)

]End Sub

]

]Overloads Sub Kill(ByVal TheEquation As Equation)

]If (IndexOf(TheEquation) = -1) Then

]Exit Sub

]End If

]For i1 As Integer = IndexOf(TheEquation) To UBound(Equations) - 1 Step 1

]Equations(i1) = Equations(i1 + 1)

]Next

]ReDim Preserve Equations(UBound(Equations) - 1)

]End Sub

]

]Sub AutoSet(Optional ByVal Movement As Integer = 1)

]If (Points Is Nothing) Then

]Exit Sub

]End If

]With X

].Up += Movement

].Down -= Movement

]If Not (.Up > 0) Then

].Up = 0 + Movement

]End If

]If Not (.Down < 0) Then

].Down = 0 - Movement

]End If

].Pixel = .Length / (.Up - .Down)

]End With

]With Y

].Up += Movement

].Down -= Movement

]If Not (.Up > 0) Then

].Up = 0 + Movement

]End If

]If Not (.Down < 0) Then

].Down = 0 - Movement

]End If

].Pixel = .Length / (.Up - .Down)

]End With

]Center = RealPoint(New Point((0 - X.Down) / (X.Up - X.Down) * X.Length, (0 - Y.Down) / (Y.Up - Y.Down) * Y.Length))

]RealPoints = Points

]For i1 As Integer = LBound(RealPoints) To UBound(RealPoints) Step 1

]RealPoints(i1) = ToCenter(RealPoint(New Point(RealPoints(i1).X * X.Pixel, RealPoints(i1).Y * Y.Pixel)))

]Next

]End Sub

]

]Structure Settings

]Dim Name As Char

]Dim NameColor As Brush

]Dim AxisColor As Color

]Dim Length As Integer

]Dim Up As Object

]Dim Down As Object

]Dim Pixel As Double

]End Structure

]End Structure

文章標籤
全站熱搜
創作者介紹
創作者 GPhettoH 的頭像
GPhettoH

歇息,等待明日的天空

GPhettoH 發表在 痞客邦 留言(0) 人氣(35)