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
51
52
|
io.stdout:setvbuf("no")
local shader
local img
local img2
local canvas
local sw, sh = jin.graphics.getSize()
function jin.core.onLoad()
local str = jin.filesystem.read("metaball.shader")
shader = jin.graphics.newShader(str)
local w, h = 256, 240
local bitmap = jin.graphics.newBitmap(w, h, {255, 255, 0, 255})
local b = bitmap:clone()
bitmap = nil
-- local bitmap2 = jin.graphics.newBitmap("img2.bmp")
img = jin.graphics.newTexture(b)
-- img2 = jin.graphics.newTexture(bitmap2)
canvas = jin.graphics.newCanvas(200, 200)
end
-- extern vec3 iResolution;
-- extern number iGlobalTime;
-- extern vec4 iMouse;
local mx, my = 0, 0
function jin.core.onEvent(e)
if e.type == "Quit" then
jin.core.stop()
end
if e.type == "KeyDown" then
if e.key == "Escape" then
jin.core.stop()
end
end
if e.type == "MouseMotion" then
-- if e.button == "left" then
mx = e.x
my = e.y
-- end
end
end
local dt = 0
function jin.core.onDraw()
dt = dt + 0.1
jin.graphics.bindCanvas(canvas)
jin.graphics.useShader(shader)
shader:sendNumber("iGlobalTime", dt )
shader:sendVec3("iResolution", {sw, sh, 1})
shader:sendVec4("iMouse", {mx, my, mx, my})
jin.graphics.draw(img, 0, 0, 1, 1)
jin.graphics.unuseShader()
jin.graphics.unbindCanvas()
jin.graphics.draw(canvas, 0, 0, 2, 2)
end
|