Skip to content

Commit d1b4ef6

Browse files
committed
update transform test to use static images (no animation)
Shows four sets of screens, each with X and Y scale adjustments. Origins are placed at the center of the image, and flipping of the image scale mirrors the image without displacing it.
1 parent 76d013e commit d1b4ef6

File tree

6 files changed

+76
-60
lines changed

6 files changed

+76
-60
lines changed

test/graphics/base_transform.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
local tiles = {}
3+
local quads = {}
4+
5+
function load_transform_tiles()
6+
local tile_sizes = { 32, 64, 128, 256 }
7+
for _, tsz in ipairs(tile_sizes) do
8+
if tiles[tsz] == nil then
9+
tiles[tsz] = lutro.graphics.newImage(("graphics/grid-transform-%dpx.png"):format(tsz))
10+
quads[tsz] = lutro.graphics.newQuad(0, 0, tsz, tsz, tsz, tsz)
11+
end
12+
end
13+
end
14+
15+
function draw_transform_tiles(params)
16+
lutro.graphics.setColor(255, 255, 255)
17+
18+
local scalex = params.scalex or 1
19+
local scaley = params.scaley or 1
20+
21+
-- draw multiple fixed scales of the quad onscreen at once.
22+
-- avoid use of animation since it complicates automated verification
23+
-- display multiple screens of tiled tests instead.
24+
-- Include scales that converge toward zero to ensure safety of maths (DivZero, etc)
25+
26+
local xpos = 10
27+
local ypos = 40
28+
29+
local xscales = {
30+
1.00, 1.00, 1.00, 1.00, 1.00,
31+
1.00, 0.70, 0.50, 0.30, 0.001
32+
}
33+
34+
-- use the first tile of the 2nd column to display scale=0 to ensure it's handled correctly (DivZero)
35+
local yscales = {
36+
0.00, 0.70, 0.50, 0.30, 0.001,
37+
0.00, 1.00, 1.00, 1.00, 1.00,
38+
}
39+
40+
local tsz = 128
41+
local adv_y = tsz + 4
42+
43+
for i = 1, 10 do
44+
if i == 6 then
45+
xpos = 10
46+
ypos = ypos + adv_y + 15
47+
end
48+
local orig = tsz / 2
49+
lutro.graphics.draw(
50+
tiles[tsz], quads[tsz],
51+
xpos + orig, ypos + orig,
52+
rotation,
53+
xscales[i] * scalex, yscales[i] * scaley,
54+
orig, orig
55+
)
56+
lutro.graphics.print(("%.1f x %.1f"):format(xscales[i] * scalex, yscales[i] * scaley), xpos + 32, ypos - 15)
57+
xpos = xpos + tsz + 5
58+
end
59+
end
6.95 KB
Loading
12.3 KB
Loading

test/graphics/grid-transform-32px.png

1.43 KB
Loading

test/graphics/grid-transform-64px.png

2.15 KB
Loading

test/graphics/scale.lua

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,31 @@
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
58

69
return {
7-
intervalTime = 5,
10+
intervalTime = 12,
811

912
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()
1214
end,
1315

1416
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 }
3818
end,
3919

4020
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
5122

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 }
6925

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]
7330
end
7431
}

0 commit comments

Comments
 (0)