summaryrefslogtreecommitdiff
path: root/tests/image_blend_occlude.lua
blob: 7c12293d1d25428bfd3461fd6fa01ebf0a5d9887 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local ffi = require("ffi")
local util = require("util")
local levas = util.get_lib("evas")

local variants = {
    "Image Blend Occlude 1 Few",
    "Image Blend Occlude 2 Few",
    "Image Blend Occlude 3 Few",
    "Image Blend Occlude 1",
    "Image Blend Occlude 2",
    "Image Blend Occlude 3",
    "Image Blend Occlude 1 Many",
    "Image Blend Occlude 2 Many",
    "Image Blend Occlude 3 Many",
    "Image Blend Occlude 1 Very Many",
    "Image Blend Occlude 2 Very Many",
    "Image Blend Occlude 3 Very Many"
}

local sin, cos = math.sin, math.cos
local rsh = bit.rshift
local band = bit.band

local conds = {
    function(i, n) return i < (n / 2) end,
    function(i, n) return band(i, 0x1) ~= 0 end,
    function(i, n) return i > (n / 2) end
}

local getcond = function(n)
    if n > 9 then return conds[n - 9] end
    if n > 6 then return conds[n - 6] end
    if n > 3 then return conds[n - 3] end
    return conds[n]
end

local getitern = function(n)
    if n > 9 then return 1600 end
    if n > 6 then return  320 end
    if n > 3 then return  128 end
    return 32
end

local weights = {
    10.6349,
    21.7728,
    12.7933,
    19.4177,
    34.4192,
    23.9110,
    22.8287,
    41.2399,
    30.1383,
    22.0342,
    38.2952,
     5.5560
}

return function(ui, variant)
    return "blend.png", variants[variant], weights[variant], function()
        local o_images     = {}
        local itern        = getitern(variant)
        local slow         = 5.0
        local cond         = getcond(variant)
        local win_w, win_h = ui.win_w, ui.win_h
        ui.func_set(util.del_objs(o_images), function(t, f)
            for i = 1, itern do
                if cond(i, itern) then
                    local w = 120
                    local h = 160
                    local x = (win_w / 2) - (w / 2)
                        + sin((f + ((i - 1) * 13)) / (36.7 * slow)) * (w / 2)
                    local y = (win_h / 2) - (h / 2)
                        + cos((f + ((i - 1) * 28)) / (43.8 * slow)) * (h / 2)
                    levas.evas_object_move(o_images[i], x, y)
                end
            end
        end)
        local evas = ui.evas
        util.randomseed()
        for i = 1, itern do
            local o = levas.evas_object_image_add(evas)
            o_images[i] = o
            if cond(i, itern) then
                levas.evas_object_image_file_set(o,
                    util.build_path("logo.png"), nil)
            else
                levas.evas_object_image_file_set(o,
                    util.build_path("image.png"), nil)
                local x = (win_w / 4) + rsh((util.random() % 256)
                    * ((win_w / 2) - 120), 8)
                local y = (win_h / 4) + rsh((util.random() % 256)
                    * ((win_h / 2) - 120), 8)
                levas.evas_object_move(o, x, y)
            end
            levas.evas_object_image_fill_set(o, 0, 0, 120, 160)
            levas.evas_object_resize(o, 120, 160)
            levas.evas_object_show(o)
        end
    end
end