def _draw(self, painter: QPainter, width: int, height: int): painter.setPen(QPen(Qt.NoPen)) painter.setBrush(QBrush(Color.green)) offset = self.base_height(height * 0.3 * smoothen_curve(self.get_age_coefficient())) second_offset = (self.green_height(height) - self.second_green_height(height)) * smoothen_curve( self.get_age_coefficient()) painter.drawPolygon( QPointF( -self.second_green_width(width) * smoothen_curve(self.get_age_coefficient())**2, offset + second_offset), QPointF( self.second_green_width(width) * smoothen_curve(self.get_age_coefficient())**2, offset + second_offset), QPointF( 0, min( self.second_green_height(height) * smoothen_curve(self.get_age_coefficient()) + offset + second_offset, height * 0.95))) super()._draw(painter, width, height)
def _draw(self, painter: QPainter, width: int, height: int): painter.setPen(QPen(Qt.NoPen)) painter.setBrush(QBrush(Color.orange)) for i, branch in enumerate(self.branches): h, rotation = branch painter.save() # translate/rotate to the position from which the branches grow painter.translate(0, self.base_height(height * h * smoothen_curve(self.age))) painter.rotate(degrees(rotation)) top_of_branch = self.branch_height(height) * smoothen_curve(self.get_adjusted_age()) * (1 - h) circle_on_branch_position = top_of_branch * self.branch_circles[i][1] r = ((width + height) / 2) * self.branch_circles[i][0] * smoothen_curve(self.get_adjusted_age()) * ( 1 - h) * self.age_coefficient painter.setBrush(QBrush(Color.orange)) painter.drawEllipse(QPointF(0, circle_on_branch_position), r, r) painter.restore() top_of_branch = self.base_height(height) * smoothen_curve(self.age) circle_on_branch_position = top_of_branch * self.branch_circles[-1][1] # make the main ellipse slightly larger increase_size = 1.3 r = ((width + height) / 2) * self.branch_circles[-1][0] * smoothen_curve(self.get_adjusted_age()) * ( 1 - self.branches[-1][0]) * self.age_coefficient * increase_size painter.drawEllipse(QPointF(0, circle_on_branch_position), r, r) super()._draw(painter, width, height)
def _draw(self, painter: QPainter, width: int, height: int): painter.setPen(QPen(Qt.NoPen)) painter.setBrush(QBrush(Color.green)) painter.drawPolygon(QPointF(-self.green_width(width) * smoothen_curve(self.age), self.offset(height)), QPointF(self.green_width(width) * smoothen_curve(self.age), self.offset(height)), QPointF(0, self.green_height(height) * smoothen_curve(self.age) + self.offset(height))) super()._draw(painter, width, height)
def _draw(self, painter: QPainter, width: int, height: int): super()._draw(painter, width, height) painter.save() # move to the position of the flower painter.translate(self.x, self.y) painter.setPen(QPen(Qt.NoPen)) painter.setBrush(QBrush(self.color)) pellet_size = self.pellet_size(width) * smoothen_curve( self.get_age_coefficient()) # draw each of the pellets for i in range(self.number_of_pellets): self.pellet_drawing_function(painter, pellet_size) painter.rotate(360 / self.number_of_pellets) # draw the center of the flower painter.setBrush(QBrush(Color.white)) pellet_size *= self.center_pellet_smaller_coefficient painter.drawEllipse( QRectF(-pellet_size / 2, -pellet_size / 2, pellet_size, pellet_size)) painter.restore()
def _draw(self, painter: QPainter, width: int, height: int): self.x = self.flower_center_x(width) * smoothen_curve( self.get_age_coefficient()) self.y = self.flower_center_y(height) * smoothen_curve( self.get_age_coefficient()) painter.setPen( QPen(Color.green, self.stem_width * smoothen_curve(self.get_age_coefficient()))) # draw the stem path = QPainterPath() path.quadTo(0, self.y * 0.6, self.x, self.y) painter.drawPath(path) # draw the leaves for position, coefficient, rotation in self.leafs: painter.save() # find the point on the stem and rotate the leaf accordingly painter.translate(path.pointAtPercent(position)) painter.rotate(degrees(rotation)) # rotate according to where the flower is leaning towards if self.y != 0: painter.rotate(-degrees(sin(self.x / self.y))) # make it so both leaves are facing the same direction if rotation < 0: painter.scale(-1, 1) painter.setBrush(QBrush(Color.green)) painter.setPen(QPen(0)) # draw the leaf leaf = QPainterPath() leaf.setFillRule(Qt.WindingFill) ls = self.leaf_size(width) * smoothen_curve( self.get_age_coefficient())**2 * coefficient leaf.quadTo(0.4 * ls, 0.5 * ls, 0, ls) leaf.cubicTo(0, 0.5 * ls, -0.4 * ls, 0.4 * ls, 0, 0) painter.drawPath(leaf) painter.restore()
def _draw(self, painter: QPainter, width: int, height: int): painter.setBrush(QBrush(Color.brown)) # main branch painter.drawPolygon( QPointF( -self.base_width(width) * smoothen_curve(self.get_age_coefficient()), 0), QPointF( self.base_width(width) * smoothen_curve(self.get_age_coefficient()), 0), QPointF( 0, self.base_height(height) * smoothen_curve(self.get_age_coefficient()))) # other branches for h, rotation in self.branches: painter.save() # translate/rotate to the position from which the branches grow painter.translate( 0, self.base_height(height * h * smoothen_curve(self.get_age_coefficient()))) painter.rotate(degrees(rotation)) painter.drawPolygon( QPointF( -self.branch_width(width) * smoothen_curve(self.get_slower_age_coefficient()) * (1 - h), 0), QPointF( self.branch_width(width) * smoothen_curve(self.get_slower_age_coefficient()) * (1 - h), 0), QPointF( 0, self.branch_height(height) * smoothen_curve(self.get_slower_age_coefficient()) * (1 - h))) painter.restore()
def offset(self, height): return min( height * 0.95, self.base_height(height * 0.3 * smoothen_curve(self.get_age_coefficient())))
def offset(self, height): return min(height * 0.95, self.base_height(height * 0.3 * smoothen_curve(self.age)))