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)
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)
def drawBackground(self, g, rect): common.View.drawBackground(self, g, rect) if self.hexcells_ui: pts = [(-13.837, 8.321), (-13.837, -4.232), (-9.843, -8.274), (11.713, -8.274), (11.713, -5.421), (13.837, -5.421), (13.837, 8.321)] poly = QPolygonF([rect.center() + QPointF(*p) for p in pts]) pen = QPen(qt.gray, 1) pen.setCosmetic(True) g.setPen(pen) g.drawPolygon(poly)
def __init__(self): QGraphicsPolygonItem.__init__(self, _cell_outer) self._inner = QGraphicsPolygonItem(_cell_inner) self._inner.setPen(no_pen) pen = QPen(Color.border, 0.03) pen.setJoinStyle(qt.MiterJoin) self.setPen(pen) self._text = QGraphicsSimpleTextItem('{?}') self._text.setBrush(Color.light_text) self._kind = Cell.unknown
def __init__(self): QGraphicsPolygonItem.__init__(self, _cell_outer) self._inner = QGraphicsPolygonItem(_cell_inner) self._inner.setPen(no_pen) pen = QPen(Color.border, 0.03) pen.setJoinStyle(qt.MiterJoin) self.setPen(pen) self._text = QGraphicsSimpleTextItem("{?}") self._text.setBrush(Color.light_text) self._kind = Cell.unknown
def solve_complete(self): """Continue solving until stuck. Return whether the entire level could be uncovered.""" while True: self.confirm_proven() app.processEvents() progress = True while progress: progress = False for cell, value in solve_simple(self): progress = True try: assert cell.actual==value except AssertionError: cell.setPen(QPen(qt.red, 0.2)) raise cell.kind = cell.actual cell.upd() if not self.solve_step(): break # If it identified all blue cells, it'll have the rest uncovered as well return self.remaining == 0
def mousePressEvent(self, e): if self.supress: return self.last_press = self.itemAt(e.scenePos(), QTransform()) if self.selection: if (e.button()==qt.LeftButton and not self.itemAt(e.scenePos(), QTransform())) or e.button()==qt.RightButton: old_selection = self.selection self.selection = set() for it in old_selection: try: it.selected = False except AttributeError: pass if not self.itemAt(e.scenePos(), QTransform()): if e.button()==qt.LeftButton: if e.modifiers()&qt.ShiftModifier: self.selection_path_item = QGraphicsPathItem() self.selection_path = path = QPainterPath() self.selection_path_item.setPen(QPen(Color.selection, 0, qt.DashLine)) path.moveTo(e.scenePos()) self.selection_path_item.setPath(path) self.addItem(self.selection_path_item) if e.button()==qt.LeftButton or (self.use_rightclick and e.button()==qt.RightButton): if not e.modifiers()&qt.ShiftModifier: self.place(e.scenePos(), Cell.full if (e.button()==qt.LeftButton)^self.swap_buttons else Cell.empty) else: QGraphicsScene.mousePressEvent(self, e)
def __init__(self): QGraphicsPolygonItem.__init__(self, _cell_outer) self._inner = QGraphicsPolygonItem(_cell_inner) self._inner.setPen(no_pen) pen = QPen(Color.border, 0.03) pen.setJoinStyle(qt.MiterJoin) self.setPen(pen) self._text = QGraphicsSimpleTextItem('{?}') self._text.setBrush(Color.light_text) update_font(self._text, lambda f: f.setWeight(55)) self._extra_text = QGraphicsSimpleTextItem('') self.kind = Cell.unknown self.show_info = 0
def solve_step(self): """Derive everything that can be concluded from the current state. Return whether progress has been made.""" if self.solving: return self.confirm_proven() self.solving = True app.processEvents() progress = False for cell, value in solve(self): try: assert cell.actual == value except AssertionError: cell.setPen(QPen(qt.red, 0.2)) raise cell.proven = True cell.upd() progress = True self.solving = False return progress
blue = QColor(5, 164, 235) blue_border = QColor(20, 156, 216) black = QColor(62, 62, 62) black_border = QColor(44, 47, 49) light_text = QColor(255, 255, 255) dark_text = QColor(73, 73, 73) border = qt.white beam = QColor(220, 220, 220, 140) flower = QColor(220, 220, 220, 128) flower_border = QColor(128, 128, 128, 192) revealed_border = QColor(0, 255, 128) selection = qt.black proven = QColor(0, 160, 0) no_pen = QPen(qt.transparent, 1e-10, qt.NoPen) def fit_inside(parent, item, k): "Fit one QGraphicsItem inside another, scale by height and center it" sb = parent.boundingRect() tb = item.boundingRect() item.setScale(sb.height() / tb.height() * k) tb = item.mapRectToItem(parent, item.boundingRect()) item.setPos(sb.center() - QPointF(tb.size().width() / 2, tb.size().height() / 2)) def multiply_font_size(font, k): if font.pointSizeF() > 0: font.setPointSizeF(font.pointSizeF() * k)