summaryrefslogtreecommitdiff
path: root/demo/vector/main.lua
blob: fda4bc8605af36f0d9f82d50c2f540634f37d83b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'common'

local window = honey.window
local nvg = honey.nvg


local vg

function honey.init()
	vg = nvg.CreateContext()
end


local time = 0
local frames = 0
function honey.update(dt)
	if window.getKey(window.win, window.KEY_ESCAPE) == window.PRESS then
		window.setShouldClose(honey.window.win, true)
	end
	
	time = time + dt
	frames = frames + 1
	if time > 5 then
		print('fps:', frames/5)
		frames = 0
		time = time - 5
	end
end


function honey.draw()
	nvg.BeginFrame(vg, 640, 480, 1.0)
	nvg.StrokeWidth(vg, 20)
	nvg.StrokeColor(vg, nvg.RGB(1, 0, 0))

	local w = 640
	local h = 480

	nvg.BeginPath(vg)
	nvg.MoveTo(vg, w*0.2, h*.5)
	nvg.LineTo(vg, w*0.4, h * (0.5 + 0.5*math.sin(math.pi * time)));
	nvg.LineTo(vg, w*0.6, h * (0.5 - 0.5*math.sin(math.pi * time)));
	nvg.LineTo(vg, w*0.8, h*.5)
	nvg.Stroke(vg)

	nvg.EndFrame(vg)
end


honey.run()