summaryrefslogtreecommitdiff
path: root/tests/line_blend.lua
blob: aec086b8f4d144401df41605a01a4de4dcd26489 (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
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 sqrt, atan = util.sqrt, util.atan
local band = bit.band
local floor = util.floor

local PI = 3.141592654

local rbf = {
    function(x) return x + 1 * PI / 180 end,
    function(x) return x - 1 * PI / 180 end,
    function(x) return x + 7 * PI / 180 end,
    function(x) return x - 1 * PI / 180 end
}

local rotate_point = function(ox, oy, r, win_w, win_h)
    local x = ox[0] - (win_w / 2)
    local y = oy[0] - (win_h / 2)
    local d = sqrt(x * x + y * y)
    local angle = atan(y / x)
    if x < 0 then angle = angle - PI end
    angle = rbf[band(r, 0x3) + 1](angle)
    ox[0] = floor(d * cos(angle) + (win_w / 2))
    oy[0] = floor(d * sin(angle) + (win_h / 2))
end

return function(ui)
    return "rect.png", "Line Blend", 1.000, function()
        local itern        = 128
        local slow         = 5
        local o_images     = {}
        local win_w, win_h = ui.win_w, ui.win_h
        local ox1, oy1 = ffi_new("Evas_Coord[1]"), ffi_new("Evas_Coord[1]")
        local ox2, oy2 = 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_line_xy_get(o, ox1, oy1, ox2, oy2)
                rotate_point(ox1, oy1, i - 1, win_w, win_h)
                rotate_point(ox2, oy2, i - 1, win_w, win_h)
                levas.evas_object_line_xy_set(o, ox1[0], oy1[0], ox2[0],
                    oy2[0])
            end
        end)
        local evas = ui.evas
        util.randomseed()
        for i = 1, itern do
            local o = levas.evas_object_line_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_line_xy_set(o,
                ((win_w / 2) * (util.random() % 256)) / 255,
                ((win_h / 2) * (util.random() % 256)) / 255,
                ((win_w / 2) * (util.random() % 256)) / 255 + (win_w / 2),
                ((win_h / 2) * (util.random() % 256)) / 255 + (win_h / 2))
            levas.evas_object_show(o)
        end
    end
end