Пример #1
0
def make_turtle_gif(user_program, output_file, snapshot_delay, frame_delay):
    def tick():
        #print("snip")
        counter.take_picture(root_prefix)
        root.after(snapshot_delay, tick)

    def exitonclick():
        turtle.exitonclick = lambda *a, **kw: None
        counter.take_picture(root_prefix)

    # prefix for temporary files
    root_prefix = ".temp_shot-%s-%03d-" % \
            (time.strftime("%Y%m%d%H%M%S"), random.randrange(1000))
    # do a last picture when we're done
    counter = Counter()
    turtle.exitonclick = exitonclick
    turtle.setup(1920, 1080)
    root = turtle.getcanvas()._root()
    root.after(snapshot_delay, tick)
    # start the users program
    execute_file(user_program)

    counter.take_picture(root_prefix)
    print("Creating gif", output_file, repr(root_prefix))
    subprocess.call(
        [CREATE_GIF_SH, root_prefix, output_file, str(frame_delay)])
Пример #2
0
def saveSpiro():
    dateStr = (datetime.now()).strftime("%d%b%Y-%H%M%S")
    fileName = "spiro" + dateStr 
    canvas=turtle.getcanvas()
    canvas.postscript(file = fileName + ".eps")
    img = Image.open(fileName + ".eps")
    img.save(fileName+".png", "png")
    print(fileName, "saved")
Пример #3
0
def engine():
	'''
	Starts the game engine running.
	'''
	while _e.ithinkican:
		# flush out changes
		turtle.update()

		# delay if it's running too fast
		time.sleep(_e.delay)

		# time for random event?
		for prob, fn in _e.random:
			if random.random() < prob:
				fn()

		# move objects
		for obj in _e.L:
			if obj in _e.deleteme:
				continue
			obj.step()
			# note obj may be deleted after calling step()

		# collision detection
		# XXX assumes the class of a game object is the class
		# XXX registered for collisions
		for i in range(len(_e.L)):
			obj1 = _e.L[i]
			if obj1 in _e.deleteme:
				continue
			for j in range(i+1, len(_e.L)):
				obj2 = _e.L[j]
				if obj2 in _e.deleteme:
					continue
				key = (obj1.__class__, obj2.__class__)
				if key in _e.collide:
					_e.collide[key](obj1, obj2)
				if obj1 in _e.deleteme:
					# may have been deleted post-collision
					break

		# handle I/O events
		for fn, args in _e.ioevents:
			fn(*args)
		_e.ioevents = []

		# _L quiescent; do deletions
		_e.L = [obj for obj in _e.L if obj not in _e.deleteme]
		_e.deleteme.clear()

	if _e.kbdfn:
		canvas = turtle.getcanvas()
		canvas.unbind('<KeyPress>', None)
	if _e.mousefn:
		turtle.onscreenclick(None)
Пример #4
0
def set_keyboard_handler(fn):
	'''
	Sets callback function to invoke when a key is pressed.  The
	function is passed the name of the key pressed as a string.
	Only one keyboard handler may be registered at a time.
	'''
	_e.kbdfn = fn
	# XXX why can't the turtle module just send the !@&^#%$ keysym?
	canvas = turtle.getcanvas()
	canvas.bind('<KeyPress>', _E._keypress_cb)
	turtle.listen()
Пример #5
0
def saveDrawing():
    #hide cursor
    turtle.hideturtle
    #generate unique filenames
    dateStr = (datetime.now()).strftime("%d%b%Y-%H%M%S")
    fileName = 'spiro-'+dateStr
    print('savig drawing to %s.eps/pnh' % fileName)
    #get tkinter canvas
    canvas = turtle.getcanvas()
    #save the drawing as a postscript image
    canvas.postscript(file = fileName + '.eps')
    #use pillow to convert to PNG
    img = Image.open(fileName + '.eps')
    img.save(fileName + '.png', 'png')
Пример #6
0
def tscheme_pixel(x, y, c):
    """Draw a filled box of pixels (default 1 pixel) at (x, y) in color c."""
    check_type(c, scheme_stringp, 0, "pixel")
    color = eval(c)
    canvas = turtle.getcanvas()
    w, h = canvas.winfo_width(), canvas.winfo_height()
    if not hasattr(tscheme_pixel, 'image'):
        _tscheme_prep()
        tscheme_pixel.image = tkinter.PhotoImage(width=w, height=h)
        canvas.create_image((0, 0), image=tscheme_pixel.image, state="normal")
    size = tscheme_pixel.size
    for dx in range(size):
        for dy in range(size):
            screenx, screeny = x * size + dx, h-(y * size + dy)
            if 0 < screenx < w and 0 < screeny < h:
                tscheme_pixel.image.put(color, (screenx, screeny))
