added random colours to the hexagons
This commit is contained in:
parent
f5aaa50433
commit
8b5b258be7
|
@ -1110,10 +1110,24 @@
|
|||
"What did we learn? \n",
|
||||
"\n",
|
||||
"* angle 0 appears to be straight up for a circle or ellipse\n",
|
||||
"* The radius of the hexagon is 2*height\n",
|
||||
"* The radius of the hexagon is $2*height$ for a pointed top hexagon, and for flat top, the radius of the hexagon is $2*width$\n",
|
||||
"* Make sure you fix the aspect ratio of the rectangles you're basing things now\n",
|
||||
"* "
|
||||
"* segments are inscribed **inside** the circle\n",
|
||||
"* tiling problems are hard!!! get a mathematician.\n",
|
||||
"* there is a utility for hex codes for colours\n",
|
||||
"* draw the hexagon using a Line with a circle to make an outline instead of an Ellipse\n",
|
||||
"\n",
|
||||
"Cleaned some stuff up and added colours to the hexagons. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
59
main.py
59
main.py
|
@ -1,11 +1,14 @@
|
|||
import collections
|
||||
import random
|
||||
import math
|
||||
|
||||
from kivy import app, properties
|
||||
from kivy.uix import button, label
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.graphics import Color, Ellipse, Line
|
||||
from kivy.logger import Logger
|
||||
import kivy.utils
|
||||
from kivy.vector import Vector
|
||||
|
||||
MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
|
||||
|
||||
|
@ -24,7 +27,7 @@ class StrategyGame(FloatLayout):
|
|||
col = region % self.map_cols
|
||||
|
||||
# Add hex cells to make up the map.
|
||||
hex_cell = self.pick_hex_cell(row=row, col=col)
|
||||
hex_cell = HexMapCell()
|
||||
self.main_map.add_widget(hex_cell)
|
||||
|
||||
# Add overlay conditionally.
|
||||
|
@ -32,65 +35,31 @@ class StrategyGame(FloatLayout):
|
|||
print('({}, {})'.format(row, col))
|
||||
#radius = math.sqrt(hex_cell.width**2 + hex_cell.height**2)
|
||||
radius = 2*hex_cell.height
|
||||
solid_x = hex_cell.x - hex_cell.height*2
|
||||
solid_y = hex_cell.y - hex_cell.height*2
|
||||
solid_size = (4*hex_cell.height, 4*hex_cell.height)
|
||||
with hex_cell.canvas.after:
|
||||
Color(1,0,1,1)
|
||||
hex_cell.ell = Line(circle=(hex_cell.x, hex_cell.y,radius, 0, 360, 6), width=2)
|
||||
Color(*kivy.utils.get_random_color(alpha = .5))
|
||||
hex_cell.solid = Ellipse(pos = (solid_x, solid_y), size = solid_size, segments = 6 )
|
||||
hex_cell.bind(pos=hex_cell.update_pos, size=hex_cell.update_pos)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def pick_hex_cell(row, col):
|
||||
row_mod = row % 6
|
||||
if col % 2 == 0:
|
||||
if row_mod == 0:
|
||||
return BU()
|
||||
elif row_mod in (1, 2):
|
||||
return L()
|
||||
elif row_mod == 3:
|
||||
return TD()
|
||||
elif row_mod in (4, 5):
|
||||
return R()
|
||||
else:
|
||||
if row_mod == 0:
|
||||
return TD()
|
||||
elif row_mod in (1, 2):
|
||||
return R()
|
||||
elif row_mod == 3:
|
||||
return BU()
|
||||
elif row_mod in (4, 5):
|
||||
return L()
|
||||
|
||||
|
||||
|
||||
class HexMapCell(label.Label):
|
||||
def __init__(self, row=0, col=0, **kwargs):
|
||||
super(HexMapCell, self).__init__(**kwargs)
|
||||
self.coords = MapCoords(row, col)
|
||||
|
||||
def update_pos(self, instance, value):
|
||||
Logger.info("StratGame: {}".format(instance))
|
||||
#radius = math.sqrt(self.width**2 + self.height**2)
|
||||
radius = 2*self.height
|
||||
solid_x = self.x - self.height*2
|
||||
solid_y = self.y - self.height*2
|
||||
solid_size = (4*self.height, 4*self.height)
|
||||
self.ell.circle = (self.x, self.y, radius, 0, 360, 6)
|
||||
|
||||
|
||||
|
||||
class BU(HexMapCell):
|
||||
pass
|
||||
|
||||
|
||||
class TD(HexMapCell):
|
||||
pass
|
||||
|
||||
|
||||
class L(HexMapCell):
|
||||
pass
|
||||
|
||||
|
||||
class R(HexMapCell):
|
||||
pass
|
||||
|
||||
|
||||
self.solid.pos = (solid_x, solid_y)
|
||||
self.solid.size = solid_size
|
||||
|
||||
class HexMapControlCell(button.Button):
|
||||
def __init__(self, hex_bind=None, **kwargs):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#:import math math
|
||||
#:include debug.kv
|
||||
##:include debug.kv
|
||||
|
||||
<StrategyGame>:
|
||||
id: _game
|
||||
|
|
Loading…
Reference in New Issue