New Approach to particle engine.
Author |
Message |
templest
|
Posted: Mon Aug 23, 2004 12:02 am Post subject: New Approach to particle engine. |
|
|
The last one I made has really huge code (think, ~400 lines), and only drew up to 11 dots on the screen at any given time (if I recall correctly).
Having learn't much more since then, I decided to redraw another one, using more practicle means. But with practicality, I lose a lot of what I had before. The other one was pretty much constant, and fixing any detail about it, required a rework of the whole code, very inconvenient. But it was extreamly fast, the new code isn't.
This is condensed to 21 lines of code, but here's what wrong.
My problem is that the dots won't start redrawing until the last dot is off the screen (to make sure that the screen is cleared for when the loop starts again), but this leaves me with a big blank trail following the last dot, and the screen stays clear for a couple of seconds while the randomizer does it's thing. I want it to be continuous, do you know what i mean? As well, I need to reduce the calculations some how (and get rid of those fors in the loops, or maybe condense it into one for statement?), this takes up too many resources.
Another thing, about the dots not starting from the top until the last dot is cleared, I think I could set two loops (like the same one running now), and set them to interchange with eachother, right when one finishes, the other one starts, ect. But I feel that would just add to the slowness.
Any input?
EDIT: How could I forget what's most important? The c0de!
code: |
View.Set ("graphics:300;200;title:temp's engine,nobuttonbar;offscreenonly")
var dotsX : array 1 .. 60 of int
var dotsY : array 1 .. 60 of int
loop
for r : 1 .. 60
dotsX (r) := Rand.Int (1, 300)
dotsY (r) := Rand.Int (305, 600)
end for
loop
exit when dotsY (1) = -300
for g : 1 .. 60
Draw.Dot (dotsX (g), dotsY (g), black)
Draw.Dot (dotsX (g), dotsY (g) + 1, white)
View.Update
end for
for w : 1 .. 60
dotsY (w) := dotsY (w) - 1
end for
end loop
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Genesis
|
Posted: Mon Aug 23, 2004 1:58 am Post subject: (No subject) |
|
|
I changed the background colour so you can see it a bit better.
code: | View.Set ("graphics:300;200;title:temp's engine,nobuttonbar")
colourback (black)
cls
var dotsX : array 1 .. 60 of int
var dotsY : array 1 .. 60 of int
for i : 1 .. 60
dotsX (i) := Rand.Int (1, 300)
dotsY (i) := Rand.Int (305, 600)
end for
loop
loop
for g : 1 .. 60
Draw.Dot (dotsX (g), dotsY (g), white)
Draw.Dot (dotsX (g), dotsY (g) + 1, black)
end for
for w : 1 .. 60
dotsY (w) := dotsY (w) - 1
if dotsY (w) <= 0 then
dotsX (w) := Rand.Int (1, 300)
dotsY (w) := Rand.Int (305, 600)
end if
end for
end loop
end loop
|
In this one I added in a clear screen, you loose a few particles, but it's much more efficient:
code: | View.Set ("graphics:300;200;title:temp's engine,nobuttonbar")
colourback (black)
cls
var dotsX : array 1 .. 60 of int
var dotsY : array 1 .. 60 of int
for i : 1 .. 60
dotsX (i) := Rand.Int (1, 300)
dotsY (i) := Rand.Int (305, 600)
end for
loop
loop
for g : 1 .. 60
Draw.Dot (dotsX (g), dotsY (g), white)
Draw.Dot (dotsX (g), dotsY (g) + 1, black)
end for
for w : 1 .. 60
dotsY (w) := dotsY (w) - 1
if dotsY (w) <= 0 then
dotsX (w) := Rand.Int (1, 300)
dotsY (w) := Rand.Int (305, 600)
cls
end if
end for
end loop
end loop |
|
|
|
|
|
|
Genesis
|
Posted: Mon Aug 23, 2004 2:07 am Post subject: (No subject) |
|
|
Actually one of those loops isn't necessary. I don't feel like reposting the code, so just remove it. |
|
|
|
|
|
templest
|
|
|
|
|
Genesis
|
Posted: Tue Aug 24, 2004 12:52 am Post subject: (No subject) |
|
|
No problem.
Thanks for the bits. |
|
|
|
|
|
|
|