Results 1 to 5 of 5

Thread: triangles

  1. #1

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238

    triangles

    Any body know a good way to draw a triangle and fill it in?

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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....

  3. #3
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    do a search on www.allapi.net for FloodFill
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    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:
    1. Dim FirstX As Single
    2. Dim FirstY As Single
    3. Dim Lenght As Long
    4.  
    5. Private Sub Form_Load()
    6. Picture1.AutoRedraw = True
    7. Picture1.ScaleMode = 3
    8. End Sub
    9.  
    10. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    11. FirstX = X
    12. FirstY = Y
    13. End Sub
    14.  
    15. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    16. If Button = 1 Then
    17.     Picture1.Cls
    18.     Lenght = Sqr((X - FirstX) ^ 2 + (Y - FirstY) ^ 2)
    19.     Picture1.Line (FirstX, FirstY - Lenght)-(FirstX + Lenght, FirstY)
    20.     Picture1.Line (FirstX + Lenght, FirstY)-(FirstX - Lenght, FirstY)
    21.     Picture1.Line (FirstX - Lenght, FirstY)-(FirstX, FirstY - Lenght)
    22.     Picture1.Refresh
    23. End If
    24. End Sub
    25.  
    26. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    27. Picture1.Picture = Picture1.Image
    28. End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width