Пример #7
0
import turtle
import time
import random
from ball import *
from turtle import *
colormode(255)
turtle.tracer(0)
turtle.hideturtle()
running = True
sleep = 0.0077
screen_width = turtle.getcanvas().winfo_width() / 2
screen_height = turtle.getcanvas().winfo_height() / 2
number_of_BALLS = 7
minimum_ball_radius = 10
maximum_ball_radius = 60
minimum_ball_dx = -5
maximum_ball_dx = 5
minimum_ball_dy = -5
maximum_ball_dy = 5
score = 0
balls = []
big_ball = Ball(100, 100, 5, 5, 50, "blue")

scoret = turtle.Turtle()

for i in range(number_of_BALLS):
    screen_random1_x = int(-screen_width + maximum_ball_radius)
    screen_random2_x = int(screen_width - maximum_ball_radius)
    random_x = random.randint(screen_random1_x, screen_random2_x)

    screen_random1_y = int(-screen_height + maximum_ball_radius)
Пример #8
0
##set up
import turtle,random,time,math
from ball import Ball
turtle.tracer(0)
turtle.hideturtle()
Running= True
sleep=0.1
screen_width=turtle.getcanvas().winfo_width()/2
screen_height= turtle.getcanvas().winfo_height()/2


       

##setup pt.2
MY_BALL=Ball(0,0,200,200,200,"darkgray")
Number_of_balls=5
MINIMUM_BALL_RADIUS=10
MAXIMUM_BALL_RADIUS=100
MINIMUM_Ball_Dx=1
MAXIMUM_BALL_Dx=3
MAXIMUM_BALL_Dy=3
MINIMUM_BALL_Dy=1
BALLS=[]
#just making sure it's an int

##making diffrent balls
for i in range(Number_of_balls):
    x=random.randint(round(-screen_width) + MAXIMUM_BALL_RADIUS,round(screen_width) - MAXIMUM_BALL_RADIUS)
    y=random.randint(round(-screen_height) + MAXIMUM_BALL_RADIUS,round(screen_width) - MAXIMUM_BALL_RADIUS)
    dx=random.randint(MINIMUM_Ball_Dx,MAXIMUM_BALL_Dx)
    dy=random.randint(MINIMUM_BALL_Dy,MAXIMUM_BALL_Dy)
Пример #9
0
def movearound():
    x = turtle.getcanvas().winfo_pointerx() - screen_width * 2
    y = screen_height * 1.4 - turtle.getcanvas().winfo_pointery()
    my_ball.goto(x, y)
Пример #10
0
def run_main():

    turtle.setup(width=0.75, height=0.9)
    turtle.hideturtle()

    if len(sys.argv) == 3:
        num = int(sys.argv[1])
        sz = int(sys.argv[2])
        for round in range(1, num + 1):
            random.seed(round)

            mz = generate_maze(sz)
            turtle.getcanvas().delete(tkinter.ALL)
            draw_maze(mz)

            ts = turtle.getscreen()
            fname = "mz%d_%d.eps" % (round, sz)
            ts.getcanvas().postscript(file=fname)
        sys.exit()

    elif len(sys.argv) != 1:
        print('Illegal usage')
        sys.exit()

    #random.seed(4)
    run = True
    maze_size = 4
    mz = None

    x0 = 0
    y0 = 0
    x1 = 0
    y1 = 0

    turtle.bgcolor('White')

    while run:
        if mz is None:
            maze_size = rnd_size()
            mz = generate_maze(maze_size)

        turtle.bgcolor(color['background'])
        draw_maze(mz)

        sleep(1)

        sz, cells, doors = mz

        x0 = rnd_coord(mz)
        y0 = rnd_coord(mz)
        x1 = rnd_coord(mz)
        y1 = rnd_coord(mz)

        d = find_path(mz, (x0, y0), (x1, y1))
        #draw_distance(mz, d)

        c0 = color['start_bg']
        c1 = color['end_bg']
        color_maze(mz, d, c0, c1)

        xc, yc = cell_center(mz, (x0, y0))
        r = image_scale() // 4
        draw_circle(xc, yc, r, color['start'], color['start'])
        sleep(1)
        xc, yc = cell_center(mz, (x1, y1))
        draw_circle(xc, yc, r, color['end'], color['end'])
        sleep(3)

        if d[(x1, y1)] == sz * sz:
            pass
        else:
            draw_trail(mz, d, (x1, y1))
        sleep(3)

        c = random.choice((['s'] * maze_size) + (['n'] * 1))

        if c == 'N' or c == 'n':
            mz = None

        turtle.getcanvas().delete(tkinter.ALL)
