|
Post by Azan on May 13, 2005 15:53:57 GMT -5
Please post em (double posting is ok)
|
|
|
Post by Azan on May 13, 2005 15:54:28 GMT -5
Really simple, but im making it better. Graphics 400,400 HidePointer Global counter=0 SetBuffer BackBuffer() Type par ;the type ball Field x Field y Field Colorr,Colorg,Colorb Field dx#,dy# End Type While Not KeyHit(1) createpar() ; if the space bar is hit create b updatepars() ;increases each b why value and draws the circle Text 10,10,counter+" "+"Particles" Flip Cls Wend Function createpar() ;creates a new instance called b following the type ball b.par=New par b\x=MouseX() ;set b x and why values b\y=MouseY() b\dx#=Rnd(-2,2) b\dy#=Rnd(-1,2) b\Colorr=256 b\Colorg=0 b\Colorb=0 counter=counter+1 End Function Function updatepars() For b.par=Each par ;targets all b ;b\y=b\y+b\ds ;for each b it has its why value increased b\Colorr=b\Colorr-3 b\dy#=b\dy#+.1 Color b\Colorr,b\Colorg,b\Colorb b\x=b\x+b\dx# b\y=b\y+b\dy# Oval b\x,b\y,2,2 ;draws a circle at each b coordinates If b\Colorr<5 Then Delete b counter=counter-1 EndIf Next End Function
|
|
|
Post by Umbrafire on May 17, 2005 17:08:08 GMT -5
im having trouble with this program, at the edges, where the particles are supposed to disappear, they sometimes instead of turning black, turn bright red again. any idea how to fix this? Graphics 400,400 SetBuffer BackBuffer() SeedRnd MilliSecs() Type ball ;the type ball Field x#,y# ;ball coordinates Field ox#,oy# ;original coordinates Field dx#,dy# ;ball direction Field r,g,b ;ball color Field time ;ball timer Field size ;ball size End Type
Global x# = 200 Global y# = 200
HidePointer While Not KeyHit(1) createball() x# = MouseX() y# = MouseY() If MouseHit(1) Then ; if the mouse is clicked create b For I = 1 To 50 createball() Next EndIf updateballs() ;increases each b y value and draws the circle Flip Cls Wend End
Function createball() ;creates a new instance called b following the type ball b.ball = New ball b\x# = x ;set b x and y values b\y# = y b\ox# = x b\oy# = y b\dx# = Rand(-5,5) b\dy# = Rand(-5,5) b\r = 200 b\g = 0 b\b = 0 b\size = 20 End Function Function updateballs() For b.ball = Each ball ;targets all b b\x# = b\x# + b\dx# b\y# = b\y# + b\dy# b\r = b\r - Rand(1,20) Color b\r,b\g,b\b Oval b\x#,b\y#,b\size,b\size ;draws a circle at each b coordinates If b\r <= 0 Then Delete b Else If b\ox# = b\x# And b\oy# = b\y# Then Delete b EndIf Next End Function
|
|
|
Post by Azan on May 17, 2005 19:00:51 GMT -5
Change "If b\r <= 0 Then" to "If b\r <= 20 Then"
|
|
|
Post by Umbrafire on May 20, 2005 19:07:23 GMT -5
thanks, here is a much better version of that program, and it is commented so that all you learners out there can read it and understand it. enjoy! ;;;;;;;;;;;;;;;;;;;; ;;;;;;Graphics Setup ;;;;;;;;;;;;;;;;;;;;
Graphics 640,480,16,1 SetBuffer BackBuffer() SeedRnd MilliSecs() HidePointer MoveMouse 320,240
;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;Variables ;;;;;;;;;;;;;;;;;;;;
Const X_WIND = 0 Const Y_WIND = 0 Const BALL_SIZE = 100
Global x# = 200 Global y# = 200 Global red = 0 Global green = 0 Global blue = 0 Global number = 0
;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;Types ;;;;;;;;;;;;;;;;;;;;
Type ball Field x#,y# ;current coordinates Field ox#,oy# ;original coordinates Field dx#,dy# ;directional values Field r,g,b ;color values Field time ;MilliSecs() value when created Field size ;particle size End Type
;;;;;;;;;;;;;;;;;;;; ;;;;;;;;Main Program ;;;;;;;;;;;;;;;;;;;;
While Not KeyHit(1) ;as long as esc is not hit number = 0 createball() ;create a new particle
x# = MouseX() y# = MouseY() updateballs() ;update each particle Color 255,255,255 ;change color to white
Text 0,0,"Number of Particles -- " + number ;print number of particles on screen
Flip ;flip buffers ClsColor(red,green,blue);next time the screen is cleared, use these values as the background color Cls ;clear screen Wend ;end while loop
End ;end program
;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;Functions ;;;;;;;;;;;;;;;;;;;;
Function createball() ;creates a new particle b.ball = New ball b\x# = x# b\y# = y# b\ox# = x# b\oy# = y# b\dx# = Rand(-5,5) b\dy# = Rand(-5,5) b\r = 200 b\g = Rand(150,200) b\b = 0 b\size = BALL_SIZE b\time = MilliSecs() End Function
Function updateballs() ;updates coordinates,color,size, of each particle For b.ball = Each ball number = number + 1 ;count each particle b\x# = b\x# + b\dx# + X_WIND ;move each particle by x value and wind b\y# = b\y# + b\dy# + Y_WIND ;move each particle by y value and wind b\r = b\r - Rand(1,10) ;decrease each particle's red value by a random integer between 1 and 10 b\g = b\g - Rand(10,20) ;decrease each particle's green value by a random integer between 10 and 20
b\size = b\size - Rand(1,2) ;decrease each particle's size by a random integer between 1 and 2 If MouseDown(1) And b\g <= 235 Then ;if left mouse button is down, increase green value b\g = b\g + Rand(10,20) EndIf If MouseDown(2) And b\b <= 235 Then ;if right mouse button is down, increase blue value b\b = b\b + Rand(10,20) EndIf If b\g <= 0 Then b\g = 0 EndIf Color b\r,b\g,b\b Oval b\x#,b\y#,b\size,b\size ;draw particle at mouse coordinates and designated size If b\r <= 10 Or b\size = 0 Then ;if red value is less than 10 or has a size smaller than 0, delete it Delete b Else If b\ox# = b\x# And b\oy# = b\y# Then Delete b EndIf Next End Function
|
|