summaryrefslogtreecommitdiff
path: root/tests/poly_blend.lua
blob: e9905c5afe6e88cf10d42b265a1a49158a5bbdb5 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local ffi = require("ffi")
local ffi_new = ffi.new
local util = require("util")
local levas = util.get_lib("evas")

local sin, cos = util.sin, util.cos

local cases = {
    function(o, x, y) -- triangle
        levas.evas_object_polygon_point_add(o, x + 50,  y + 0)
        levas.evas_object_polygon_point_add(o, x + 100, y + 100)
        levas.evas_object_polygon_point_add(o, x + 0,   y + 100)
    end,
    function(o, x, y) -- square
        levas.evas_object_polygon_point_add(o, x + 0,   y + 0)
        levas.evas_object_polygon_point_add(o, x + 100, y + 0)
        levas.evas_object_polygon_point_add(o, x + 100, y + 100)
        levas.evas_object_polygon_point_add(o, x + 0,   y + 100)
    end,
    function(o, x, y) -- hex
        levas.evas_object_polygon_point_add(o, x + 50,  y + 0)
        levas.evas_object_polygon_point_add(o, x + 100, y + 30)
        levas.evas_object_polygon_point_add(o, x + 100, y + 70)
        levas.evas_object_polygon_point_add(o, x + 50,  y + 100)
        levas.evas_object_polygon_point_add(o, x + 0,   y + 70)
        levas.evas_object_polygon_point_add(o, x + 0,   y + 30)
    end,
    function(o, x, y) --star
        levas.evas_object_polygon_point_add(o, x + 50, y + 0)
        levas.evas_object_polygon_point_add(o, x + 60, y + 40)
        levas.evas_object_polygon_point_add(o, x + 90, y + 30)
        levas.evas_object_polygon_point_add(o, x + 70, y + 60)
        levas.evas_object_polygon_point_add(o, x + 90, y + 100)
        levas.evas_object_polygon_point_add(o, x + 50, y + 70)
        levas.evas_object_polygon_point_add(o, x + 10, y + 100)
        levas.evas_object_polygon_point_add(o, x + 30, y + 60)
        levas.evas_object_polygon_point_add(o, x + 10, y + 30)
        levas.evas_object_polygon_point_add(o, x + 40, y + 40)
    end
}

local poly = function(o, tp, x, y)
    levas.evas_object_polygon_points_clear(o)
    local f = cases[(tp % 4) + 1]
    if f then f(o, x, y) end
end

return function(ui)
    return "rect.png", "Polygon Blend", 0.5000, function()
        local itern        = 128
        local slow         = 5
        local o_images     = {}
        local win_w, win_h = ui.win_w, ui.win_h
        local w, h = ffi_new("Evas_Coord[1]"), ffi_new("Evas_Coord[1]")
        ui.func_set(util.del_objs(o_images), function(t, f)
            for i = 1, itern do
                local o = o_images[i]
                levas.evas_object_geometry_get(o, nil, nil, w, h)
                local x = (win_w / 2) - (w[0] / 2)
                    + sin((f + ((i - 1) * 13)) / (36.7 * slow)) * (win_w / 4)
                local y = (win_h / 2) - (h[0] / 2)
                    + cos((f + ((i - 1) * 28)) / (43.8 * slow)) * (win_h / 4)
                levas.evas_object_move(o, x, y)
            end
        end)
        local evas = ui.evas
        util.randomseed()
        for i = 1, itern do
            local o = levas.evas_object_polygon_add(evas)
            o_images[i] = o
            local a =  (util.random() % 256) / 2
            local r = ((util.random() % 256) * a) / 255
            local g = ((util.random() % 256) * a) / 255
            local b = ((util.random() % 256) * a) / 255
            levas.evas_object_color_set(o, r, g, b, a)
            levas.evas_object_show(o)
            poly(o, i - 1, 0, 0)
        end
    end
end