-
Notifications
You must be signed in to change notification settings - Fork 0
/
flip horizontally.bas
75 lines (67 loc) · 1.33 KB
/
flip horizontally.bas
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
REM BASIC8
REM Copyright (C) 2018 - 2019 Tony Wang
REM Plugin program of BASIC8.
REM Imports common modules.
import "common/frame"
REM Loads the plugin.
def plug()
print "Loading plugin: Flip horizontally...";
register_plugin
(
"sprite, map, tiles, quantized", ' Target assets.
"Flip horizontally", ' Name.
nil, ' Tooltips.
false, ' Selection only?
false, ' Square only?
20, ' Category.
30 ' Priority.
)
enddef
REM Runs the plugin.
def run()
' Prepares.
print "Running plugin: Flip horizontally...";
x0 = 0
y0 = 0
x1 = 0
y1 = 0
w = 0
h = 0
d = nil
' Gets the operating area.
if has_selection() then
v = get_selection_range()
unpack(v, x0, y0, x1, y1)
else
v = get_frame_size()
unpack(v, x1, y1)
x1 = x1 - 1
y1 = y1 - 1
endif
w = x1 - x0 + 1
h = y1 - y0 + 1
' Gets the current pixels.
d = get_pixels_rect(x0, y0, w, h)
' Sets with the new pixels.
begin_operation("Flip horizontally")
for j = 0 to h - 1
y = y0 + j
for i = 0 to w - 1
x = x0 + i
ox = x0 + (w - 1 - i)
k = hash_xy(ox, y, w)
c = get(d, k)
set_pixel(x, y, c)
next
next
end_operation()
' Marks the asset dirty.
set_asset_unsaved()
enddef
REM Checks the operation.
ph = get_phase()
if ph = "plug" then
plug()
elseif ph = "run" then
run()
endif