Skip to content
Ingo Ruhnke edited this page Mar 22, 2015 · 5 revisions

TODO: create some more examples such as explosins, water and stuff like that.

Particle systems, as currently implemented in Windstille, consists of two main sub parts, a drawer object and a distribution object. The drawer gets the particles position and parameter and draws it, while the distribution is used to spawn the particles. Distributions are geometric shapes like lines, rectangles or circles.

Drawer

The job of the drawer object is to render the particles, it gets the position, lifetime ond other parameter of the particle and can then decide how to render it with that information. New Drawer objects can be added with relative ease.

surface-drawer

Draws a image at the position of each particle.

(image //string//)

(blendfunc-src //string//)

(blendfunc-dst //string//)

spark-drawer

Draws a line from the current particle position to the position the particle had a frame earlier.

(color //r// //g// //b// //a//)

Distribution

In source code Distribution is currently called Randomizer, this needs to be cleaned up.

The Distribution object decides at which position the next Particle should be spawned. In most cases the distribution object defines a geometric shape in which new Particles get created.

rect-distribution

line-distribution

ciricle-distribution

point-distribution

Variables

(drawer //drawer-declaration//)

drawer that draws the particle

(distribution //distribution-declaration//)

description of a distribution object from which particles spawn

(count //count//)

number of particles that can be on the screen at once

(pos //x// //y//)

position of the particle system

(z-pos //pos//)

z position, used for drawing order

(layer //layer-name//)

layer name to which the particles get drawn, can be:

  • "highlight"
  • "light"
  • "color"

(cone //start-angle// //end-angle//)

direction into which particles are emitted

(velocity //min// //max//)

speed of the emitted particles

Example

;; -*- scheme -*-

(particle-systems
 ;; Fire sparks
 (particle-system
  (drawer (spark-drawer (color 1.0 0.5 0.5)))
  (z-pos 900)
  (pos 0 32)
  (layer "highlight")
  (velocity 400 650)
  (cone -115 -65)
  (gravity 0  1)
  (distribution (line-distribution (x1 -50)  (y1 0) (x2 50) (y2 0))))

 ;; Fire smoke
 (particle-system
  (pos 0 32)
  (lifetime 8)
  (count 30)
  (z-pos -200)
  (drawer (surface-drawer (image "images/particles/smoke2.png")
                          (blendfunc-src "src_alpha")
                          (blendfunc-dst "one_minus_src_alpha")))
  (velocity 10 20)
  (cone -115 -65)
  (gravity 0 -0.05)
  (size 1.0 3.0)
  (distribution (line-distribution (x1 -50) (y1 0) (x2 50) (y2 0))))


 ;; Fire itself
 (particle-system
  (pos 0 0)
  (count 75)
  (z-pos 1000)
  (layer "highlight")
  (velocity 200 300)
  (cone -95 -85)
  (gravity 0 -0.05)
  (size 1.5 1.0)
  (distribution (line-distribution (x1 -50) (y1 0) (x2 50) (y2 0)))
  (drawer (surface-drawer (image "images/particles/smoke.png")
                          (blendfunc-src "src_alpha")
                          (blendfunc-dst "one"))))
)

;; EOF ;;

And here an older version of the example code in action:

[https://www.youtube.com/watch?v=q-9miRwcLwk]

Other Particle Engines

Clone this wiki locally