shithub: lua9

ref: 1dded09f619d53f0b31d51870a9984aaf0152e02
dir: /sample.lua/

View raw version
#!/bin/ape/lua9

-- lua libdraw sample

function rect(x0, y0, x1, y1)
	return { min = { x = x0, y = y0 }, max = { x = x1, y = y1 } }
end

function pt(x, y)
	return { x = x, y = y }
end

local ZP = pt(0, 0)
local red = nil

function eresized()
	draw.draw(screen, screen.r, display.white, nil, ZP)
	draw.draw(screen, rect(50, 150, 100, 200), display.black, nil, ZP)
	draw.string(screen, pt(110, 160), display.black, nil, font, 'Hello LUA')
	draw.line(screen, pt(50, 210), pt(150, 210), draw.END_DISC, draw.END_ARROW, 1, display.black, ZP)
	draw.ellipse(screen, pt(300, 300), 200, 100, 2, display.black, ZP)
	draw.fillellipse(screen, pt(300, 300), 20, 50, red, ZP)
end

draw.init('lua sample')
event.init(event.MOUSE|event.KEYBOARD)
red = draw.allocimage(display, rect(0,0,1,1), screen.chan, 1, color.RED)
eresized()
while true do
	local e, ev = event.event()
	if e == event.MOUSE then
		--print 'Mouse event'
	elseif e == event.KEYBOARD then
		if key.eq(ev.kbdc, 'q') or ev.kbdc == key.DEL then
			os.exit()
		end
	end
end