Skip to content

Instantly share code, notes, and snippets.

@pkulchenko
Created April 1, 2012 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkulchenko/2278953 to your computer and use it in GitHub Desktop.
Save pkulchenko/2278953 to your computer and use it in GitHub Desktop.
A test for running Lua in a browser (http://notebook.kulchenko.com/) #lua #browser #javascript
function initCanvas(w, h)
local canvas = document:createElement("canvas")
canvas.id = "canvas"
canvas.width = w
canvas.height = h
canvas.style.width = canvas.width .. 'px'
canvas.style.height = canvas.height .. 'px'
document:getElementsByTagName('body')[0]:appendChild(canvas)
end
initCanvas(300, 300)
local canvas = document:getElementById("canvas")
local ctx = canvas:getContext("2d")
ctx.fillStyle = "rgb(200,0,0)"
ctx:fillRect(130, 130, 50, 50)
ctx.fillStyle = "rgba(0, 0, 200, 0.1)"
for i = 1, 100 do
ctx:fillRect(math.random(0, 300), math.random(0, 300), 50, 50)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment