Code: Alles auswählen
InitSprite()
#b = 0.01745329
Procedure.f Abstand(x1, y1, x2, y2)
r.f = Sqr(Pow(x1-x2,2)+Pow(y1-y2,2))
ProcedureReturn r
EndProcedure
Procedure.f Diagonale(x.f,y.f)
r.f = Sqr(x*x+y*y)
ProcedureReturn r
EndProcedure
Procedure.f Winkel(x.f,y.f)
Winkel.f
If x = 0
If y < 0 : Winkel = -90 : EndIf
If y >= 0 : Winkel = 90 : EndIf
Else
Winkel = ATan(y/x)/#b
If x < 0 : Winkel + 180 : EndIf
EndIf
If Winkel < 0 : Winkel + 360 : EndIf
ProcedureReturn Winkel
EndProcedure
Structure P
Farbe.l ; Farbe
l.l ; Teilchenlänge
x.f ; x-Position
y.f ; y-Position
dx.f ; Flugrichtung (in X)
dy.f ; Flugrichtung (in Y)
rw.l ; Eigenrotationswinkel
rdw.l ; Eigenrotationswinkeländerung
EndStructure
Global NewList P.P() ; Partikelliste
; Fügt ein Partikel hinzu mit (Farbe, Posion(x,y), Flugrichtung, Geschwindigkeit, Rotationsgeschwindigkeit)
Procedure AddParticle(Farbe, l, x, y, w.f, v.f, rdw.f)
AddElement(P())
P()\Farbe = Farbe
P()\l = l
P()\x = x
P()\y = y
P()\dx = Cos(w*#b)*v
P()\dy = Sin(w*#b)*v
P()\rw = w
P()\rdw = rdw
EndProcedure
Procedure AddExplosion(Farbe, l, x.f, y.f, Dichte.f, v.f, rdw.f)
nn = 360*Dichte
For n = 1 To nn
AddParticle(Farbe, l, x, y, n/Dichte, Random(v*100)/100+v/2, rdw)
Next n
EndProcedure
#Gravitation = 0.01 ; bei 0 keine
OpenWindow(1, 300, 0, 600, 600, "2D-Drawing",#PB_Window_MinimizeGadget )
OpenWindowedScreen(WindowID(1), 0, 0, 600, 600, 0, 0, 0)
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
ClearScreen(0)
StartDrawing(ScreenOutput())
ResetList(P())
While NextElement(P())
; Gravitation
P()\dy + #Gravitation
; Bewegung
P()\x + P()\dx
P()\y + P()\dy
; Eigenrotation
P()\rw + P()\rdw
;Anzeige
Winkel = Winkel(P()\dx,P()\dy)+P()\rw
x2 = Cos(Winkel*#b)*P()\l
y2 = Sin(Winkel*#b)*P()\l
Line(P()\x, P()\y, x2, y2, P()\Farbe)
; Deletakontrolle
If P()\y > 620 : DeleteElement(P()) : EndIf
Wend
StopDrawing()
FlipBuffers()
WMx = WindowMouseX(1)
WMy = WindowMouseY(1)
If GetAsyncKeyState_(#VK_LBUTTON) <> 0
Druck = 1
ElseIf Druck = 1
Druck = 0
Rot = Random(127)+128
Gruen = Random(127)+128
Blau = Random(127)+128
Laenge = Random(10)+5 ; Wie groß soll eines Teilchens durchschnittlich sein
Dichte.f = (Random(15)+5)/10 ; Wie viele Teilchen soll es pro 1° geben
v.f = (Random(20)+5)/10 ; wie schnell sollen die Teilchen Durchschnittlich fliegen
rdw.f = Random(4) ; wie schnell soll die Eigenrotation der Teilchen sein
AddExplosion(RGB(Rot,Gruen,Blau), Laenge, WMx, WMy, Dichte, v, rdw)
EndIf
ForEver