1 import("piece_theme.lua")
8 theme
.options
= OptList
{
9 BoolOpt("moves_overlay", "Moves overlay", true)
12 function tile(white
, ratio
)
14 local i
= Image(size
,size
)
17 local g
= RadialGradient(Point(size
*0.5,size
*0.5), size
*0.5, Point(size
*0.3,size
*0.3))
23 i
:translate(-size
, -size
)
25 b
:translate(-size
, -size
)
31 i
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
33 b
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
36 i
:draw_glyph(Rect(0,0,size
,size
), "Shogi.ttf", "0x2c", "black", b
)
40 function addChar(char
, promoted
)
41 return function(i
, size
)
42 i
:draw_glyph(Rect(0,0,size
,size
), "Shogi.ttf", char
,
43 promoted
and "#d00000" or "#004000",
49 function draw_arrowhead(i
, p
, vx
,vy
, length
, rwidth
, linecolor
,linewidth
)
50 -- normalize to 1 the direction vector
51 local vl
= (vx
*vx
+ vy
*vy
)^
0.5
53 -- the component vector along the arrow direction
54 local vxdirect
, vydirect
= -vx
*length
, -vy
*length
55 -- an orthogonal vector of requested relative width
56 local vxortho
,vyortho
= vydirect
*rwidth
, -vxdirect
*rwidth
58 i
:draw_line(p
,Point(p
.x
+vxdirect
+vxortho
,p
.y
-vydirect
-vyortho
), linecolor
,linewidth
)
59 i
:draw_line(p
,Point(p
.x
+vxdirect
-vxortho
,p
.y
-vydirect
+vyortho
), linecolor
,linewidth
)
62 function shogi_moves(...)
64 return function(i
,size
)
65 if not theme
.options
.moves_overlay
.value
then
70 --local xcenter, ycenter, width = size/2, size/2, size/4
71 local xcenter
, ycenter
, width
= 0.8*size
, 0.82*size
, 0.08*size
72 local tilesize
,shortsize
= 0.8*width
, 0.3*width
73 local arrowlen
,arrowrwidth
= 0.2*width
, 0.5
74 local centerpoint
= Point(xcenter
,ycenter
)
75 local b
= Brush("red")
76 for index
,move
in ipairs(moves
) do
77 local x
,y
,long
= move
[1],move
[2],move
[3]
79 local p2
= Point(xcenter
+1.5*x
*width
, ycenter
-1.5*y
*width
)
80 i
:draw_line(centerpoint
,p2
, "purple",1)
81 draw_arrowhead(i
, p2
, x
,y
, arrowlen
,arrowrwidth
, "purple",1)
83 i
:draw_line(centerpoint
, Point(xcenter
+x
*width
,ycenter
-y
*width
),"red",1)
84 i
:fill_rect(Rect(xcenter
+x
*width
-shortsize
/2, ycenter
-y
*width
-shortsize
/2,
85 shortsize
, shortsize
), b
)
90 i
:fill_rect(Rect(xcenter
-tilesize
/2,ycenter
-tilesize
/2,
91 tilesize
,tilesize
), b
)
97 function shogi_piece(char
, white
, promoted
, ratio
, ...)
98 return addShadow(overlay(tile(white
, ratio
),
100 addChar(char
, promoted
)))
103 theme
.black_king
= shogi_piece("0x6B", false, false, 1,
106 {-1,-1},{0,-1},{1,-1})
107 theme
.black_rook
= shogi_piece("0x72", false, false, 0.96,
108 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1})
109 theme
.black_p_rook
= shogi_piece("0x52", false, true, 0.96,
110 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
111 {-1,-1},{1,-1},{-1,1},{1,1})
112 theme
.black_bishop
= shogi_piece("0x62", false, false, 0.93,
113 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1})
114 theme
.black_p_bishop
= shogi_piece("0x42", false, true, 0.93,
115 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
116 {-1,0},{1,0},{0,-1},{0,1})
117 theme
.black_gold
= shogi_piece("0x67", false, false, 0.9,
120 theme
.black_silver
= shogi_piece("0x73", false, false, 0.9,
123 theme
.black_p_silver
= shogi_piece("0x53", false, true, 0.9,
126 theme
.black_knight
= shogi_piece("0x68", false, false, 0.86,
128 theme
.black_p_knight
= shogi_piece("0x48", false, true, 0.86,
131 theme
.black_lance
= shogi_piece("0x6C", false, false, 0.83,
133 theme
.black_p_lance
= shogi_piece("0x4C", false, true, 0.83,
136 theme
.black_pawn
= shogi_piece("0x70", false, false, 0.8,
138 theme
.black_p_pawn
= shogi_piece("0x50", false, true, 0.8,
142 theme
.white_king
= shogi_piece("0x6B", true, false, 1,
145 {-1,-1},{0,-1},{1,-1})
146 theme
.white_rook
= shogi_piece("0x72", true, false, 0.96,
147 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1})
148 theme
.white_p_rook
= shogi_piece("0x52", true, true, 0.96,
149 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
150 {-1,-1},{1,-1},{-1,1},{1,1})
151 theme
.white_bishop
= shogi_piece("0x62", true, false, 0.93,
152 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1})
153 theme
.white_p_bishop
= shogi_piece("0x42", true, true, 0.93,
154 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
155 {-1,0},{1,0},{0,-1},{0,1})
156 theme
.white_gold
= shogi_piece("0x67", true, false, 0.9,
159 theme
.white_silver
= shogi_piece("0x73", true, false, 0.9,
162 theme
.white_p_silver
= shogi_piece("0x53", true, true, 0.9,
165 theme
.white_knight
= shogi_piece("0x68", true, false, 0.86,
167 theme
.white_p_knight
= shogi_piece("0x48", true, true, 0.86,
170 theme
.white_lance
= shogi_piece("0x6C", true, false, 0.83,
172 theme
.white_p_lance
= shogi_piece("0x4C", true, true, 0.83,
175 theme
.white_pawn
= shogi_piece("0x70", true, false, 0.8,
177 theme
.white_p_pawn
= shogi_piece("0x50", true, true, 0.8,
181 -- To be able to adapt this theme to chess too
182 -- should use a Free King (\u5954\u738b) instead
183 theme
.black_queen
= theme
.black_gold
184 theme
.white_queen
= theme
.white_gold