Пример #11
0
    def game_mode2():
        #variables
        turtle.tracer(0, 0)
        turtle.hideturtle()
        RUNNING = True
        SLEEP = 0.0077
        SCREEN_WIDTH = turtle.getcanvas().winfo_width() // 2
        SCREEN_HEIGHT = turtle.getcanvas().winfo_height() // 2
        player = Ball(0, 0, 25, 25, 15, "blue")
        NUMBER_OF_BALLS = 40
        MINIMUM_BALL_RADIUS = 5
        MAXIMUM_BALL_RADIUS = 25
        MINIMUM_BALL_DX = -3
        MAXIMUM_BALL_DX = 3
        MINIMUM_BALL_DY = -3
        MAXIMUM_BALL_DY = 3
        BALLS = []
        turtle.bgpic("index2.gif")
        points = 3
        timer = turtle.Turtle()
        timer.hideturtle()
        timer.penup()
        timer.goto(0, 300)

        #creating the circles
        for i in range(NUMBER_OF_BALLS):
            x = random.randint(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS,
                               SCREEN_WIDTH - MAXIMUM_BALL_RADIUS)
            y = random.randint(-SCREEN_HEIGHT + MAXIMUM_BALL_RADIUS,
                               SCREEN_HEIGHT - MAXIMUM_BALL_RADIUS)
            dx = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            dy = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            r = random.randint(MINIMUM_BALL_RADIUS, MAXIMUM_BALL_RADIUS)
            color = (random.random(), random.random(), random.random())
            while dx == 0:
                dx = random.randint(MINIMUM_BALL_DX, MAXIMUM_BALL_DX)
            while dy == 0:
                dy = random.randint(MINIMUM_BALL_DY, MAXIMUM_BALL_DY)
            new_ball = Ball(x, y, dx, dy, r, color)
            BALLS.append(new_ball)

        #checking collisions between 2 balls
        def collide(ball_a, ball_b):
            if ball_a == ball_b:
                return False
            current_x1 = ball_a.xcor()
            current_y1 = ball_a.ycor()

            current_x2 = ball_b.xcor()
            current_y2 = ball_b.ycor()

            D = math.sqrt(
                math.pow((current_x2 - current_x1), 2) +
                math.pow((current_y2 - current_y1), 2))
            if D >= ball_a.r + ball_b.r:
                return False
            if D < ball_a.r + ball_b.r:
                return True

        def myball_collision():
            for ball_a in BALLS:
                collide(ball_a, player)
                if collide(ball_a, player) == True:
                    if ball_a.r > player.r or ball_a.r < player.r:
                        quit()

        #making the game move
        def move_all_balls():
            for i in BALLS:
                i.move(SCREEN_WIDTH, SCREEN_HEIGHT)

        def movearound(event):
            player.goto(event.x - SCREEN_WIDTH, SCREEN_HEIGHT - event.y)

        turtle.getcanvas().bind("<Motion>", movearound)

        while RUNNING:
            move_all_balls()
            myball_collision()

            turtle.update()
            time.sleep(SLEEP)

            while points >= 0:
                timer.write(str("GAME STARTS IN : " + str(points) +
                                " SECONDS"),
                            move=True,
                            align="center",
                            font=("Arial", 20, "normal"))
                points -= 1
                time.sleep(1)
                timer.clear()
                timer.goto(0, 300)
Пример #12
0
init_state = state(size)

wn = turtle.Screen()
wn.bgcolor("black")
wn.title("Align3")
wn.setup(700, 700)


def onTextClick(event):
    x, y = event.x, event.y
    print('x={}, y={}'.format(x, y))
    if (x >= 600 and x <= 800) and (y >= 280 and y <= 300):
        turtle.onscreenclick(lambda x, y: turtle.bgcolor('red'))


canvas = turtle.getcanvas()
canvas.bind('<Button-1>', onTextClick)

tile_pen = Pen()
user_pen = User()
agent_pen = Agent()
draw_floor(size)

N = 0


def run_game():
    res = alpha_beta(init_state, BLUE, a, b, 0, max_depth)
    res_arr = res[1]
    #print res_arr
    try:
Пример #13
0
import turtle

canvas = turtle.getcanvas()  # ��Ʋ���� ������ ����� ȭ���� �����´�.
drawFlag = False    # ���� Ŭ���� �� �������� üũ�ϴ� �÷��׺���  draw_line���� ����Ѵ�.
color = 'black'   #�� ����
bgcolor = 'white'  # ������

canvas.config(background = bgcolor)  #�˹������ٰ� ������ �����ش�.


last_point = (-1, -1)  # ���ʿ��� ����Ʈ�� ���̸� �ȵǹǷ� (-1,-1) �������� ������.


def penClick(event):   #���� ���� ���ʿ� ȣ��Ǵ� �Լ�
    global last_point
    x = canvas.canvasx(event.x)  #���� ȭ�鿡 ������ִ� ĵ������ x����� �����´�.
    y = canvas.canvasy(event.y)  #���� ȭ�鿡 ������ִ� ĵ������ y����� �����´�.
    last_point = (x, y)         #��������Ʈ�� �ٲ��ش�. (Ŭ���������� ������ ����Ʈ�����̹Ƿ�)


