|
1 |
| -local t, rotation, scale_x, scale_y, org_x, org_y, src_x, src_w = 0, 0, 0, 0, 0, 0, 0, 0 |
2 |
| -local draw_line = false |
3 |
| -local line_segments = {} |
4 |
| -local img = nil |
| 1 | + |
| 2 | +require("graphics/base_transform") |
| 3 | + |
| 4 | +local rotation = 0 |
| 5 | +local xflip = 1 |
| 6 | +local yflip = 1 |
| 7 | +local time = 0 |
5 | 8 |
|
6 | 9 | return {
|
7 |
| - intervalTime = 5, |
| 10 | + intervalTime = 12, |
8 | 11 |
|
9 | 12 | load = function()
|
10 |
| - img = lutro.graphics.newImage("graphics/font.png") |
11 |
| - line_segments[1] = {x=104, y=108} -- 100 + centred on quad |
| 13 | + load_transform_tiles() |
12 | 14 | end,
|
13 | 15 |
|
14 | 16 | draw = function()
|
15 |
| - lutro.graphics.setColor(255, 255, 255) |
16 |
| - |
17 |
| - -- track scaling-offset interaction using a line |
18 |
| - if draw_line then |
19 |
| - lutro.graphics.print("Image should follow the line:", 40, 80) |
20 |
| - line_segments[#line_segments + 1] = {x=104 - scale_x * org_x, y=108 - scale_y * org_y} |
21 |
| - for idx, coord in ipairs(line_segments) do |
22 |
| - if idx > 1 then |
23 |
| - local prevcoord = line_segments[idx - 1] |
24 |
| - lutro.graphics.line(prevcoord.x, prevcoord.y, coord.x, coord.y) |
25 |
| - end |
26 |
| - end |
27 |
| - end |
28 |
| - |
29 |
| - lutro.graphics.draw(img, |
30 |
| - lutro.graphics.newQuad( src_x, 0, src_w, 16, img:getWidth(), img:getHeight()), |
31 |
| - 100, 100, |
32 |
| - rotation, |
33 |
| - scale_x, |
34 |
| - scale_y, |
35 |
| - org_x, |
36 |
| - org_y |
37 |
| - ) |
| 17 | + draw_transform_tiles{ scalex = xflip, scaley = yflip } |
38 | 18 | end,
|
39 | 19 |
|
40 | 20 | update = function(dt)
|
41 |
| - ------------------------------------------- |
42 |
| - -- Set parameters based on current time. -- |
43 |
| - ------------------------------------------- |
44 |
| - t = t + dt |
45 |
| - |
46 |
| - -- rotation not supported, so we leave it as zero. |
47 |
| - rotation = 0 |
48 |
| - |
49 |
| - scale_x = 1 + math.sin(t * 3) * 4 |
50 |
| - scale_y = math.cos(t * 2) * 2 |
| 21 | + time = time + dt |
51 | 22 |
|
52 |
| - -- test zero scaling (should be blank) |
53 |
| - if t < 0.2 then |
54 |
| - scale_x = 0 |
55 |
| - scale_y = 0 |
56 |
| - end |
57 |
| - |
58 |
| - -- image offset while scaled |
59 |
| - if t > 2.5 then |
60 |
| - -- set xscale, yscale to something arbitrary |
61 |
| - -- then ensure origin is offset correctly by scale |
62 |
| - scale_x = 1.1 + math.pow(t - 2.5, 2) |
63 |
| - scale_y = 1.1 + math.pow(t - 2.5, 2) |
64 |
| - org_x = -(t - 2.5) * 20 |
65 |
| - org_y = -10 - (math.sin((t - 2.5) * 3) * 10) |
66 |
| - -- (origin should follow the line being drawn) |
67 |
| - draw_line = true |
68 |
| - end |
| 23 | + local lutx = { 1, 1, -1, -1 } |
| 24 | + local luty = { 1, -1, 1, -1 } |
69 | 25 |
|
70 |
| - -- src position |
71 |
| - src_x = 9 * math.floor(t + 1) |
72 |
| - src_w = 8 |
| 26 | + local ix = math.min(math.floor(time / 3) + 1, 4) |
| 27 | + local iy = math.min(math.floor(time / 3) + 1, 4) |
| 28 | + xflip = lutx[ix] |
| 29 | + yflip = luty[iy] |
73 | 30 | end
|
74 | 31 | }
|
0 commit comments