Any body know a good way to draw a triangle and fill it in?
Printable View
Any body know a good way to draw a triangle and fill it in?
You could find a fill algorithm, or you could make a loop: draw a line from left corner to the top, and then make the line smaller draw from the left corner (X+1) and to the top (Y - 1, X + 1) until the lenght is 1....that would make a fine triangle....:)
do a search on www.allapi.net for FloodFill
here's an example i made to draw triangles:
Just add a picturebox to the form and then paste this code to the form
VB Code:
Dim FirstX As Single Dim FirstY As Single Dim Lenght As Long Private Sub Form_Load() Picture1.AutoRedraw = True Picture1.ScaleMode = 3 End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) FirstX = X FirstY = Y End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Picture1.Cls Lenght = Sqr((X - FirstX) ^ 2 + (Y - FirstY) ^ 2) Picture1.Line (FirstX, FirstY - Lenght)-(FirstX + Lenght, FirstY) Picture1.Line (FirstX + Lenght, FirstY)-(FirstX - Lenght, FirstY) Picture1.Line (FirstX - Lenght, FirstY)-(FirstX, FirstY - Lenght) Picture1.Refresh End If End Sub Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Picture1.Picture = Picture1.Image End Sub
This gives me a chance to show off a bit. I've made this to make arrows. You can make x,y static once you know where it looks good. Please give me credit if you publish, I need it on my resume:
'written by joeyo2 10/05/01 as example for arrow button
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
For size = 1 To 255
col = RGB(size, 255 - size / 2, size / 2)
Line (X - size, Y + size)-(X - size, Y - size), col
Line -(X + size, Y), col
Line -(X - size, Y + size), col
Next
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
For size = 1 To 255
col = RGB(size / 2, 255 - size, 255 - size)
Line (X - size, Y + size)-(X - size, Y - size), col
Line -(X + size, Y), col
Line -(X - size, Y + size), col
Next
debug.print X & ", " & Y
End Sub