def draw_line(event):  #�������¿��� �����̴� ����(�巡�׻���) ���� �۵��ϴ� �Լ�

    global drawFlag, last_point
    if(drawFlag):   # �÷��� ���¿� ���� ���� ������ ���� ���Ѵ�.
        return
    drawFlag = True
    x = canvas.canvasx(event.x)
    y = canvas.canvasy(event.y)
    canvas.create_line(\
        last_point[0], last_point[1], x, y, fill = color)    # ���� �ߴ´�.  last_point�������� ���� ���콺�� ��ġ�� (x,y) ��������
Пример #14
0
 def take_picture(self, root_prefix):
     filename = root_prefix + "{:03d}.ps".format(self.snapshot)
     take_picture(
         turtle.getcanvas(), 
         filename)
     self.snapshot += 1
Пример #15
0
def onmousemove(callback):
    cv = turtle.getcanvas()
    cv.bind('<Motion>', callback)
Пример #16
0
def tscheme_screen_width():
    """Screen width in pixels of the current size (default 1)."""
    return turtle.getcanvas().winfo_width() // tscheme_pixel.size
Пример #17
0
import turtle as tu

lines = 100_000

with open("1_million_digits_of_pi.txt", "r") as f:
    pi = f.read()

tu.mode('logo')
tu.tracer(False)
tu.screensize(6000, 6000, 'black')
tu.colormode(255)


for n in range(lines):
    color = int(n/(lines/255))
    tu.pencolor(255, 255-color, color)
    zahl = int(pi[n])
    rotation = zahl * 36
    tu.setheading(rotation)
    tu.forward(3)
    if n % 10_000 == 0:
        tu.update()

tu.getcanvas().postscript(file='PI_Picture.ps')
tu.done()
Пример #18
0
from turtle import *
import turtle
from player import *
from bullet import *
from target import *
import random
import time
import math
from threading import Thread
import sys

turtle.tracer(1, 0)

SLEEP = 0.05
SCREEN_WIDTH = int(turtle.getcanvas().winfo_width() / 2)
SCREEN_HEIGHT = int(turtle.getcanvas().winfo_height() / 2)
TIME = Turtle()
TIME.ht()
TIME.pu()
RUNNING = True
UP_ARROW = "Up"
DOWN_ARROW = "Down"
SPACEBAR = "space"
c = 0

bullets = []
NUMBER_OF_BALLS = 10
MINIMUM_BALL_RADIUS = 30
MAXIMUM_BALL_RADIUS = 30
MINIMUM_BALL_DX = -5
MAXIMUM_BALL_DX = 5
Пример #19
0
#again = turtle.Turtle()
go.hideturtle()

Door = turtle.clone()
Door.ht()
Door.penup()
Door.goto(400, 400)


turtle.colormode(1)

turtle.tracer(0)
turtle.hideturtle() 

running = True
screen_width = turtle.getcanvas().winfo_width()/2
screen_height = turtle.getcanvas().winfo_height()/2




my_ball = Ball(0, 0,3, 1,"blue",15, True)

turtle.register_shape("small_ghost.gif")
my_ball.shape("small_ghost.gif")





