-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.lua2p
89 lines (77 loc) · 1.88 KB
/
generator.lua2p
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
local Generator = {}
function Generator.path_points_fireflies(x, y, n)
@@assert(type(x) == "number")
@@assert(type(y) == "number")
@@assert(type(n) == "number")
local offset = 8
local points = {x = x, y = y}
local prev_x = x
local prev_y = y
for _ = 1, n - 1 do
local px = love.math.random(prev_x - offset, prev_x + offset)
local py = love.math.random(prev_y - offset, prev_y + offset)
local p = {x = px, y = py}
prev_x = px
prev_y = py
table.insert(points, p)
end
return points
end
function Generator.path_points_ants(x, y, ex, ey, n)
@@assert(type(x) == "number")
@@assert(type(y) == "number")
@@assert(type(ex) == "number")
@@assert(type(ey) == "number")
@@assert(type(n) == "number")
local points = {}
local dx = 1
local dy = (y <= ey) and -1 or 1
local offset = 2
for i = 0, n - 1 do
local t = i/n
local ox = love.math.random(-offset, offset)
local oy = love.math.random(-offset, offset)
local px = mathx.lerp(x, ex, t)
local py = mathx.lerp(y, ey, t)
px = px + ox * dx
py = py + oy * dy
dx = dx * -1
dy = dy * -1
table.insert(points, {x = px, y = py})
end
return points
end
function Generator.path_points_flies(x, y)
@@assert(type(x) == "number")
@@assert(type(y) == "number")
local minx, maxx = 8, 16
local miny, maxy = 6, 12
--[[
b c d
a o e
h g f
--]]
local hx = love.math.random(minx, maxx)
local hx_h = hx * 0.5
local hy = love.math.random(miny, maxy)
local hy_h = hy * 0.75
local o = vec2(x, y)
local vecs = {
o:sadd(-hx, 0), --a
o:sadd(-hx_h, -hy_h), --b
o:sadd(0, -hy), --c
o:sadd(hx_h, -hy_h), --d
o:sadd(hx, 0), --e
o:sadd(hx_h, hy_h), --f
o:sadd(0, hy), --g
o:sadd(-hx_h, hy_h), --h
}
local points = {}
local r = love.math.random(math.pi/6, math.pi/4)
for _, v in ipairs(vecs) do
v:rotate_around_inplace(r, o)
table.insert(points, {x = v.x, y = v.y})
end
return points
end
return Generator