CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2001
    Posts
    20

    floating bubbles

    i am a beginner that is trying to get mutilple bubles to float upwards in a form (using the circle command to test myself,i already know how with using premade shapes)i can get 1 buble to go up at a time but i want at least 9. (i would also like different colors for each buble) (this is also in vb4 but i do have a working model of 6) heres the code:

    Public Function bub()
    Dim rndnumx As Long 'defines variables
    Dim rndnumy As Long '
    Top: 'endless loop untill told to stop
    r = 255 * Rnd 'random color for circles
    g = 255 * Rnd '
    b = 255 * Rnd '
    rndnumx = Form1.Width 'defines the value for
    rndnumy = Form1.Height 'which the circle will
    'work with
    nus = Rnd 'random position for the start of the
    'circle
    Do Until rndnumy = 0 'ends when the cirle has
    'reached the top of the form
    'creates a circle with a
    'random color
    Circle (rndnumx * nus, rndnumy), 300, RGB(r, g, b)
    For num = 1 To 8000 'delay the circle
    Next num
    'clears the previous circle using the forms
    'back color
    Circle (rndnumx * nus, rndnumy), 300, vbBlack
    'changes the position of the cirlce to make it
    'go "up"
    rndnumy = rndnumy - 5
    'so the user can end the loop
    DoEvents
    'when the user chooses another demo or stops
    'the demo with the mnustop tab mnububles.checked
    'equals false
    If mnububles.Checked = False Then
    GoTo bot
    End If
    Loop
    'does the loop over again
    GoTo Top
    bot:
    End Function


  2. #2
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Re: floating bubbles

    You should use an arrays of nine bubble like that


    'BubbleY(9), the 9 verticals positions of the 9 bubbles
    'BubbleX(9), the 9 horizontals posotions of the 9 bubbles
    Dim BubbleY(9) as integer
    Dim BubbleX(9) as integer




    but you will have many arrays, so create your own TYPE


    private Type Bubble
    X as Integer
    Y as Integer
    End Type

    Dim BubbleArray(9) as Bubble
    BubbleArray(1).X = 300
    ...


    'In this case, you can keep as many informations as you want

    'to draw the bubble, simply use a loop

    [vbcode]
    'initialisation
    for i = 0 to 8
    BubbleArray(i).x = rnd
    ...
    next i

    'Circle (rndnumx * nus, rndnumy), 300, vbBlack
    'changes the position of the cirlce to make it
    'go "up"

    'These 2 lines make the bubble "go up" and draw them
    'use these lines in a loop ( for i = 0 to 8 )
    BubbleArray(i).y = BubbleArray(i).y - rndnumx * nus
    Circle(BubbleArray(i).x,BubbleArray(i).y), 300, vbBlack





    Hope this will help you!


    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

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

Featured