number_of_KEYS = 9
Пример #20
0
def first_game():

    go = turtle.clone()
    go.color("red")
    #again = turtle.Turtle()
    go.hideturtle()

    turtle.setup(width=1920, height=1080)

    Door = turtle.clone()
    Door.ht()
    Door.penup()
    Door.goto(1000, 1000)

    turtle.colormode(1)

    turtle.tracer(0)
    turtle.hideturtle()

    running = True
    screen_width = turtle.getcanvas().winfo_width() / 2
    screen_height = turtle.getcanvas().winfo_height() / 2

    my_ball = Ball(0, 0, 3, 1, "blue", 15, True)

    def key1():
        my_ball.setheading(90)
        my_ball.fd(30)
        update()

    def key2():
        my_ball.setheading(180)
        my_ball.fd(30)
        update()

    def key3():
        my_ball.setheading(270)
        my_ball.fd(30)
        update()

    def key4():
        my_ball.setheading(360)
        my_ball.fd(30)
        update()

    Screen().onkey(key1, "Up")
    Screen().onkey(key2, "Left")
    Screen().onkey(key3, "Down")
    Screen().onkey(key4, "Right")

    Screen().listen()

    turtle.register_shape("small_ghost.gif")
    my_ball.shape("small_ghost.gif")

    number_of_KEYS = 9
    minimum_ball_radius = 10
    maximum_ball_radius = 100
    minimum_ball_dx = -5
    maximum_ball_dx = 5
    minimum_ball_dy = -5
    maximum_ball_dy = 5

    turtle.register_shape("Door.gif")
    Door.shape("Door.gif")
    turtle.register_shape("flying_keys.gif")
    turtle.register_shape("fire.gif")
    KEYS = []
    FIRES = []

    for i in range(number_of_KEYS):
        #   x = random.randint( -screen_width + maximum_ball_radius, screen_width - maximum_ball_radius)
        #    y = random.randint(-screen_height + maximum_ball_radius, screen_height - maximum_ball_radius)
        #    dx = random.randint(minimum_ball_dx, maximum_ball_dx)
        #    dy = random.randint(minimum_ball_dy, maximum_ball_dy)
        #    r = random.randint(minimum_ball_radius, maximum_ball_radius)
        #    color = (random.random(), random.random(), random.random())

        #flying_keys = Keys_Fires(x, y, dx, dy, 20, color, True)
        #flying_keys.shape("flying_keys.gif")
        #KEYS.append(flying_keys)

        x = random.randint(-screen_width + maximum_ball_radius,
                           screen_width - maximum_ball_radius)
        y = random.randint(-screen_height + maximum_ball_radius,
                           screen_height - maximum_ball_radius)
        dx = random.randint(minimum_ball_dx, maximum_ball_dx)
        dy = random.randint(minimum_ball_dy, maximum_ball_dy)
        r = random.randint(minimum_ball_radius, maximum_ball_radius)
        color = (random.random(), random.random(), random.random())

        flying_keys = Ball(x, y, dx, dy, color, 26, True)
        flying_keys.shape("flying_keys.gif")
        KEYS.append(flying_keys)
        x = random.randint(-screen_width + maximum_ball_radius,
                           screen_width - maximum_ball_radius)
        y = random.randint(-screen_height + maximum_ball_radius,
                           screen_height - maximum_ball_radius)
        dx = random.randint(minimum_ball_dx, maximum_ball_dx)
        dy = random.randint(minimum_ball_dy, maximum_ball_dy)
        r = random.randint(minimum_ball_radius, maximum_ball_radius)
        color = (random.random(), random.random(), random.random())
        new_fires = Ball(x, y, dx, dy, color, 25, False)
        new_fires.shape("fire.gif")
        FIRES.append(new_fires)

    #def move_all_KEYS():
    #for b in KEYS:
    #  b.move(screen_width, screen_height)

    def collide(my_ball, ball_b):
        if my_ball == ball_b:
            return False

        distance = math.sqrt(
            math.pow(my_ball.xcor() - ball_b.xcor(), 2) +
            math.pow(my_ball.ycor() - ball_b.ycor(), 2))
        if my_ball.r + ball_b.r >= distance:
            return True

        else:
            return False

    def col_with_door(my_ball, Door):
        if my_ball == Door:
            return False
        distance = math.sqrt(
            math.pow(my_ball.xcor() - Door.xcor(), 2) +
            math.pow(my_ball.ycor() - Door.ycor(), 2))
        if distance <= 50:
            return True
        else:
            return False

    #distance_ab = math.sqrt(math.pow(my_ball.xcor() - ball_b.xcor(), 2) + math.pow(my_ball.ycor() - ball_b.ycor(), 2))

    def check_all_KEYS_collision():
        global running
        all_KEYS = []
        all_fires = []
        # all_KEYS.append(my_ball)

        for ball in KEYS:
            all_KEYS.append(ball)
        for ball in FIRES:
            all_KEYS.append(ball)
        for ball_b in all_KEYS:
            if (collide(my_ball, ball_b)):
                r1 = my_ball.r
                r2 = ball_b.r
                if ball_b.CanBeEaten:
                    ball_b.ht()
                    KEYS.remove(ball_b)
                if ball_b.CanBeEaten == False:
                    go.write("GAME OVER!!! TRY AGAIN IN 1000 YEARS",
                             align="center",
                             font=("david", 25, "normal"))
                    time.sleep(4)
                    quit()
        if col_with_door(my_ball, Door):
            #turtle.clearscreen()
            for fire in FIRES:
                fire.hideturtle()
            #turtle.bgpic("heavenxhell.png")
            my_ball.hideturtle()
            Door.hideturtle()
            second_game()

            # x = random.randint( -screen_width + maximum_ball_radius, screen_width - maximum_ball_radius)
            # y = random.randint(-screen_height + maximum_ball_radius, screen_height - maximum_ball_radius)
            # dx = random.randint(minimum_ball_dx, maximum_ball_dx)
            # dy = random.randint(minimum_ball_dy, maximum_ball_dy)
            # while (dx == 0 and dy ==0):
            #     dx = random.randint(minimum_ball_dx, maximum_ball_dx)
            #     dy = random.randint(minimum_ball_dy, maximum_ball_dy)
            # r = random.randint(minimum_ball_radius, maximum_ball_radius)
            # color = (random.random(), random.random(), random.random())
            # if my_ball.CanBeEaten and ball_b.CanBeEaten:
            #     if r1 > r2:
            #         if my_ball == ball_b:
            #             running = False
            # if r2 > r1:
            #     my_ball.new_Ball(x, y, dx, dy, r,color)
            #     if my_ball == my_ball:
            #         running = False
            #     if your_ball == my_ball:
            #         running = False
            #     if your_ball == ball_b:
            #         your_ball.r = your_ball.r + 1
            #         your_ball.shapesize(your_ball.r/10)

    # def movearound():
    #     x=turtle.getcanvas().winfo_pointerx() - screen_width*2

    #     y = screen_height*1.5 - turtle.getcanvas().winfo_pointery()

    #     my_ball.goto(x, y)

    running = True
    while running:
        if len(KEYS) == 0:
            Door.goto(500, 450)
            Door.showturtle()
        screen_width = turtle.getcanvas().winfo_width() / 2
        screen_height = turtle.getcanvas().winfo_height() / 2

        #movearound()

        #move_all_KEYS()
        # turtle.update()
        # time.sleep(2)

        check_all_KEYS_collision()

        time.sleep(.1)

        turtle.update()

    t.join()
