我正在创建一个程序,用户可以命令一只乌龟在一个名为panel 1的白色面板上移动。我使用rotatefliptype
使乌龟旋转
我现在正在跟进它。我有一些想法,包括将像素放在符合要求的地方。我的一个问题是位置。是否有可能使位置相对于某一点?
我目前的代码是:
Sub imageCloner(clonedImage As Image, clonedWidth As Int16, clonedHeight As Int16, clonedLocation As Point)
'clone image
Dim dotImage As New PictureBox()
dotImage.Image = clonedImage
dotImage.Location = clonedLocation
dotImage.Width = clonedWidth
dotImage.Height = clonedHeight
dotImage.SizeMode = picBoxTurtle.SizeMode
panel1.Controls.Add(dotImage)
End Sub
Sub findGradient()
'gradient = rise / run
turtleMovementGradient = (turtleYLocation - turtleOriginalYLocation) / (turtleXLocation - turtleOriginalXLocation)
End Sub
Sub drawLine()
find the gradient
findGradient()
create variables
Dim xcounter As Int16 = 0
Dim ycounter As Int16 = 0
For ycounter = 1 To panel1.Height
For xcounter = 1 To panel1.Width
If ycounter / xcounter = turtleMovementGradient Then
imageCloner(blackDotOnePixel.Image, 1, 1, New Point(panel1.Width - xcounter, panel1.Height - ycounter))
End If
Next
Next
End Sub
首先运行drawLine()子例程。 我需要帮助绘制线条
答案 0 :(得分:0)
这应该会给你一些想法。
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
' Create a local version of the graphics object for the Panel.
Dim g As Graphics = e.Graphics
' Draw a string on the Panel.
g.DrawString("This is a diagonal line drawn on the control", New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the Panel.
g.DrawLine(System.Drawing.Pens.Red, Panel11.Left, Panel1.Top, Panel1.Right, Panel1.Bottom)
End Sub