def hide_old_moon(): canvas.save_gstate() canvas.set_fill_color(0, 0, 0) # paint it as black as outer space rad = moonrad * inz.radscale diam = 2.0 * rad canvas.fill_ellipse(oldmx - rad, oldmy - rad, diam, diam) canvas.restore_gstate()
def privateGstate(): """Save the canvas.gstate and then restore it when leaving the 'with' clause.""" canvas.save_gstate() try: yield None finally: canvas.restore_gstate()
def show_earth(er, eg, eb): canvas.save_gstate() canvas.set_fill_color(er, eg, eb) rad = earthrad * inz.radscale diam = 2.0 * rad canvas.fill_ellipse(earthx - rad, earthy - rad, diam, diam) canvas.restore_gstate()
def show_moon(mr, mg, mb): canvas.save_gstate() canvas.set_fill_color(mr, mg, mb) rad = moonrad * inz.radscale diam = 2.0 * rad canvas.fill_ellipse(moonx - rad, moony - rad, diam, diam) canvas.restore_gstate()
def drawHand(width, length, angle): rads = radians(angle) endX = int(cos(angle) * length) + centerX endY = int(sin(angle) * length) + centerY canvas.save_gstate() canvas.set_stroke_color(0.0, 0.0, 0.0, 0.6) canvas.set_line_width(width) canvas.draw_line(centerX, centerY, endX, endY) canvas.restore_gstate()
def flippedDisplay(): """Flip the display so that the origin is the topLeft instead of the bottomLeft. Restore the origin to bottomLeft when leaving the 'with' clause.""" canvas.save_gstate() canvas.scale(1, -1) canvas.translate(0, -screenHeight) try: yield None finally: canvas.restore_gstate()
def drawMinorTickmarks(): for i in range(60): canvas.save_gstate() canvas.translate(centerX, centerY) canvas.rotate(-2 * pi / 60.0 * i) canvas.set_fill_color(0.4, 0.4, 0.4, 0.6) width = 1 height = 5 canvas.set_line_width(1) canvas.draw_rect(-width/2, clockWidth * 0.505, width, height) canvas.restore_gstate()
def drawMajorTickmarks2(): for i in range(12): canvas.save_gstate() canvas.set_fill_color(0.3, 0.3, 0.3, 0.6) width = height = 5 angle = -2 * pi / 12.0 * (i - 3) length = clockWidth * 0.52 rads = radians(angle) x = int(cos(angle) * length) + centerX y = int(sin(angle) * length) + centerY canvas.draw_rect(x - width/2, y - height/2, width, height) canvas.restore_gstate()
def drawNumbers2(): for i in range(12): canvas.save_gstate() canvas.translate(centerX, centerY) canvas.rotate(-2 * pi / 12.0 * i) canvas.set_fill_color(0.3, 0.3, 0.3, 0.6) fontSize = 30 fontName = 'Helvetica-Bold' number = str(12 if i == 0 else i) width, height = canvas.get_text_size(number, fontName, fontSize) canvas.draw_text(number, -width/2, 115, fontName, fontSize) canvas.restore_gstate()
def drawNumbers(): for i in range(12): canvas.save_gstate() canvas.set_fill_color(0.3, 0.3, 0.3, 0.6) fontSize = 30 fontName = 'Helvetica-Bold' number = str(12 if i == 0 else i) width, height = canvas.get_text_size(number, fontName, fontSize) hour = i angle = -2 * pi / 12.0 * (hour - 3) length = clockWidth * 0.43 rads = radians(angle) x = int(cos(angle) * length) + centerX y = int(sin(angle) * length) + centerY canvas.draw_text(number, x - width/2, y - height/2, fontName, fontSize) canvas.restore_gstate()
canvas.set_fill_color(0, 0.7, 0) for i in range(40, 460, 20): x = i + 5 y = originY - 5 canvas.fill_rect(x, y, 10, 10) for i in range(40, 460, 20): x = originX - 5 y = i + 5 canvas.fill_rect(x, y, 10, 10) canvas.set_fill_color(0.5, 0, 0, 0.5) for i in range(12): canvas.save_gstate() canvas.set_fill_color(0.4, 0.4, 0.8, 0.4) canvas.translate(250, 250) canvas.rotate(-2 * pi / 12.0 * i) canvas.fill_rect(0, 0, 120, 120) canvas.restore_gstate() canvas.begin_updates() for i in range(12): canvas.save_gstate() canvas.translate(250, 250) canvas.rotate(-2 * pi / 12.0 * i) for j in range(0, 80): randomIntX = random.randrange(0, 160) randomIntY = random.randrange(0, 160) randomColor = random.random()