This project integrates Pixi.js v8 as a rendering backend with Lua as a scripting language. It allows you to write Lua code that controls graphics rendered by Pixi.js.
Try out the live demo at https://mikedx.github.io/flua-web
- Real-time Lua script editing and execution
- Pixi.js v8 rendering engine
- Built-in functions for drawing shapes and manipulating sprites
- Frame-based animation system
- Example scripts demonstrating various features
- Node.js (v14 or later recommended)
- npm (comes with Node.js)
- Clone this repository
- Install dependencies:
npm install
- Start the development server:
npm start
- Open your browser and navigate to
http://localhost:9000
To build the project for production:
npm run build:prod
The built files will be in the dist
directory.
The application is split into two main areas:
- The left side shows the Pixi.js canvas where your graphics will be rendered
- The right side contains a Lua code editor where you can write and run scripts
The following functions are available in the Lua environment:
circle(x, y, radius, vertices, color, outline)
: Draw a circlecolor
: Table with {r, g, b, a} values (0-1) or hex valueoutline
: 0 for filled, 1 for outline
box(x, y, width, height, color, outline)
: Draw a rectangledrawLine(x1, y1, x2, y2, color, thickness)
: Draw a linesetBackgroundColor(color)
: Set the background colorclear()
: Clear all graphicsupdate()
: Update the display (yields to next frame)
gWidth()
: Get canvas widthgHeight()
: Get canvas heightgetFPS()
: Get current FPSprintAt(x, y, text)
: Draw text at positionrnd(max)
: Get random number from 0 to max-1
loadImage(path)
: Load an image texturecreateSprite()
: Create a new spritesetSpriteImage(sprite, texture)
: Set sprite texturesetSpritePosition(sprite, x, y)
: Set sprite positionsetSpriteColor(sprite, r, g, b, a)
: Set sprite color/tintsetSpriteSpeed(sprite, {x, y})
: Set sprite movement speedupdateSprites()
: Update all spritesdrawSprites()
: Draw all sprites
-- Initialize particle system
local particles = {}
local emitterX = gWidth() / 2
local emitterY = gHeight() / 2
local totalTime = 0
local dt = 0.016 -- Fixed time step
while true do
clear()
totalTime = totalTime + dt
-- Update and spawn particles
-- Move emitter in a circle
emitterX = gWidth() / 2 + math.cos(totalTime * 2) * 100
emitterY = gHeight() / 2 + math.sin(totalTime * 2) * 100
-- Display stats
printAt(10, 10, "FPS: " .. getFPS())
update()
end
bunny = loadImage("assets/wabbit_alpha.png")
while true do
clear()
t = touch()
if t[0].z then
-- Spawn bunnies on click
createSprite()
setSpriteImage(newbunny, bunny)
end
updateSprites()
drawSprites()
update()
end
- Uses frame-based timing for consistent animation
- Supports both filled and outlined shapes
- Color values can be specified as RGB tables or hex values
- Sprites support automatic screen edge collision
This project is licensed under the ISC License - see the LICENSE file for details.