1 -- generic functions for shogi themes
2 -- FIXME: still depends on Shogi.ttf for the tile
4 function tile(white
, ratio
)
6 local i
= Image(size
,size
)
9 local g
= RadialGradient(Point(size
*0.5,size
*0.5), size
*0.5, Point(size
*0.3,size
*0.3))
15 i
:translate(-size
, -size
)
17 b
:translate(-size
, -size
)
23 i
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
25 b
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
28 i
:draw_glyph(Rect(0,0,size
,size
), "../ShogiSVG-TTF/Shogi.ttf", "0x2c", "black", b
)
29 --i:draw_svg(Rect(0,0,size,size), "../ShogiSVG/tile.svg")
34 function draw_arrowhead(i
, p
, vx
,vy
, length
, rwidth
, linecolor
,linewidth
)
35 -- normalize to 1 the direction vector
36 local vl
= (vx
*vx
+ vy
*vy
)^
0.5
38 -- the component vector along the arrow direction
39 local vxdirect
, vydirect
= -vx
*length
, -vy
*length
40 -- an orthogonal vector of requested relative width
41 local vxortho
,vyortho
= vydirect
*rwidth
, -vxdirect
*rwidth
43 i
:draw_line(p
,Point(p
.x
+vxdirect
+vxortho
,p
.y
-vydirect
-vyortho
), linecolor
,linewidth
)
44 i
:draw_line(p
,Point(p
.x
+vxdirect
-vxortho
,p
.y
-vydirect
+vyortho
), linecolor
,linewidth
)
47 function shogi_moves(moves
)
48 return function(i
,size
)
49 if not theme
.options
.moves_overlay
.value
then
54 --local xcenter, ycenter, width = size/2, size/2, size/4
55 local xcenter
, ycenter
, width
= 0.8*size
, 0.82*size
, 0.08*size
56 local tilesize
,shortsize
= 0.8*width
, 0.3*width
57 local arrowlen
,arrowrwidth
= 0.2*width
, 0.5
58 local centerpoint
= Point(xcenter
,ycenter
)
59 local b
= Brush("red")
60 for index
,move
in ipairs(moves
) do
61 local x
,y
,long
= move
[1],move
[2],move
[3]
63 local p2
= Point(xcenter
+1.5*x
*width
, ycenter
-1.5*y
*width
)
64 i
:draw_line(centerpoint
,p2
, "purple",1)
65 draw_arrowhead(i
, p2
, x
,y
, arrowlen
,arrowrwidth
, "purple",1)
67 i
:draw_line(centerpoint
, Point(xcenter
+x
*width
,ycenter
-y
*width
),"red",1)
68 i
:fill_rect(Rect(xcenter
+x
*width
-shortsize
/2, ycenter
-y
*width
-shortsize
/2,
69 shortsize
, shortsize
), b
)
74 i
:fill_rect(Rect(xcenter
-tilesize
/2,ycenter
-tilesize
/2,
75 tilesize
,tilesize
), b
)
84 {-1,-1},{0,-1},{1,-1}}
85 shogimoves_rook
= {{-1,0,1},{1,0,1},{0,-1,1},{0,1,1}}
87 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
88 {-1,-1},{1,-1},{-1,1},{1,1}}
89 shogimoves_bishop
= {{-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1}}
91 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
92 {-1,0},{1,0},{0,-1},{0,1}}
99 shogimoves_knight
= {{-1,2},{1,2}}
100 shogimoves_lance
= {{0,1,1}}
101 shogimoves_pawn
= {{0,1}}
103 shogimoves_freeking
= {
104 {-1,1,1},{0,1,1},{1,1,1},
106 {-1,-1,1},{0,-1,1},{1,-1,1}}