Click to See Complete Forum and Search --> : floating bubbles


Alex122486
September 16th, 2001, 10:36 AM
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

JeffB
September 16th, 2001, 04:02 PM
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! ;)