Пример #21
0
def movearound():
    cursor_x = turtle.getcanvas().winfo_pointerx() - screen_width
    cursor_y = screen_height - turtle.getcanvas().winfo_pointery()
    my_ball.goto(cursor_x, cursor_y)
Пример #22
0
import turtle

c = turtle.Turtle()
turtle.bgcolor('black')
c.pensize(2)
c.hideturtle()
c.speed(0)

colours = [
    "misty rose", "pink", "light pink", "pale violet red", "violet", "plum",
    "seashell"
]

for i in range(6):
    for col in colours:
        c.color(col)
        c.circle(100)
        c.left(10)

turtle.getcanvas().postscript(file="circle_spirograph.eps")

turtle.mainloop()
Пример #23
0
def color_rgb(cname):
    return turtle.getcanvas().winfo_rgb(cname)
Пример #24
0
from turtle import *
import turtle
import random

colormode(255)
running = True
sleep = 0.0077
screen_width = int(turtle.getcanvas().winfo_width() / 2)
screen_height = int(turtle.getcanvas().winfo_height() / 2)


class Ball(Turtle):
    def __init__(self, x, y, dx, dy, r, color):
        Turtle.__init__(self)
        self.pu()
        self.dx = dx
        self.dy = dy
        self.r = r
        self.x = x
        self.y = y
        self.shapesize(r / 10)
        self.goto(x, y)
        self.color(color)
        self.shape("circle")

    def move(self, width, height):
        current_x = self.xcor()
        new_x = current_x + self.dx
        current_y = self.ycor()
        new_y = current_y + self.dy
        right_side_ball = new_x + self.r
Пример #25
0
def sleep(seconds):
    cv = turtle.getcanvas()
    cv.update_idletasks()
    time.sleep(seconds)
Пример #26
0
from turtle import *
import turtle
import time
import random
from ball import *
colormode(255)
tracer(0)
hideturtle()

getscreen().setup(1.0, 1.0)

SCREEN_WIDTH = turtle.getcanvas().winfo_width() / 2
SCREEN_HEIGHT = turtle.getcanvas().winfo_height() / 2

bgcolor("black")
running = True
sleep = 0.0077
number_of_BALLS = 7
minimum_ball_radius = 3
maximum_ball_radius = 60
minimum_ball_dx = -3
maximum_ball_dx = 3
minimum_ball_dy = -3
maximum_ball_dy = 3
balls = []

MY_BALL = Ball(0, 0, 0, 0, 25, "red")

for i in range(number_of_BALLS):

    screen_random1_x = int(-screen_width + maximum_ball_radius)
Пример #27
0
 def get_canvas(self):
     cv = turtle.getcanvas()
     return cv
Пример #28
0
                coordonnees = (x, sup_droit1)
                hexagone(coordonnees, longueur, col, centre, rayon)
            n += 1
        sup_droit1 = sup_droit1 - longueur * math.sin(angle)


# ETAPE 4: code principal aevc paramètres demandés à l'utilisateur
pavage(inf_gauche, sup_droit, longueur, col, centre,
       r)  # r = rayon de la sphère de déformation
inf_gauche = int(
    input(
        "Valeurs coordonnées bord inférieur gauche fenêtre de visualisation : "
    ))
sup_droit = int(
    input(
        "Valeurs coordonnées bord supérieur droit fenêtre de visualisation : ")
)
longueur = int(input("longueur segment de pavé avant déformation : "))
col1 = int(input("nom de la couleur 1 blue : "))
col2 = int(input("nom de la couleur 2 black: "))
col2 = int(input("nom de la couleur 2 black: "))
centre = int(input(X0, Y0,
                   Z0))  # coordonnées du centre de la sphère de déformante
r = int(input("rayon de la sphère de déformation : "))
turtle.getcanvas().postscript(
    file="pavage.eps"
)  # enregistrer l'image du pavage dans le fichier "pavage.eps"
turtle.done()

# GAEL, pour les données à rentrer, voir le mail que j'ai envoyé
Пример #29
0
			print("no")
			return(False)
def printTime():
    #timer function:
    global timer
    turtle.clear()
    turtle.write(timer,font=("Courier",20,"normal"))
    timer=timer-1
def movearound(event):

	X1 = (event.x - screen_width - 75)
	Y1 = screen_height - event.y
	MY_HEAD.move_head(X1,Y1)


