Results 1 to 5 of 5

Thread: Drawing Stars

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    6

    Unhappy

    hi does ne 1 know the code to produce either of the followings

    *
    **
    ***
    ****

    ****
    ***
    **
    *

    *
    **
    ***
    ****

    ****
    ***
    **
    *

    also adding to that does ne 1 know how to add in a pice of code that asks the user for the dimension

    cheers!

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    What exactly is that pattern you're trying to reproduce? It might be helpful to know what it is before simply bashing together something to reproduce it I originally looked at this thread because of the subject... on that note, I do have a sub that will draw a real star (of any number of points you choose) on something. Let me know if you'd like it.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    6

    Wink

    hi...

    yes basically its a pattern of stars...i think it kinda uses loops or whatever..


    ****
    ***
    **
    *

    this is the pattern that i posted on earlier... and the otehr things where just the same thing but in a different direction.. basically im after how do you create something like this!

    thanks
    any more probs lemme know
    cheers

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Code:
        Dim strStars As String
        Dim intSize As Integer
        Dim strResponse As String
        Dim intMax As Integer
        
        
        ' Keep producing patterns until the user enters zero
        Do Until strResponse = "0"
            ' imitialize stars
            strStars = "*"
    
            ' Get the maximum size from the user. Use 10 as the suggested value.
            strResponse = InputBox("How big do you want the longest row to be? " _
                        & "(1 to 100 or 0 to quit)", "Stars!", 10)
            Select Case True
                Case Len(strResponse) = 0
                    ' The user pressed "Cancel"
                    MsgBox "Please enter a number between 0 and 100"
                Case strResponse = "0"
                    MsgBox "Bye"
                    Exit Do
                Case Val(strResponse) > 0 And Val(strResponse) < 101
                    ' Convert the response to a number
                    intMax = Val(strResponse)
                    If MsgBox("Do you want the rows to start small and get bigger?", _
                             vbQuestion + vbYesNo, "Which direction?") = vbYes Then
                        ' Bigger is easy
                        For intSize = 1 To intMax
                            strStars = strStars & "*"
                            Debug.Print strStars
                        Next
                    Else
                        ' Smaller is only a little harder. First create a string
                        ' that contains the maximum number od stars
                        For intSize = 1 To intMax
                            strStars = strStars & "*"
                        Next
                        ' Then shorten and print it until it's a single star
                        For intSize = intMax To 1 Step -1
                            Debug.Print Left$(strStars, intSize)
                        Next
                    End If
                Case Else
                    MsgBox "Invalid response, please try again."
            End Select
        Loop
        
        End

  5. #5
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    I finally found my star drawing sub. Currently, it just draws a simplistic star of a given number of points. I'm trying to make it do triangular points instead of just lines, but that's a little harder.

    Code:
    Public Sub DrawStar(objTarget As Object, sngX As Single, sngY As Single, sngRadius As Single, Optional intPoints As Integer = 5, Optional intMode As Integer = vbCopyPen, Optional intStyle As Integer = vbSolid, Optional intWidth As Integer = 1, Optional lngColor As OLE_COLOR = vbBlack)
    
       Dim i As Integer
       Dim intOldDrawMode As Integer
       Dim intOldDrawStyle As Integer
       Dim intOldDrawWidth As Integer
       Dim sngPi As Single
       
       If (TypeOf objTarget Is PictureBox) Or (TypeOf objTarget Is Form) Then
          sngPi = 4 * Atn(1)
    
          If intWidth <= 0 Then intWidth = 1
          If intPoints <= 0 Then intPoints = 1
    
          intOldDrawMode = objTarget.DrawMode
          intOldDrawStyle = objTarget.DrawStyle
          intOldDrawWidth = objTarget.DrawWidth
    
          objTarget.DrawMode = intMode
          objTarget.DrawStyle = intStyle
          objTarget.DrawWidth = intWidth
    
          For i = 0 To (intPoints - 1)
             objTarget.Line (sngX, sngY)-(sngX + (sngRadius * Sin(((2 * sngPi) / intPoints) * i)), sngY + (-sngRadius * Cos(((2 * sngPi) / intPoints) * i))), lngColor
          Next i
    
          objTarget.DrawMode = intOldDrawMode
          objTarget.DrawStyle = intOldDrawStyle
          objTarget.DrawWidth = intOldDrawWidth
    
       End If
    
    End Sub
    You can do whatever you wish with this. Anyone that's had trig can do it.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

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