PDA

View Full Version : [Q] Firework, ai co' kho^ng cho em xin



White_Rose
28-10-2002, 02:46
ai có thuật toán hay source code (=VB là tốt nhất hoặc nếu ko = C hay pascal cũng được) về firework (pháo hoa ý) cho em xin với.

White_Rose
01-11-2002, 00:53
helppp đi mà :((

vuminhphan
01-11-2002, 07:27
thử xem nhé:

Private Sub Form_Load()
'logical initialization
Randomize Timer


Form1.BackColor = vbBlack


Form1.AutoRedraw = False


Form1.Show

'constants
Const pi = 3.14159265358979
Const fragments = 40

'explosion fragment variables
Dim fragx(1 To fragments) As Integer
Dim fragy(1 To fragments) As Integer
Dim prevx(1 To fragments) As Integer 'these are to remember the previous coordinates, so
Dim prevy(1 To fragments) As Integer 'the line connects to the previous point
Dim fragangle(1 To fragments) As Single
Dim fragpower(1 To fragments) As Integer
Dim fragcolorR(1 To fragments) As Integer 'using the RGB color
Dim fragcolorG(1 To fragments) As Integer 'system, best use this
Dim fragcolorB(1 To fragments) As Integer 'with 32-bit color

'loop-variables, nothing but that
Dim loopvar As Integer, loopvar2 As Integer

Dim size As Single
Dim timeloop As Long



Do
'launching part
x = Form1.Width / 2 'set staring-point
y = Form1.Height'mid-under In form
xplus = Rnd * 150 - 75 'randomize forces
yplus = Rnd * 50 - 200 'horizontal, vertical



For loopvar = 1 To 70 '70 frames for launch
Line (x, y)-(x + xplus, y + yplus), vbBlack 'overpaint old line
xplus = xplus / 1.01 'weaken sideway-power
yplus = yplus + 3 'gravity effect
x = x + xplus 'change coordinates using forces
y = y + yplus
Line (x, y)-(x + xplus, y + yplus), vbYellow 'new line
'now a short break, change this is you h
' ave a slower system


For timeloop = 1 To 200000: Next timeloop
Next loopvar
size = Rnd * 2 'randomize a force for the complete explosion,
'to get smaller and larger explosions

'initialize all fragments, with a lot of
' randomizations


For loopvar = 1 To fragments


DoEvents
fragx(loopvar) = x
fragy(loopvar) = y
fragpower(loopvar) = 40 + (Rnd * 80) * size
fragangle(loopvar) = Rnd * (2 * pi)
fragcolorR(loopvar) = Rnd * 256
fragcolorG(loopvar) = Rnd * 256
fragcolorB(loopvar) = Rnd * 256
Next loopvar
'exploding part


For loopvar2 = 1 To 20 'the explosion exists of 20 frames


For loopvar = 1 To fragments 'go through all fragments


DoEvents 'make sure system remains accessible
prevx(loopvar) = fragx(loopvar) 'save old coordinates For connecting
prevy(loopvar) = fragy(loopvar) 'current point To previous point
'now calculate the new coordintes using
' the angle
fragx(loopvar) = fragx(loopvar) + _
Sin(fragangle(loopvar)) * fragpower(loopvar)
fragy(loopvar) = fragy(loopvar) - _
Cos(fragangle(loopvar)) * fragpower(loopvar)
'lower power for explosion effect
If fragpower(loopvar) > 15 Then _
fragpower(loopvar) = fragpower(loopvar) / 1.1
'now change the angle so the fragments f
' all down
'when the fragment is pointed down, angl
' e = pi
If fragangle(loopvar) > pi Then _
fragangle(loopvar) = fragangle(loopvar) - _
(fragangle(loopvar) - pi) / 10
If fragangle(loopvar) < pi Then _
fragangle(loopvar) = fragangle(loopvar) + _
(pi - fragangle(loopvar)) / 10

'lower Red, Green and Blue values, so th
' e colors get darker
fragcolorR(loopvar) = fragcolorR(loopvar) / 1.12
fragcolorG(loopvar) = fragcolorG(loopvar) / 1.12
fragcolorB(loopvar) = fragcolorB(loopvar) / 1.12



Form1.Line (fragx(loopvar), fragy(loopvar))- _
(prevx(loopvar), prevy(loopvar)), _
RGB(fragcolorR(loopvar), _
fragcolorG(loopvar), _
fragcolorB(loopvar))
Next loopvar
Next loopvar2
Loop
End Sub


Private Sub Form_Unload(Cancel As Integer)
'for some reason the program won't end w
' hen clicking the upper-right
'cross, but this fixes that
End
End Sub

thanhise
23-05-2009, 13:29
mình cũng đang cần code làm firework nhưng là code C++.Mong các pro hay mod giúp dùm hen