def draw(self): s = self.size # abbreviate as we will use this a lot g = shapes.Group() g.transform = [1, 0, 0, 1, self.x, self.y] # background g.add( shapes.Circle(s * 0.5, s * 0.5, s * 0.5, fillColor=self.skinColor)) # left eye g.add( shapes.Circle(s * 0.35, s * 0.65, s * 0.1, fillColor=colors.white)) g.add( shapes.Circle(s * 0.35, s * 0.65, s * 0.05, fillColor=self.eyeColor)) # right eye g.add( shapes.Circle(s * 0.65, s * 0.65, s * 0.1, fillColor=colors.white)) g.add( shapes.Circle(s * 0.65, s * 0.65, s * 0.05, fillColor=self.eyeColor)) # nose g.add( shapes.Polygon( points=[s * 0.5, s * 0.6, s * 0.4, s * 0.3, s * 0.6, s * 0.3], fillColor=None)) # mouth if self.mood == 'happy': offset = -0.05 elif self.mood == 'sad': offset = +0.05 else: offset = 0 g.add( shapes.Polygon( points=[ s * 0.3, s * 0.2, #left of mouth s * 0.7, s * 0.2, #right of mouth s * 0.6, s * (0.2 + offset), # the bit going up or down s * 0.4, s * (0.2 + offset) # the bit going up or down ], fillColor=colors.pink, strokeColor=colors.red, strokeWidth=s * 0.03)) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # no-entry-sign specific bits if self.strokeColor: g.add(shapes.Circle(cx = (self.x+(s/2)), cy = (self.y+(s/2)), r = s/2, fillColor = None, strokeColor = self.strokeColor, strokeWidth=1)) if self.fillColor: g.add(shapes.Circle(cx = (self.x+(s/2)), cy =(self.y+(s/2)), r = ((s/2)-(s/50)), fillColor = self.fillColor, strokeColor = None, strokeWidth=0)) innerBarColor = self.innerBarColor if innerBarColor: g.add(shapes.Rect(self.x+(s*0.1), self.y+(s*0.4), width=s*0.8, height=s*0.2, fillColor = innerBarColor, strokeColor = innerBarColor, strokeLineCap = 1, strokeWidth = 0)) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() # SmileyFace specific bits g.add( shapes.Circle(cx=self.x + (s / 2), cy=self.y + (s / 2), r=s / 2, fillColor=self.fillColor, strokeColor=self.strokeColor, strokeWidth=max(s / 38., self.strokeWidth))) for i in (1, 2): g.add( shapes.Ellipse(self.x + (s / 3) * i, self.y + (s / 3) * 2, s / 30, s / 10, fillColor=self.strokeColor, strokeColor=self.strokeColor, strokeWidth=max(s / 38., self.strokeWidth))) # calculate a pointslist for the mouth # THIS IS A HACK! - don't use if there is a 'shapes.Arc' centerx = self.x + (s / 2) centery = self.y + (s / 2) radius = s / 3 yradius = radius xradius = radius startangledegrees = 200 endangledegrees = 340 degreedelta = 1 pointslist = [] a = pointslist.append from math import sin, cos, pi degreestoradians = pi / 180.0 radiansdelta = degreedelta * degreestoradians startangle = startangledegrees * degreestoradians endangle = endangledegrees * degreestoradians while endangle < startangle: endangle = endangle + 2 * pi angle = startangle while angle < endangle: x = centerx + cos(angle) * radius y = centery + sin(angle) * yradius a(x) a(y) angle = angle + radiansdelta # make the mouth smile = shapes.PolyLine(pointslist, fillColor=self.strokeColor, strokeColor=self.strokeColor, strokeWidth=max(s / 38., self.strokeWidth)) g.add(smile) return g
def draw(self): # general widget bits s = float(self.size) # abbreviate as we will use this a lot g = shapes.Group() strokeColor = self.strokeColor # not=allowed specific bits outerCircle = shapes.Circle(cx=(self.x + (s / 2)), cy=(self.y + (s / 2)), r=(s / 2) - (s / 10), fillColor=self.fillColor, strokeColor=strokeColor, strokeWidth=s / 10.) g.add(outerCircle) centerx = self.x + s centery = self.y + (s / 2) - (s / 6) radius = s - (s / 6) yradius = radius / 2 xradius = radius / 2 startangledegrees = 100 endangledegrees = -80 degreedelta = 90 pointslist = [] a = pointslist.append from math import sin, cos, pi degreestoradians = pi / 180.0 radiansdelta = degreedelta * degreestoradians startangle = startangledegrees * degreestoradians endangle = endangledegrees * degreestoradians while endangle < startangle: endangle = endangle + 2 * pi angle = startangle while angle < endangle: x = centerx + cos(angle) * radius y = centery + sin(angle) * yradius a(x) a(y) angle = angle + radiansdelta crossbar = shapes.PolyLine(pointslist, fillColor=strokeColor, strokeColor=strokeColor, strokeWidth=s / 10.) g.add(crossbar) return g
def testCircle(self): s = shapes.Circle(100, 50, 10) assert s.getBounds() == (90, 40, 110, 60)
def __init__(self): self.leftCircle = shapes.Circle(100,100,20, fillColor=colors.red) self.rightCircle = shapes.Circle(300,100,20, fillColor=colors.red)
#tutorial 37 #create png #reportlab graphics sub package save to png #save to png #rectangle from reportlab.graphics import shapes, renderPM from reportlab.lib import colors drawing_obj = shapes.Drawing(700, 800) drawing_obj.add(shapes.Rect(20, 20, 300, 300, fillColor=colors.green)) renderPM.drawToFile(drawing_obj, "tutorial37.png", "PNG") #circle from reportlab.graphics import shapes, renderPM from reportlab.lib import colors drawing_obj = shapes.Drawing(700, 800) drawing_obj.add(shapes.Circle(150, 150, 75, fillColor=colors.green)) renderPM.drawToFile(drawing_obj, "tutorial37.png", "PNG")
def simple_drawing(): drawing = shapes.Drawing(400, 400) drawing.add(shapes.Circle(200, 200, 100, fillColor=colors.red)) renderPDF.drawToFile(drawing, 'simple_drawing.pdf', msg='My Drawing')
#tutorial 36 #create index #reportlab graphics sub package #RECTANGLE DRAWING from reportlab.graphics import shapes, renderPDF from reportlab.lib import colors drawing_obj = shapes.Drawing(500, 200) drawing_obj.add(shapes.Rect(10, 10, 250, 100, fillColor=colors.blue)) renderPDF.drawToFile(drawing_obj, "tutorial36.pdf", msg="tutorial36") #CIRCLE DRAWING from reportlab.graphics import shapes, renderPDF from reportlab.lib import colors drawing_obj = shapes.Drawing(500, 200) drawing_obj.add(shapes.Circle(50, 50, 50, fillColor=colors.blue)) renderPDF.drawToFile(drawing_obj, "tutorial36.pdf", msg="tutorial36")
def _draw_circle(self, X, Y, radius, color=blue): c = shapes.Circle(X * mm, Y * mm, radius * mm) c.fillColor = None c.strokeColor = color c.strokeWidth = self.strokeWidth return c