def hex1(): result = QPolygonF() l = 0.5/cos30 for i in range(6): a = i*tau/6 - tau/12 result.append(QPointF(l*math.sin(a), -l*math.cos(a))) return result
def _cell_polys(): poly = QPolygonF() l = 0.46/cos30 inner_poly = QPolygonF() il = 0.75*l for i in range(6): a = i*tau/6 - tau/12 poly.append(QPointF(l*math.sin(a), -l*math.cos(a))) inner_poly.append(QPointF(il*math.sin(a), -il*math.cos(a))) return poly, inner_poly
def flower_neighbors(self): if not self.scene(): return poly = QPolygonF() l = 1.7 for i in range(6): a = i*tau/6 poly.append(QPointF(self.x()+l*math.sin(a), self.y()+l*math.cos(a))) for it in self.scene().items(poly): if isinstance(it, Cell) and it is not self: yield it
def _cell_polys(): # It will be 0.49*2+0.03 = 1.01 units high, so neighbors will slightly collide. poly = QPolygonF() l = 0.49 / cos30 # There is also a smaller inner part, for looks. inner_poly = QPolygonF() il = 0.77 * l for i in range(6): a = i * tau / 6 - tau / 12 poly.append(QPointF(l * math.sin(a), -l * math.cos(a))) inner_poly.append(QPointF(il * math.sin(a), -il * math.cos(a))) return poly, inner_poly
def _cell_polys(): # It will be 0.49*2+0.03 = 1.01 units high, so neighbors will slightly collide. poly = QPolygonF() l = 0.49/cos30 # There is also a smaller inner part, for looks. inner_poly = QPolygonF() il = 0.77*l for i in range(6): a = i*tau/6-tau/12 poly.append(QPointF(l*math.sin(a), -l*math.cos(a))) inner_poly.append(QPointF(il*math.sin(a), -il*math.cos(a))) return poly, inner_poly
def _flower_poly(): result = QPolygonF() hex1 = QPolygonF() l = 0.501/cos30 for i in range(6): a = i*tau/6-tau/12 hex1.append(QPointF(l*math.sin(a), -l*math.cos(a))) for i1 in range(6): a1 = i1*tau/6 for i2 in range(6): a2 = i2*tau/6 result = result.united(hex1.translated(math.sin(a1)+math.sin(a2), -math.cos(a1)-math.cos(a2))) return result
def __init__(self): # The collision box is rectangular poly = QPolygonF() poly.append(QPointF(-0.25, 0.48)) poly.append(QPointF(-0.25, 0.02)) poly.append(QPointF(0.25, 0.02)) poly.append(QPointF(0.25, 0.48)) #l = 0.49/cos30 #for i in range(6): #a = i*tau/6-tau/12 #poly.append(QPointF(l*math.sin(a), -l*math.cos(a))) QGraphicsPolygonItem.__init__(self, poly) self.setBrush(QColor(255, 255, 255, 0)) #self.setPen(QPen(qt.red, 0)) self.setPen(no_pen) self._text = QGraphicsSimpleTextItem('v') self._text.setBrush(Color.dark_text) fit_inside(self, self._text, 0.8)
if self.display!=self.kind: r.append('({})'.format(repr(self.kind).split('.')[1])) r.append(self._text.text()) try: r.append('#{}'.format(self.id)) except AttributeError: pass if first: r.append('neighbors:[{}]'.format(' '.join(m.__repr__(False) for m in self.neighbors))) if self.members: r.append('members:[{}]'.format(' '.join(m.__repr__(False) for m in self.members))) return '<{}>'.format(' '.join(str(p) for p in r if str(p))) _col_poly = QPolygonF() for x, y in [(-0.25, 0.48), (-0.25, 0.02), (0.25, 0.02), (0.25, 0.48)]: _col_poly.append(QPointF(x, y)) _col_angle_deltas = {-60: (1, 1), 0: (0, 1), 60: (-1, 1)} class Column(QGraphicsPolygonItem, Item): "Column number marker" def __init__(self): QGraphicsPolygonItem.__init__(self, _col_poly) self.show_info = False self.setBrush(QColor(255, 255, 255, 0)) self.setPen(no_pen) self._text = QGraphicsSimpleTextItem('v') self._text.setBrush(Color.dark_text)