Computer Science Canada [source] - PARTICLE SPRAY by IKER |
Author: | iker [ Sun Feb 12, 2006 8:54 pm ] | ||
Post subject: | [source] - PARTICLE SPRAY by IKER | ||
here is a little particle system that I put together, thought I might share the source with everyone here. Its actualy quite fun to watch, especialy when you screw around with the constants. The bursts dicipate after a while, and the particles spray at a constant rate, which is better. Anyways, have fun and edit at will
|
Author: | Cervantes [ Sun Feb 12, 2006 10:01 pm ] | ||||
Post subject: | |||||
Why do the particles lose their horizontal velocity so abruptly?
Why? I think you'll find the following to make a lot more sense:
The next step up from this is to make each particle an object. |
Author: | iker [ Mon Feb 13, 2006 4:24 pm ] | ||
Post subject: | |||
try using
for the constants, and as for making them into objects, I don't know if I want to seeing as how this isn't realy a project... but I might. |
Author: | Cervantes [ Mon Feb 13, 2006 5:42 pm ] |
Post subject: | |
iker wrote: and as for making them into objects, I don't know if I want to seeing as how this isn't realy a project... but I might.
Why do you think it best to learn the concepts you need while doing a project (worth marks)? It's far better to learn the concepts ahead of time, so applying them is easy. This extends to learning the concepts out of class, before the lessons, so that the lessons are easier. This extends to all subjects, not just computer science. |
Author: | iker [ Mon Feb 13, 2006 6:15 pm ] | ||
Post subject: | |||
Cervantes wrote: iker wrote: and as for making them into objects, I don't know if I want to seeing as how this isn't realy a project... but I might.
Why do you think it best to learn the concepts you need while doing a project (worth marks)? It's far better to learn the concepts ahead of time, so applying them is easy. This extends to learning the concepts out of class, before the lessons, so that the lessons are easier. This extends to all subjects, not just computer science. I'm not actualy in a computer science class, I haven't been for the last year or so... all programming that I've done has been done for my own purposes. I'm basically done with turing, moving onto Java and/or Ruby, which use classes and objects as one of my friends was telling me, so I'm learning them anyways. Didn't say that I didn't want to learn classes, just meant that I didn't want to apply them to this program. modded my own code for randomn colored particles
|
Author: | Martin [ Mon Feb 13, 2006 8:30 pm ] | ||
Post subject: | |||
Now what we've done is created a particle with life and rgb colour values. From here, what you can now do is use some basic alpha blending to make the particle's colour slowly fade into whatever the background colour is. For example, supposing that a particle was given the initial RGB colours (1.0,0.8,0.5), the background colour was (0.0,0.0,0.0) (black), then you could determine the current colour by the following formula: CurrentColor = life * initialColour + (1 - life) * backgroundColour or simply new_r = life * particle._r + (1 - life)* background._r new_g = life * particle._g + (1 - life)* background._g new_b = life * particle._b + (1 - life)* background._b (I don't remember how to use colour codes in Turing, sorry). Then, you'll want to do the following: 1. Create an array of particles. 2. Initialize each particle to some default values, with _life = 0 main loop 3. When the event occurs (ie. mouse is down), start setting particles which are not alive (_life <= 0) to have life 1.0 4. Draw all particles that have life > 0. Draw the particle using the formula given above. Don't change the values of _r, _g, _b within your particle, however. 5. For each particle, subtract fade from its life. myParticle._life -= myParticle._fade End main loop This'll make it so that particles die out after you stop clicking, but don't disappear immediately (I haven't run your code, I don't have turing). And you will have on your hands a very fancy particle engine. EDIT: updated it a bit |
Author: | Cervantes [ Mon Feb 13, 2006 9:31 pm ] | ||||
Post subject: | |||||
iker wrote: I'm not actualy in a computer science class, I haven't been for the last year or so... all programming that I've done has been done for my own purposes. I'm basically done with turing, moving onto Java and/or Ruby, which use classes and objects as one of my friends was telling me, so I'm learning them anyways. Didn't say that I didn't want to learn classes, just meant that I didn't want to apply them to this program. I'm glad to see Ruby in there. When you move your next language, you will be surrounded by (varying degrees of) unfamiliar syntax. Knowing the major concepts that a language employs (OOP, in this case) will ease that transition. Turing can provide a good introduction to OOP. Of course, even if you master Turing's OOP, there are still things to learn that you will be confronted with when moving to Java or Ruby (or other languages). For example, in Ruby, you will learn that everything is an object, unlike in Turing where very few things are objects (only the things you write classes for). Learning OOP in Turing will get the some of the main concepts under your belt, so you have less to worry about when you move on to your next language. Iker wrote:
How about,
Functions should be used in place of procedures, wherever possible. It makes far more sense to assign a variable to the value returned by a function than to allow a procedure full written control over the variable you pass to it. |
Author: | iker [ Tue Feb 14, 2006 4:52 pm ] | ||||
Post subject: | |||||
Thanks for all of the tips, but actualy, after i posted that last message, I decided to make it into a class and everything, and it uses alot of what you guys said, even though I didn't read it before I did it... anyways, heres the class, might be usefull for a game with headshots...
And heres a "program" to call that class
|
Author: | [Gandalf] [ Tue Feb 14, 2006 5:06 pm ] |
Post subject: | |
That's a module not a class. While the two may look similar, they really involve completely unique concepts. In a class everything revolves around objects, while a module is basically just a 'shell' for your code. A module is no doubt useful, but in this case a class would be much better suited since each particle can act as an 'object'. |
Author: | iker [ Tue Feb 14, 2006 5:09 pm ] |
Post subject: | |
[Gandalf] wrote: That's a module not a class. While the two may look similar, they really involve completely unique concepts.
In a class everything revolves around objects, while a module is basically just a 'shell' for your code. A module is no doubt useful, but in this case a class would be much better suited since each particle can act as an 'object'. I guess I did say class... but I meant module... sry for the mixup, I was just reading about someone saying for me to make it into a class, guess I was thinking module and put class... no worrys |
Author: | Cervantes [ Tue Feb 14, 2006 6:32 pm ] | ||||
Post subject: | |||||
iker wrote: no worrys
But, but! You still don't have particle objects. And, why did you make the module pervasive? What happens if you don't make it pervasive, and import it normally? ie.
Be sure to have the module saved as "Particle.tu". If it's not, you'll have to do something like
|