turtle.getcanvas().bind("<Motion>", movearound)
turtle.listen()
def check_click():
	print(xclick, " ", yclick)
	if xclick >= -75 and xclick <= 75 and yclick > 0 and yclick <= 35:
		turtle.clear()
		screen.bgcolor("light blue")
		turtle.shape("ma8ah.gif")
		goto(-300,screenMaxY-50)
		turtle.stamp()
		RUNNING=True
		
		while RUNNING==True and timer>-1:
			global b
			stop=True
			c=0
Пример #30
0
def move_around():
    x_coordinate = turtle.getcanvas().winfo_pointerx() - screen_width * 2
    y_coordinate = screen_height * 1.4 - turtle.getcanvas().winfo_pointery()
    my_ball.goto(x_coordinate, y_coordinate)
    my_ball.x = x_coordinate
    my_ball.y = y_coordinate
Пример #31
0
from turtle import Turtle
import turtle
import random
import math
turtle.tracer(0)
SCREEN_WIDTH = turtle.getcanvas().winfo_width() / 2
SCREEN_HEIGHT = turtle.getcanvas().winfo_height() / 2
colors = ["Black", "Red", "Green", "Orange", "Yellow"]
turtle.listen()
BALLS = []
score = 0


class Ball(Turtle):
    def __init__(self, radius, color, speed, dx, dy, x, y, player):
        Turtle.__init__(self)
        SCREEN_WIDTH = turtle.getcanvas().winfo_width() / 2
        SCREEN_HEIGHT = turtle.getcanvas().winfo_height() / 2
        self.shape('circle')
        self.radius = radius
        self.shapesize(self.radius / 10)
        self.color(color)
        self.penup()
        self.speed(0)
        self.dx = dx / 10
        self.dy = dy / 10
        self.goto(x, y)
        self.speed(speed)
        self.player = player

    def move(self):
Пример #32
0
import turtle
import time
import random
from ind_proj import Ball
import math

turtle.colormode(255)
turtle.tracer(0)
turtle.hideturtle()
newscore = turtle.clone()
score = 0
turtle.bgpic('fireandwater.gif')

RUNNING = True
SLEEP = 0.0077
SCREEN_WIDTH = turtle.getcanvas().winfo_width() / 2
SCREEN_HEIGHT = turtle.getcanvas().winfo_height() / 2

MY_BALL = Ball(0, 0, 0, 0, 21, 'red')

NUMBER_OF_BALLS = 6
MINIMUM_BALL_RADIUS = 10
MAXIMUM_BALL_RADIUS = 25
MINIMUM_BALL_DX = -2
MAXIMUM_BALL_DX = 2
MINIMUM_BALL_DY = -2
MAXIMUM_BALL_DY = 2

