Построение треугольника по точкам - VB
Формулировка задачи:
суть, мы счёлкаем по PictureBox и программа должна заносить координаты в отдельные окошки. после того, как нажимаем на кнопку - строить треугольник.
проблема: если вручную заношу координаты - то рисует нормально, а если мышкой нажимаю - то только запоминает последнюю координату, а следовательно рисует не треугольник а луч
как доделать?
Решение задачи: «Построение треугольника по точкам»
textual
Листинг программы
Option Base 1 Dim x11 As Single Dim x12 As Single Dim y11 As Single Dim y12 As Single Dim x13 As Single Dim y13 As Single 'massivy Dim a(4) As Byte Dim b(4) As Byte Dim x1(4) As Single Dim y1(4) As Single Dim x2(4) As Single Dim y2(4) As Single Dim tochka As Integer Function dlina(xd1 As Single, yd1 As Single, xd2 As Single, yd2 As Single) As Single dlina = Sqr(((xd2 - xd1) ^ 2) + ((yd2 - yd1) ^ 2)) End Function Private Sub setka() For dx% = 1 To 20 Picture1.Line (dx, 0)-(dx, 20), vbWhite Picture1.Line (dx, 0)-(dx, 0.35), vbRed 'шкала Picture1.Line (dx, 20)-(dx, 19.65), vbRed 'шкала For i = 5 To 20 Step 5 Picture1.PSet (i - 0.45, 0.7), vbWhite Picture1.Print i Picture1.PSet (i - 0.45, 19.7), vbWhite Picture1.Print i Next i Next dx For dy% = 1 To 20 Picture1.Line (0, dy)-(20, dy), vbWhite Picture1.Line (0, dy)-(0.35, dy), vbRed 'shkala Picture1.Line (19.65, dy)-(20, dy), vbRed For i = 5 To 20 Step 5 Picture1.PSet (0.3, i - 0.2), 16777000 Picture1.Print i Picture1.PSet (19.3, i - 0.2), vbWhite Picture1.Print i Next i Next dy End Sub Private Sub Command1_Click() End Sub Private Sub draw_Click() Picture1.Refresh Picture1.DrawWidth = 4 Static i As Byte For i = 1 To 3 If i = 3 Then Picture1.Line (x1(i), y1(i))-(x1(1), y1(1)), vbYellow Else Picture1.Line (x1(i), y1(i))-(x1(i + 1), y1(i + 1)), vbYellow End If Next i For j = 1 To 3 If j = 3 Then Picture1.Line (x2(j), y2(j))-(x2(1), y2(1)), vbRed Else Picture1.Line (x2(j), y2(j))-(x2(j + 1), y2(j + 1)), vbRed End If Next j End Sub Private Sub exit_Click() End End Sub Private Sub Form_Load() Picture1.Scale (0, 20)-(20, 0) Picture1.FillStyle = 0 Picture1.DrawWidth = 1 setka End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Picture1.Refresh Picture1.PSet (X, Y): tochka = tochka + 1 If tochka > 3 Then tochka = 1 x1(tochka) = X: y1(tochka) = Y Text1(0).Text = x1(1) Text1(1).Text = y1(1) Text1(2).Text = x1(2) Text1(3).Text = y1(2) Text1(4).Text = x1(3) Text1(5).Text = y1(3) End Sub Private Sub pl1_Click() Static i As Byte For i = 1 To 3 If i = 3 Then a(i) = dlina(x1(1), y1(1), x1(i), y1(i)) Else a(i) = dlina(x1(i), y1(i), x1(i + 1), y1(i + 1)) End If Next i Label3.Caption = a(2) End Sub Private Sub pl2_Click() For i = 1 To 3 If i = 3 Then b(i) = dlina(x2(1), y2(1), x2(i), y2(i)) Else b(i) = dlina(x2(i), y2(i), x2(i + 1), y2(i + 1)) End If Next i Label3.Caption = b(3) End Sub Private Sub Text3_Change(Index As Integer) x2(1) = Val(Text3(0).Text) y2(1) = Val(Text3(1).Text) x2(2) = Val(Text3(2).Text) y2(2) = Val(Text3(3).Text) x2(3) = Val(Text3(4).Text) y2(3) = Val(Text3(5).Text) End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д