Fireflies
A swarm born anywhere in a flat box over the platform, swirling around its middle. The gradient starts and ends dark, so each one lights up and goes out.
local natiny = require("natiny")
natiny.backend.init(arg and arg[1] or natiny.backend.AUTO)
local win = natiny.window.create("Natiny - Fireflies", 960, 640)
natiny.window.set_scale_mode(win, natiny.window.SCALE_MODE_STRETCH)
local BG = natiny.color.from_hex("#0C121C")
local sprite = natiny.texture.create(natiny.resource.load("common/textures/particle.png"))
local platform = natiny.resource.load("common/models/platform.glb")
natiny.model.create(natiny.mesh.load(platform))
natiny.resource.destroy(platform)
-- Born anywhere in a flat box over the platform and drifting in every
-- direction, each one pulled gently towards the middle and carried around it.
local flies = natiny.particles.create(600)
natiny.particles.set_texture(flies, sprite)
natiny.particles.set_shape(flies, natiny.particles.SHAPE_BOX, 3.6, 0.9, 3.6)
natiny.particles.set_spread(flies, 360)
natiny.particles.set_rate(flies, 120)
natiny.particles.set_speed(flies, 0.05, 0.22)
natiny.particles.set_lifetime(flies, 3.0, 5.0)
natiny.particles.set_size(flies, 0.03, 0.07)
natiny.particles.set_radial(flies, -0.03, 0.2)
-- Nothing is ever switched on or off: the gradient starts and ends at an
-- alpha of zero, so every firefly lights up and goes out on its own.
natiny.particles.set_colors(flies, {
natiny.color.from_hex("#C8FF6000"),
natiny.color.from_hex("#E9FF9AFF"),
natiny.color.from_hex("#C8FF6000"),
})
natiny.particles.set_blend(flies, natiny.particles.BLEND_ADD)
natiny.entity.set_position(flies, natiny.entity.SPACE_WORLD, 0, 0.7, 0)
-- A meadow that has been busy for a while before anyone looked at it.
natiny.particles.simulate(flies, 5.0)
local pivot = natiny.pivot.create()
local camera = natiny.camera.create()
natiny.entity.set_parent(camera, pivot)
natiny.entity.set_position(camera, natiny.entity.SPACE_LOCAL, 0, 1.2, 3.0)
natiny.entity.look_at(camera, 0, 0.6, 0)
natiny.camera.set_fov(camera, 50.0)
natiny.camera.set_clip(camera, 0.1, 100.0)
natiny.backend.loop(function(dt)
natiny.entity.rotate(pivot, natiny.entity.SPACE_LOCAL, 0, 8.0 * dt, 0)
natiny.window.bind(win, function()
natiny.render.clear(BG)
natiny.camera.bind(camera, function()
natiny.render.tag("model")
natiny.render.tag("particles")
end)
end)
end)
natiny.backend.shutdown()