BALLS = []
for i in range(NUMBER_OF_BALLS):
    x = random.randint(int(-SCREEN_WIDTH + MAXIMUM_BALL_RADIUS),
Пример #33
0
def tscheme_screen_height():
    """Screen height in pixels of the current size (default 1)."""
    return turtle.getcanvas().winfo_height() // tscheme_pixel.size
Пример #34
0
def movearound():
    xcor = turtle.getcanvas().winfo_pointerx() - screen_width
    ycor = screen_height - turtle.getcanvas().winfo_pointery()
    my_ball.goto(xcor, ycor)
Пример #35
0
from turtle import *
import turtle
import random

#sqrt ( x2-x1 square ) + ( y2-y1 square)
RUNNING = True
SLEEP = 0.0077
SCREEN_WIDTH = turtle.getcanvas().winfo_width() / 2
SCREEN_HIGHT = turtle.getcanvas().winfo_height() / 2


class ball(Turtle):
    def __init__(self, x, y, dx, dy, r, color):
        Turtle.__init__(self)
        turtle.pu()
        self.dx = dx
        self.dy = dy
        self.r = r
        self.shapesize(r / 10)
        self.goto(x, y)
        self.color(color)

    def move(self, width, height):
        current_x = self.xcor()
        new_x = current_x + dx
        current_y = self.ycor()
        new_y = current_y + dy
        right_side_ball = new_x + r
        left_side_ball = new_x - r
        top_side_ball = new_y + r
        bottom_side_ball = new_y - r
def tscheme_screen_width():
    return turtle.getcanvas().winfo_width() // tscheme_pixel.size
Пример #37
0
def main():
    """The entry point of the program."""
    # parse command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("--no-export",
                        action="store_true",
                        help="Don't export an .eps file of the drawing")
    parser.add_argument(
        "--fast",
        action="store_true",
        help="Add triangles directly to the Tkinter canvas for speed")
    parser.add_argument("--birds-eye",
                        action="store_true",
                        help="Show a bird's eye view of the entire terrain")
    parser.add_argument("--random-terrain",
                        action="store_true",
                        help="Use a random seed for the terrain heightmap")
    parser.add_argument(
        "--random-color-offset",
        action="store_true",
        help="Use a random seed for the color offset heightmap")
    args = parser.parse_args()

    # set up turtle parameters
    print("Setting up...")
    turtle.setup(9999, 9999)
    win_scale = min(turtle.window_width() // 22, turtle.window_height() // 17)
    turtle.setup(win_scale * 22,
                 win_scale * 17)  # the largest 11x8.5 window possible
    turtle.title("Submission by Quinn Tucker")
    turtle.tracer(0, 0)
    turtle.setundobuffer(None)
    turtle.hideturtle()
    turtle.penup()

    # fill the background with the sky gradient
    print("Filling the sky...")
    fill_sky_gradient(256, 0.58)

    # set up the lights and camera
    lights = [
        #DirectionalLight(SUNLIGHT_DIRECTION, SUNLIGHT_COLOR, dot_clip=0.0),
        DirectionalLight(AMBIENT_LIGHT_DIRECTION,
                         AMBIENT_LIGHT_COLOR,
                         dot_clip=-0.0),
    ]
    if args.birds_eye:
        camera = Camera((0, 6.0, -2.4),
                        math.pi * 0.34,
                        0,
                        0,
                        zoom=3.4,
                        fog_factor=0,
                        lights=lights,
                        fast_draw=args.fast)
    else:
        camera = Camera((0, 0.07, -0.001),
                        0,
                        0,
                        0,
                        zoom=1.2,
                        fog_factor=FOG_FACTOR,
                        lights=lights,
                        fast_draw=args.fast)

    # generate and draw the terrain
    print("Generating terrain...")
    if args.random_color_offset:
        color_offset_seed = random.getrandbits(32)
        print(f"    Color offset seed = {color_offset_seed}")
    else:
        color_offset_seed = 3038607546
    random.seed(color_offset_seed)
    color_offset = Terrain(recursion_depth=9, noise_depth=4, scale=0.35)

    if args.random_terrain:
        terrain_seed = random.getrandbits(32)
        print(f"    Terrain seed = {terrain_seed}")
    else:
        terrain_seed = 129477298
    random.seed(terrain_seed)
    terrain = Terrain(recursion_depth=9,
                      noise_depth=7,
                      scale=0.10,
                      snow_height=0.025,
                      tree_height=-0.015,
                      color_offset_heightmap=color_offset)

    terrain.draw(camera)
    print("Updating the screen...")
    turtle.update()

    # export the drawing to a file
    if not args.no_export:
        OUTPUT_FILE = "output.eps"
        print(f"Exporting {OUTPUT_FILE}...")
        turtle.getcanvas().postscript(file=OUTPUT_FILE,
                                      colormode="color",
                                      pagewidth="11i")

    # wait for the user to close the window
    print("Done!")
    turtle.mainloop()
def tscheme_screen_height():
    return turtle.getcanvas().winfo_height() // tscheme_pixel.size
Пример #39
0
    t = t + 1
    turtle.forward(Vsnake)
    turtle.stamp();

    if cherry > 0:
        cherry = cherry - 1
    else:
        turtle.clearstamps(1)


    turtle.ontimer(move, 100)
turtle.ontimer(move, 100)

def callback(event):
    global cherry
    print event.x, event.y
    #cherry = 1


canvas = turtle.getcanvas()
canvas.bind('<Button-1>', callback)

wn.onkey(lambda: turtle.setheading(90), 'Up')
wn.onkey(lambda: turtle.setheading(180), 'Left')
wn.onkey(lambda: turtle.setheading(0), 'Right')
wn.onkey(lambda: turtle.setheading(270), 'Down')
wn.listen()


#turtle.exitonclick()
turtle.done()
Пример #40
0
from ball import Ball
import tkinter as tk
from tkinter import simpledialog
turtle.listen()
turtle.tracer(0, 0)
turtle.hideturtle()
turtle.bgpic("sea.gif")
colors = [
    "blue", "red", "green", "yellow", "black", "white", "orange", "purple",
    "hot pink", "aquamarine", "crimson"
]  #list of colors the turtle can be
Running = True
Sleep = 0.0077
score = 0
h_scor = 0
screen_w = turtle.getcanvas().winfo_width() // 2
screen_h = turtle.getcanvas().winfo_height() // 2
turtle.penup()
turtle.goto(screen_w, screen_h)
turtle.pensize(5)
for i in range(4):  #drawing a square
    turtle.right(90)
    turtle.pendown()
    turtle.forward(screen_w * 2)
turtle.penup()
turtle.color(random.choice(colors))
turtle.goto(-100, 450)
turtle.write("Welcome!",
             move=False,
             align="left",
             font=("Arial", 24, "normal"))
def tscheme_screen_width():
    """Screen height in pixels of the current size (default 1)."""
    return turtle.getcanvas().winfo_height() // tscheme_pixel.size
Пример #42
0
def move(offset_x, offset_y):

    canvas = turtle.getcanvas() # `turtle`, not `t`
    for element_id in canvas.find_all():
        canvas.move(element_id, offset_x, offset_y)