When you click and draw on this program's form, the code draws other curves related to yours. For example, it might draw a mirror image of what you draw or it might repeat your drawing rotated by multiples of 30 degrees.
The MouseDown, MouseMove, and MouseUp routines do most of the work. MouseDown simply starts drawing and MouseUp ends it.
The MouseMove event handler draws your curve and its modified copies. It draws a line from the previous point (m_X, m_Y) to the mouse's current position. Then depending on the type of drawing (reflection, rotation, etc.) the program transforms the previous and current points and draws a line between them.
|
Private Sub Form_MouseDown(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
m_X = X
m_Y = Y
m_Drawing = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
Dim i As Integer
Dim angle As Double
Dim dx1 As Double
Dim dy1 As Double
Dim dx2 As Double
Dim dy2 As Double
Dim x1 As Double
Dim y1 As Double
Dim x2 As Double
Dim y2 As Double
If Not m_Drawing Then Exit Sub
Select Case m_CurrentStyle
Case "Reflection X"
Line (m_X, m_Y)-(X, Y)
Line (2 * m_Cx - m_X, m_Y)-(2 * m_Cx - X, Y)
Case "Reflection Y"
Line (m_X, m_Y)-(X, Y)
Line (m_X, 2 * m_Cy - m_Y)-(X, 2 * m_Cy - Y)
Case "Reflection XY"
Line (m_X, m_Y)-(X, Y)
Line (2 * m_Cx - m_X, m_Y)-(2 * m_Cx - X, Y)
Line (m_X, 2 * m_Cy - m_Y)-(X, 2 * m_Cy - Y)
Line (2 * m_Cx - m_X, 2 * m_Cy - m_Y)-(2 * m_Cx _
- X, 2 * m_Cy - Y)
Case "Rotation 2"
Line (m_X, m_Y)-(X, Y)
dx1 = m_X - m_Cx
dy1 = m_Y - m_Cy
dx2 = X - m_Cx
dy2 = Y - m_Cy
Line (m_Cx - dx1, m_Cy - dy1)-(m_Cx - dx2, m_Cy _
- dy2)
Case "Rotation 4"
Line (m_X, m_Y)-(X, Y)
dx1 = m_X - m_Cx
dy1 = m_Y - m_Cy
dx2 = X - m_Cx
dy2 = Y - m_Cy
Line (m_Cx - dx1, m_Cy - dy1)-(m_Cx - dx2, m_Cy _
- dy2)
Line (m_Cx - dy1, m_Cy + dx1)-(m_Cx - dy2, m_Cy _
+ dx2)
Line (m_Cx + dy1, m_Cy - dx1)-(m_Cx + dy2, m_Cy _
- dx2)
Case "Rotation 8"
x1 = m_X
y1 = m_Y
x2 = X
y2 = Y
For i = 1 To 8
Line (x1, y1)-(x2, y2)
RotatePointAround m_Cx, m_Cy, PI / 4, x1, y1
RotatePointAround m_Cx, m_Cy, PI / 4, x2, y2
Next i
Case "Rotation Other"
x1 = m_X
y1 = m_Y
x2 = X
y2 = Y
For i = 1 To CInt((2 * PI) / m_Angle)
Line (x1, y1)-(x2, y2)
RotatePointAround m_Cx, m_Cy, m_Angle, x1, _
y1
RotatePointAround m_Cx, m_Cy, m_Angle, x2, _
y2
Next i
End Select
m_X = X
m_Y = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
m_Drawing = False
End Sub
|