log.console("test_particles starting") var time = use('time') var random = use('random').random var core = use('core') var particles2d = use('particles2d') var text2d = use('text2d') var compositor = use('compositor') var film2d = use('film2d') var math = use('math/radians') var particle_handles = [] var emitters = [] var labels = [] var t = 0 var camera = { pos: {x: 250, y: 250}, width: 500, height: 500, anchor: {x: 0.5, y: 0.5} } var compositor_config = { clear: {r: 0.05, g: 0.05, b: 0.1, a: 1}, planes: [ { name: 'main', plane: 'main', camera: camera, resolution: {width: 500, height: 500}, presentation: 'stretch', clear: {r: 0.05, g: 0.05, b: 0.1, a: 1} } ] } function init() { // Emitter 1: Normal particles (top-left) var handle1 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 20, height: 20 }) particle_handles[] = handle1 emitters[] = particles2d.emitters.create({ pos: {x: 100, y: 400}, spawn_area: {width: 30, height: 10}, velocity: {x: 0, y: 50}, velocity_var: {x: 20, y: 10}, life: 2, rate: 15, scale: 1, scale_var: 0.2, color: {r: 1, g: 0.8, b: 0.3}, handle: handle1 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Normal", pos: {x: 70, y: 480}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 1, a: 1} }) // Emitter 2: Half opacity (top-center) var handle2 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 20, height: 20, opacity: 0.5 }) particle_handles[] = handle2 emitters[] = particles2d.emitters.create({ pos: {x: 250, y: 400}, spawn_area: {width: 30, height: 10}, velocity: {x: 0, y: 50}, velocity_var: {x: 20, y: 10}, life: 2, rate: 15, scale: 1, scale_var: 0.2, color: {r: 1, g: 0.8, b: 0.3}, handle: handle2 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Opacity 0.5", pos: {x: 210, y: 480}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 1, a: 1} }) // Emitter 3: Red tint (top-right) var handle3 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 20, height: 20, tint: {r: 1, g: 0.2, b: 0.2, a: 1} }) particle_handles[] = handle3 emitters[] = particles2d.emitters.create({ pos: {x: 400, y: 400}, spawn_area: {width: 30, height: 10}, velocity: {x: 0, y: 50}, velocity_var: {x: 20, y: 10}, life: 2, rate: 15, scale: 1, scale_var: 0.2, color: {r: 1, g: 0.8, b: 0.3}, handle: handle3 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Red Tint", pos: {x: 370, y: 480}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 1, a: 1} }) // Emitter 4: Blue tint (bottom-left) var handle4 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 24, height: 24, tint: {r: 0.3, g: 0.5, b: 1, a: 1} }) particle_handles[] = handle4 emitters[] = particles2d.emitters.create({ pos: {x: 100, y: 200}, spawn_area: {width: 40, height: 10}, velocity: {x: 0, y: 60}, velocity_var: {x: 30, y: 15}, life: 2.5, rate: 20, scale: 1.2, scale_var: 0.3, color: {r: 1, g: 1, b: 1}, handle: handle4 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Blue Tint", pos: {x: 70, y: 280}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 1, a: 1} }) // Emitter 5: Green tint + opacity (bottom-center) var handle5 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 24, height: 24, tint: {r: 0.3, g: 1, b: 0.3, a: 1}, opacity: 0.7 }) particle_handles[] = handle5 emitters[] = particles2d.emitters.create({ pos: {x: 250, y: 200}, spawn_area: {width: 40, height: 10}, velocity: {x: 0, y: 60}, velocity_var: {x: 30, y: 15}, life: 2.5, rate: 20, scale: 1.2, scale_var: 0.3, color: {r: 1, g: 1, b: 1}, handle: handle5 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Green + 70%", pos: {x: 210, y: 280}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 1, a: 1} }) // Emitter 6: Animated tint (bottom-right) var handle6 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 24, height: 24, tint: {r: 1, g: 1, b: 1, a: 1} }) particle_handles[] = handle6 emitters[] = particles2d.emitters.create({ pos: {x: 400, y: 200}, spawn_area: {width: 40, height: 10}, velocity: {x: 0, y: 60}, velocity_var: {x: 30, y: 15}, life: 2.5, rate: 20, scale: 1.2, scale_var: 0.3, color: {r: 1, g: 1, b: 1}, handle: handle6 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Rainbow", pos: {x: 370, y: 280}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 1, a: 1} }) // Emitter 7: Animated opacity (center) var handle7 = particles2d.create({ plane: 'main', layer: 0, image: 'examples/tiles/fireball', width: 32, height: 32, opacity: 1 }) particle_handles[] = handle7 emitters[] = particles2d.emitters.create({ pos: {x: 250, y: 80}, spawn_area: {width: 60, height: 20}, velocity: {x: 0, y: 40}, velocity_var: {x: 40, y: 20}, life: 3, rate: 25, scale: 1.5, scale_var: 0.4, color: {r: 1, g: 0.6, b: 0.2}, handle: handle7 }) labels[] = text2d({ plane: 'main', layer: 10, text: "Pulsing Opacity", pos: {x: 180, y: 20}, font: 'examples/fonts/dos', size: 14, color: {r: 1, g: 1, b: 0, a: 1} }) log.console("test_particles initialized with " + text(length(emitters)) + " emitters") } function update(dt) { t += dt // Update all emitters var i = 0 for (i = 0; i < length(emitters); i++) { particles2d.emitters.update(emitters[i], dt) } // Animate rainbow tint on emitter 6 var rainbow_handle = particle_handles[5] rainbow_handle.tint.r = 0.5 + 0.5 * math.sine(t * 2) rainbow_handle.tint.g = 0.5 + 0.5 * math.sine(t * 2 + 2.094) rainbow_handle.tint.b = 0.5 + 0.5 * math.sine(t * 2 + 4.188) // Animate pulsing opacity on emitter 7 var pulsing_handle = particle_handles[6] pulsing_handle.opacity = 0.3 + 0.7 * abs(math.sine(t * 1.5)) } function render() { var plan = compositor.compile(compositor_config) return compositor.execute(plan) } init() core.start({ width: 500, height: 500, title: "Test Particles Features", framerate: 60, update: update, render: render })