-- constants
local SIZE = 320
local ITERATIONS = 4
local VORTICITY = 7
local SOURCE = 'Source.png'
local OFFSET = Vector2.new(SIZE) / 2

-- load an image to be the fire source
local source = Bitmap.new(SOURCE)
source:resize(settings.scale, settings.scale)

-- initialize fire simulation system
local fire = FluidSystem.new(SIZE, SIZE, 2)
fire.fuel = settings.fuel
fire.speed = settings.speed
fire.fade = settings.fade
fire.iterations = ITERATIONS
fire.vorticity = VORTICITY
fire:setDensityMap(source, Vector2.new(0))

-- create mesh to define the shape (a box)
local mesh = Mesh2D.box(SIZE, SIZE)

-- create texture to which we will draw to
local texture = Texture.new(SIZE, SIZE)
mesh.material.texture = texture

-- create cursor node to represent the mesh in the scene
local cursor = Node2D.new()
cursor:addMesh( mesh )
cursor:spawn()

-- events
function step(deltaTime)
    -- step the fire simulation
    fire:step(deltaTime)

    -- render current fire simulation density map to texture
    fire:renderDensityMap(texture, settings.color)

    -- update cursor position based on mouse position
    cursor.position = ym.getCursorPosition() + OFFSET
end
