VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Draws a curve from a random array of 3-9 coordinates. (Press numbers 3-9 for the size of the array

Zeev Rotshtein  (1 Submission)   Graphics   Visual Basic 5.0   Unknown Difficulty   Thu 11th August 2005   Mon 8th February 2021

Draws a curve from a random array of 3-9 coordinates. (Press numbers 3-9 for the size of the array and Enter to draw).

API Declarations



Option Explicit

Const STEP = 100

Public Enum SplineSegment
SplineMiddleSegment = &H0
SplineFirstSegment = &H1
SplineLastSegment = &H2
SplineSingleSegment = &H3
End Enum

Public Type Coordinate
X As Double
Y As Double
End Type

Public Sub HalfSpline(Board As Form, Point1 As Coordinate, Point2 As Coordinate, Point3 As Coordinate, Optional Flag As SplineSegment = SplineMiddleSegment)
Dim p1 As Coordinate
Dim p3 As Coordinate

If (Flag And SplineFirstSegment) Then
p1.X = Point1.X
p1.Y = Point1.Y
Else
p1.X = (Point1.X + Point2.X) / 2
p1.Y = (Point1.Y + Point2.Y) / 2
End If

If (Flag And SplineLastSegment) Then
p3.X = Point3.X
p3.Y = Point3.Y
Else
p3.X = (Point3.X + Point2.X) / 2
p3.Y = (Point3.Y + Point2.Y) / 2
End If

SingleSpline Board, p1, Point2, p3
End Sub

Public Sub SingleSpline(Board As Form, Point1 As Coordinate, Point2 As Coordinate, Point3 As Coordinate)
Dim i As Integer

Dim CurrX1 As Double
Dim CurrY1 As Double
Dim CurrX2 As Double
Dim CurrY2 As Double

Dim StepX1 As Double
Dim StepY1 As Double
Dim StepX2 As Double
Dim StepY2 As Double

Dim DX As Double
Dim DY As Double
Dim LastDX As Double
Dim LastDy As Double

CurrX1 = Point1.X
CurrY1 = Point1.Y
CurrX2 = Point2.X
CurrY2 = Point2.Y

StepX1 = (Point2.X - Point1.X) / STEP
StepY1 = (Point2.Y - Point1.Y) / STEP
StepX2 = (Point3.X - CurrX2) / STEP
StepY2 = (Point3.Y - CurrY2) / STEP

LastDX = CurrX1
LastDy = CurrY1

For i = 0 To STEP
DX = ((CurrX2 - CurrX1) * (i / STEP)) + CurrX1
DY = ((CurrY2 - CurrY1) * (i / STEP)) + CurrY1
Board.Line (DX, DY)-(LastDX, LastDy)

LastDX = DX
LastDy = DY

CurrX1 = CurrX1 + StepX1
CurrY1 = CurrY1 + StepY1
CurrX2 = CurrX2 + StepX2
CurrY2 = CurrY2 + StepY2
Next i
End Sub

Rate Draws a curve from a random array of 3-9 coordinates. (Press numbers 3-9 for the size of the array (1(1 Vote))
Draws a curve from a random array of 3-9 coordinates. (Press numbers 3-9 for the size of the array .bas

Draws a curve from a random array of 3-9 coordinates. (Press numbers 3-9 for the size of the array Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters