Beispiel #1
0
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()
Beispiel #2
0
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()		
Beispiel #3
0
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()
Beispiel #4
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()
        x = randomIntX
        y = randomIntY
for i in range(53):
    x = randint(0, winwidth)
    y = randint(0, winheight)
    canvas.fill_pixel(x, y)

# use MKS units:  meter, kg, sec
# use average Earth-Moon distance for view scaling
moondistance = 3.84399e8

# set up initial conditions in our simulated universe
# Earth at center origin
earthrad = 6.3781e6
earthx = 0.0
earthy = 0.0

canvas.translate(winwidth / 2.0, winheight / 2.0)  # earth at center of view
winmin = min(winwidth, winheight)
winmax = max(winwidth, winheight)
viewscale = winmin / (3.0 * moondistance * inz.winscale)  # pixels/meter
canvas.scale(viewscale, viewscale)
apixel = 0.4 / viewscale  # to plot pixels as ship moves
offscreen = winmax / viewscale  # meters to be out of view

# RGB colorsets for Earth and Moon

er, eg, eb = 0.2, 0.2, 1.0  # the blue-ish Earth
mr, mg, mb = 0.6, 0.6, 0.4  # the grey-ish Moon


def show_earth(er, eg, eb):
    canvas.save_gstate()