Skip to content

Commit

Permalink
slight outline for stones
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Land committed Mar 15, 2020
1 parent 11c2942 commit 20bb2a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"size_min": 1,
"size_max": 15,
"stones": [ [0.05, 0.05, 0.05], [0.95, 0.95, 0.95] ],
"outline": [ [0.3,0.3,0.3,0.5], [0.7, 0.7, 0.7,0.5] ],
"ghost_alpha": 0.5,
"eval_colors": [[0.537, 0.129, 0.42], [1, 0, 0], [1, 0.95, 0], [0.117, 0.588, 0]],
"undo_alpha": 0.5,
Expand Down
2 changes: 1 addition & 1 deletion katrain.kv
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
rgba: 0.95, 0.95, 0.95, 1
Rectangle:
pos: self.pos
size: self.size
size: root.size
BadukPanWidget:
id: board
size_hint: 1 - controls.size_hint[0], 1
Expand Down
21 changes: 13 additions & 8 deletions katrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from controller import Config
from kivyutils import *

COLORS = Config.get("ui")["stones"]
STONE_COLORS = Config.get("ui")["stones"]
OUTLINE_COLORS = Config.get("ui").get("outline", [None, None])
GHOST_ALPHA = Config.get("ui")["ghost_alpha"]


Expand Down Expand Up @@ -69,9 +70,13 @@ def on_size(self, *args):
self.draw_board()
self.redraw()

def draw_stone(self, x, y, col, innercol=None, evalcol=None, evalsize=10.0, scale=1.0):
def draw_stone(self, x, y, col, outline_col=None, innercol=None, evalcol=None, evalsize=10.0, scale=1.0):
stone_size = self.stone_size * scale
draw_circle((self.gridpos[x], self.gridpos[y]), stone_size, col)
if outline_col:
Color(*outline_col)
Line(circle=(self.gridpos[x], self.gridpos[y], stone_size), width=0.05 * stone_size)

if evalcol:
evalsize = min(self.EVAL_BOUNDS[1], max(evalsize, self.EVAL_BOUNDS[0])) / self.EVAL_BOUNDS[1]
draw_circle((self.gridpos[x], self.gridpos[y]), math.sqrt(evalsize) * stone_size * 0.5, evalcol)
Expand All @@ -94,7 +99,6 @@ def draw_board(self, *args):
sz = min(self.width, self.height)
Color(*Config.get("ui")["board_color"])
board = Rectangle(pos=(0, 0), size=(sz, sz))

# grid lines
margin = Config.get("ui")["board_margin"]
self.grid_size = board.size[0] / (self.engine.board_size - 1 + 1.5 * margin)
Expand Down Expand Up @@ -136,8 +140,8 @@ def redraw(self, *args):
eval, evalsize = m.evaluation_info
move_eval_on = full_eval_on[m.player] or m in last_few_moves
evalcol = self._eval_spectrum(eval) if move_eval_on and eval and evalsize > Config.get("ui").get("min_eval_temperature", 0.5) else None
inner = COLORS[1 - m.player] if (m == last_move) else None
self.draw_stone(m.coords[0], m.coords[1], COLORS[m.player], inner, evalcol, evalsize)
inner = STONE_COLORS[1 - m.player] if (m == last_move) else None
self.draw_stone(m.coords[0], m.coords[1], STONE_COLORS[m.player], OUTLINE_COLORS[m.player], inner, evalcol, evalsize)

# ownership - allow one move out of date for smooth animation
ownership = last_move.ownership or (last_move.parent and last_move.parent.ownership)
Expand All @@ -148,7 +152,7 @@ def redraw(self, *args):
for x in range(self.engine.board_size):
ix_owner = 0 if ownership[ix] > 0 else 1
if ix_owner != (has_stone.get((x, y), -1)):
Color(*COLORS[ix_owner], abs(ownership[ix]))
Color(*STONE_COLORS[ix_owner], abs(ownership[ix]))
Rectangle(pos=(self.gridpos[x] - rsz / 2, self.gridpos[y] - rsz / 2), size=(rsz, rsz))
ix = ix + 1

Expand All @@ -160,7 +164,8 @@ def redraw(self, *args):
if m.coords[0] is not None:
undo_coords.add(m.coords)
evalcol = (*self._eval_spectrum(eval_info[0]), alpha) if eval_info[0] else None
self.draw_stone(m.coords[0], m.coords[1], (*COLORS[m.player][:3], alpha), None, evalcol, self.EVAL_BOUNDS[1], scale=Config.get("ui").get("undo_scale", 0.95))
scale = Config.get("ui").get("undo_scale", 0.95)
self.draw_stone(m.coords[0], m.coords[1], (*STONE_COLORS[m.player][:3], alpha), None, None, evalcol, self.EVAL_BOUNDS[1], scale=scale)

# hints
if self.engine.hints.active(current_player):
Expand All @@ -172,7 +177,7 @@ def redraw(self, *args):

# hover next move ghost stone
if self.ghost_stone:
self.draw_stone(*self.ghost_stone, (*COLORS[current_player], GHOST_ALPHA))
self.draw_stone(*self.ghost_stone, (*STONE_COLORS[current_player], GHOST_ALPHA))

# pass circle
passed = len(moves) > 1 and last_move.is_pass
Expand Down

0 comments on commit 20bb2a5

Please sign in to comment.