Beginnings of a spray thingy... Now with fading colour!!
Author |
Message |
Lapsus Antepedis
![](http://img.photobucket.com/albums/v315/Lapsus/DreamAvatarforums.png)
|
Posted: Tue Oct 25, 2005 1:41 pm Post subject: Beginnings of a spray thingy... Now with fading colour!! |
|
|
I got bored again, and this came out during my spare time in french class... I'm posting it so I can get it home and try to make it into a module or something so I can have more than one running at once...
Anyway, here's my code. Let me know if you have any thoughts about it...
(I also plan to add inter-particle and object collision...)
Edit 1: Added code so origin of particles follows mouse and syntax tags...
Edit 1.5: Switched bace to code tags... (syntax does not mean size 24!!)
Edit 2: Decreased delay for smoother simulation
Edit 3: Added colour fading to indicate life of particles
code: | type thingy : % I couldn't think of a better name...
record
x, y, clr, siz, life : int
xs, ys : real
end record
var window : int := Window.Open ("graphics:max;max, offscreenonly") %open a psudeo-fullscreen window
const grav : real := -0.1 %Force pulling the particles in the y direction...
const damp : real := 0.005 %Force pulling velocities toward zero
const minlife : int := 100 %Minimum lifespan of particles
const maxlife : int := 300 %Maximum lifespan of particles
const numball : int := 300 %Number of particles
const size : int := 5 %Size of particles
const del : int := 10 %Delay in main loop
const bounce : real := .99 %Percent of velocity kept on bounce
var ox : int := 100 %x origin of particles
var oy : int := 100 %y origin of particles
var blah : int
var ball : array 1 .. numball of thingy %Array full of particles
loop
if maxcolour < numball + 1 then
blah := RGB.AddColour (0, 0, 0)
else
exit
end if
end loop
proc reset (n, x, y : int) %Procedure to reset specific particle to a place on screen after death
ball (n).x := x
ball (n).y := y
ball (n).clr := n
ball (n).siz := size
ball (n).life := Rand.Int (minlife, maxlife) % Random lifespan
ball (n).xs := Rand.Int (1000, 6000) / 1000 %My randreal thing...
ball (n).ys := Rand.Int (1000, 6000) / 1000 %Same as above
end reset
proc colourball (i : int)
RGB.SetColour (ball (i).clr, ball (i).life / maxlife, ball (i).life / maxlife, ball (i).life / maxlife)
end colourball
proc draw % Procedure to draw particles
for i : 1 .. numball
colourball (i)
drawfilloval (ball (i).x, ball (i).y, ball (i).siz, ball (i).siz, ball (i).clr)
end for
end draw
proc main % Main procedure
for i : 1 .. numball
ball (i).x += round (ball (i).xs) %Move particles
ball (i).y += round (ball (i).ys)
ball (i).ys += grav %Gravity
if ball (i).xs > 0 then %x damping
ball (i).xs -= damp
elsif ball (i).xs < 0 then
ball (i).xs += damp
end if
if ball (i).xs > 0 then %y damping
ball (i).xs -= damp
elsif ball (i).xs < 0 then
ball (i).xs += damp
end if
if ball (i).y < 0 then %Bounce off top and bottom of screen
ball (i).ys *= -bounce
ball (i).y := 0
elsif ball (i).y > maxy then
ball (i).ys *= -bounce
ball (i).y := maxy
end if
if ball (i).x > maxx or ball (i).x < 0 or ball (i).life <= 0 then %Reset if offscreen or life over
reset (i, ox, oy)
end if
ball (i).life -= 1 %Life shortened
end for
end main
for i : 1 .. numball %Inital placement of particles
reset (i, ox, oy)
end for
colourback (numball + 1)
loop %Main loop
Mouse.Where (ox, oy, blah)
draw
View.Update
main
delay (del)
cls
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
beard0
![](http://ugray.be/compsci/silly.gif)
|
Posted: Tue Oct 25, 2005 3:47 pm Post subject: (No subject) |
|
|
I haven't really looked at the code behind it in depth, but It looks like a decent simulation ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Jekate
|
Posted: Tue Oct 25, 2005 4:25 pm Post subject: (No subject) |
|
|
That's awsome man! I don't really know what to say on the code either cause I'm relearning turing. I knew it long ago but never really kept up with it, but as far as I can tell it looks good. |
|
|
|
|
![](images/spacer.gif) |
Lapsus Antepedis
![](http://img.photobucket.com/albums/v315/Lapsus/DreamAvatarforums.png)
|
Posted: Wed Oct 26, 2005 8:42 am Post subject: (No subject) |
|
|
Lapsus Antepedis wrote: Edit 1: Added code so origin of particles follows mouse and syntax tags...
Edit 1.5: Switched bace to code tags... (syntax does not mean size 24!!)
Edit 2: Decreased delay for smoother simulation
Edit 3: Added colour fading to indicate life of particles
I made some changes to my program, I think it looks better with the colours fading to black to indicate remaining lifespan... |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Wed Oct 26, 2005 8:56 am Post subject: (No subject) |
|
|
Yeah, I think it looks better this way too - completely blank . I suggest double checking your code. |
|
|
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
Posted: Wed Oct 26, 2005 12:36 pm Post subject: (No subject) |
|
|
That's one of the coolest, er... thingies I've seen in Turing in a while. |
|
|
|
|
![](images/spacer.gif) |
ZeroPaladn
|
Posted: Fri Oct 28, 2005 8:50 am Post subject: (No subject) |
|
|
i wouldnt know, all i see is a white screen. maybe i ahve to wait for it, i exited the program after about 10 secs of whiteness.... |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Fri Oct 28, 2005 5:32 pm Post subject: (No subject) |
|
|
No, that is what my post meant.
This very strange loop doesn't exit..
code: | loop
if maxcolour < numball + 1 then
blah := RGB.AddColour (0, 0, 0)
else
exit
end if
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|