Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    def drawForeground(self, g, rect):
        g.setBrush(Color.flower)
        g.setPen(no_pen)
        for it in self.all(Cell):
            if it.flower:
                poly = _flower_poly.translated(it.scenePos())
                g.drawPolygon(poly)

        g.setBrush(QBrush(qt.NoBrush))
        pen = QPen(Color.flower_border, 1.5)
        pen.setCosmetic(True)
        g.setPen(pen)
        for it in self.all(Cell):
            if it.flower:
                poly = _flower_poly.translated(it.scenePos())
                g.drawPolygon(poly)
        
        g.setPen(no_pen)
        g.setBrush(Color.beam)
        for it in self.all(Column):
            if it.beam:
                poly = QPolygonF(QRectF(-0.045, 0.525, 0.09, 1e6))
                poly = QTransform().translate(it.scenePos().x(), it.scenePos().y()).rotate(it.rotation()).map(poly)
                poly = poly.intersected(QPolygonF(rect))
                g.drawConvexPolygon(poly)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
    def drawForeground(self, g, rect):
        g.setBrush(Color.flower)
        g.setPen(no_pen)
        for it in self.all(Cell):
            if it.flower:
                poly = _flower_poly.translated(it.scenePos())
                g.drawPolygon(poly)

        g.setBrush(QBrush(qt.NoBrush))
        pen = QPen(Color.flower_border, 2)
        pen.setCosmetic(True)
        g.setPen(pen)
        for it in self.all(Cell):
            if it.flower:
                poly = _flower_poly.translated(it.scenePos())
                g.drawPolygon(poly)

        g.setPen(no_pen)
        g.setBrush(Color.beam)
        for it in self.all(Column):
            if it.beam:
                poly = QPolygonF(QRectF(-0.03, 0.525, 0.06, 1e6))
                poly = QTransform().translate(it.scenePos().x(),
                                              it.scenePos().y()).rotate(
                                                  it.rotation()).map(poly)
                poly = poly.intersected(QPolygonF(rect))
                g.drawConvexPolygon(poly)
Ejemplo n.º 5
0
def _flower_poly():
    result = QPolygonF()
    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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 def members(self):
     try:
         sr = self.scene().sceneRect()
     except AttributeError:
         return
     poly = QPolygonF(QRectF(-0.001, 0.05, 0.002, 2*max(sr.width(), sr.height())))
     if abs(self.rotation())>1e-2:
         poly = QTransform().rotate(self.rotation()).map(poly)
     poly.translate(self.scenePos())
     items = self.scene().items(poly)
     for it in items:
         if isinstance(it, Cell):
             if not poly.containsPoint(it.pos(), qt.OddEvenFill):
                 continue
             yield it
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
 def members(self):
     try:
         sr = self.scene().sceneRect()
     except AttributeError:
         return
     poly = QPolygonF(QRectF(-0.001, 0.05, 0.002, 2*max(sr.width(), sr.height())))
     if abs(self.rotation())>1e-2:
         poly = QTransform().rotate(self.rotation()).map(poly)
     poly.translate(self.scenePos())
     items = self.scene().items(poly)
     for it in items:
         if isinstance(it, Cell):
             if not poly.containsPoint(it.pos(), qt.OddEvenFill):
                 continue
             yield it
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    def __repr__(self, first=True):
        r = [self.display]
        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)
        
Ejemplo n.º 19
0
    def __repr__(self, first=True):
        r = [self.display]
        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)