Log In  

Cart #29890 | 2016-10-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

Particle theory, the ability of creating particles in a programing language and then deleting them from a list, is a pretty new concept for me.

http://natureofcode.com/book/chapter-4-particle-systems/

I'm more apt to creating an array of a fixed size of elements I need and then using zero (0) for X or something to flag particles that do not appear.

However, PICO does support LISTS, which enables you to create all kinds of data constructs and store them literally like trays at a cafeteria.

Adding an item to the list is easy. Instead of keeping track of the last place where you inserted an item, just use the ADD() command with your parameters and sub-class variable definitions.

When you are done with it, instead of changing one of the numbers to zero, you can literally DELETE the whole sub-class set and it and your list is that much shorter and faster to run.

You can do this by using the DEL() command.

To keep track of them all, you use the function "IN ALL()" I.E.: FOR I IN ALL(BIT)

Try running the code above. Press (Z) to launch a particle into the air and watch as gravity takes hold of it.

Now look over the source code (it's only 32-lines long) and see how these three concepts of IN ALL(), ADD(), and DEL(), are made use of.

Thanks to Tyroney for showing me this concept earlier.

P#29892 2016-10-03 15:45 ( Edited 2016-10-03 20:18)

:: dw817
2

Made a few changes in the code. Now when the firework hits its zenith, it releases an additional 16 other fireworks around it.

A single flag is used to tell that THESE new fireworks are all duds, and do not further explode into an additional 16, or as you could see, the program would hang rather quickly with each new firework igniting over and over again.

What are the results of one firework spawning 16 more ? Run and see ! :)

Cart #29897 | 2016-10-03 | Code ▽ | Embed ▽ | No License
2

P#29896 2016-10-03 16:18 ( Edited 2016-10-03 20:33)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-05-31 04:57 | 0.018s | 4194k | Q:32