def show_goal_posts(self, goal_posts):
     for p in goal_posts:
         turtle.color("#FFFF00")
         turtle.setposition(p[0], p[1])
         turtle.shape("circle")
         turtle.stamp()
         turtle.update()
示例#2
0
 def show_robot(self, robot):
     turtle.color("green")
     turtle.shape('turtle')
     turtle.setposition(*robot.xy)
     turtle.setheading(robot.h)
     turtle.stamp()
     turtle.update()
    def show_sharks(self, sharks):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        turtle.clearstamps()
        draw_cnt = 0
        px = {}
        for shark in sharks:
            draw_cnt += 1
            shark_shape = 'classic' if shark.tracked else 'classic'
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 0:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x = int(shark.x * self.one_px)
                scaled_y = int(shark.y * self.one_px)
                scaled_xy = scaled_x * 10000 + scaled_y
                turtle.color(shark.color)
                turtle.shape(shark_shape)
                turtle.resizemode("user")
                turtle.shapesize(1.5,1.5,1)
                if not scaled_xy in px:
                    px[scaled_xy] = 1
                    turtle.setposition(*shark.xy)
                    turtle.setheading(math.degrees(shark.h))
                    turtle.stamp()
 def show_shark(self, shark):
     turtle.color(shark.color)
     turtle.shape('turtle')
     turtle.setposition(*shark.xy)
     turtle.setheading(math.degrees(shark.h))
     turtle.stamp()
     turtle.update()
示例#5
0
def drawLines(line_arr):
    turt = turtle.Turtle()
    turtle.shape("blank")
    # draws each line in the line_arr
    for line in line_arr:
        draw_single_line(line, turt)
    turtle.done()
示例#6
0
 def show_robot(self, robot):
     turtle.color("green")
     turtle.shape('turtle')
     turtle.setposition([robot.x + self.width / 2, robot.y + self.height / 2])
     turtle.setheading(robot.theta / pi * 180.0)
     turtle.stamp()
     turtle.update()
    def show_particles(self, particles):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        # turtle.clearstamps()
        turtle.shape('tri')

        draw_cnt = 0
        px = {}
        for p in particles:
            draw_cnt += 1
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x1 = int(p.x1 * self.one_px)
                scaled_y1 = int(p.y1 * self.one_px)
                scaled_xy1 = scaled_x1 * 10000 + scaled_y1
                if not scaled_xy1 in px:
                    px[scaled_xy1] = 1
                    turtle.setposition(*p.xy1)
                    turtle.setheading(math.degrees(p.h))
                    turtle.color("Red")
                    turtle.stamp()

                    turtle.setposition(*p.xy2)
                    turtle.setheading(math.degrees(p.h))
                    turtle.color("Blue")
                    turtle.stamp()
示例#8
0
def drawCurr(currX, currY, nextX, nextY, state):
	if state == 1:
		turtle.color("red")
	else:
		turtle.color("blue")
	turtle.shape("turtle")
	startX = 0 
	startY = 0
	if(state == 1):
		startX = initX1
		startY = initY2
	else:
		startX = initX2
		startY = initY2
	prev_x_coord = startX + square_len * currY + square_len/2
	prev_y_coord = startY - square_len * currX - square_len/2

	turtle.penup()
	turtle.goto(prev_x_coord, prev_y_coord)
	
	next_x_coord = startX + square_len * nextY + square_len/2
	next_y_coord = startY - square_len * nextX - square_len/2
	
	turtle.pendown()
	if next_x_coord > prev_x_coord:
		# move right
		turtle.goto(next_x_coord, prev_y_coord)
		# move down
		turtle.goto(next_x_coord, next_y_coord)
	else:
		# move down
		turtle.goto(prev_x_coord, next_y_coord)
		# move left
		turtle.goto(next_x_coord, next_y_coord)
	turtle.penup()
示例#9
0
def main():
    import turtle
    turtle.forward(0)
    turtle.shape("turtle")
    turtle.color("teal")
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    turtle.left(90)  
    
    import turtle
    turtle.forward(0)
    turtle.color("red")
    turtle.forward(50)
    turtle.left(90)
    turtle.color("orange")
    turtle.forward(50)
    turtle.left(90)
    turtle.color("yellow")
    turtle.forward(50)
    turtle.left(90)
    turtle.color("green")
    turtle.forward(50)
    turtle.left(90) 
示例#10
0
def drawPaintBoard():
	turtle.shape("triangle")
	turtle.penup()
	turtle.color("red")
	fillRect(0 - width,0 + height,30 -width,30 +height)
	turtle.color("blue")
	fillRect(30-width,height,60-width,30+height)
	turtle.color("#000000")
	drawRect(width,height,width-30,30+height)
	drawRect(width-30,height,width-60,height+30)
	turtle.penup()
	turtle.goto(width-15,height)
	turtle.pendown()
	turtle.circle(15)
	fillRect(width-60,height,width-90,height+30)
	drawRect(width-90,height,width-120,height+30)
	turtle.penup()
	turtle.goto(width-105,height)
	turtle.pendown()
	turtle.begin_fill()
	turtle.circle(15)
	turtle.end_fill()
	turtle.penup()
	drawRect(-15,height,15,height+30)
	turtle.goto(0,height)
	drawCursor()
	drawEraser()
	turtle.color("blue")
 def show_robot(self, robot):
     turtle.color("blue")
     turtle.shape('square')
     turtle.setposition(*robot.xy)
     turtle.setheading(math.degrees(robot.h))
     turtle.stamp()
     turtle.update()
示例#12
0
    def show_particles(self, particles):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        turtle.clearstamps()
        turtle.shape('tri')

        # Particle weights are shown using color variation
        show_color_weights = 1 #len(weights) == len(particles)
        draw_cnt = 0
        px = {}
        for i, p in enumerate(particles):
            draw_cnt += 1
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x = int(p.x * self.one_px)
                scaled_y = int(p.y * self.one_px)
                scaled_xy = scaled_x * 10000 + scaled_y
                if not scaled_xy in px:
                    px[scaled_xy] = 1
                    turtle.setposition([p.x + self.width / 2, p.y + self.height / 2])
                    turtle.setheading(p.theta / pi * 180.0)
                    if(show_color_weights):
                        weight = p.w
                    else:
                        weight = 0.0
                    turtle.color(self.weight_to_color(weight))
                    turtle.stamp()
示例#13
0
def changeShape():
	global shapeList
	global currentShape
	turtle.shape(shapeList[currentShape])
	if currentShape >= len(shapeList)-1:
		currentShape = 0
	else:
		currentShape += 1
示例#14
0
 def show_mean(self, x, y, confident=False):
     if confident:
         turtle.color("#00AA00")
     else:
         turtle.color("#cccccc")
     turtle.setposition(x, y)
     turtle.shape("circle")
     turtle.stamp()
示例#15
0
    def show_particles(self, particles):
        turtle.shape('dot')

        for p in particles:
            turtle.setposition(*p.xy)
            turtle.setheading(p.h)
            turtle.color(self.weight_to_color(p.w))
            turtle.stamp()
示例#16
0
    def addBodyPart(self):
        if (self.currentBodyPart < 7) :
            self.currentBodyPart += 1

            self.image = "../hangman" + str(self.currentBodyPart) + ".gif"

            self.screen.addshape(self.image)
            turtle.shape(self.image)
示例#17
0
	def draw(self):
		'''
		Draws the object at its current (x, y) coordinates.
		'''
		turtle.goto(self.x, self.y)
		turtle.seth(self.heading())
		turtle.shape(self.shape)
		turtle.color(self.color)
		return turtle.stamp()
示例#18
0
文件: spiro.py 项目: diopib/pp
def main():
    # use sys.argv if needed
    print('generating spirograph...')
    # create parser
    descStr = """This program draws spirographs using the Turtle module. 
    When run with no arguments, this program draws random spirographs.
    
    Terminology:

    R: radius of outer circle.
    r: radius of inner circle.
    l: ratio of hole distance to r.
    """
    parser = argparse.ArgumentParser(description=descStr)
  
    # add expected arguments
    parser.add_argument('--sparams', nargs=3, dest='sparams', required=False, 
                        help="The three arguments in sparams: R, r, l.")
                        

    # parse args
    args = parser.parse_args()

    # set to 80% screen width
    turtle.setup(width=0.8)

    # set cursor shape
    turtle.shape('turtle')

    # set title
    turtle.title("Spirographs!")
    # add key handler for saving images
    turtle.onkey(saveDrawing, "s")
    # start listening 
    turtle.listen()

    # hide main turtle cursor
    turtle.hideturtle()

    # checks args and draw
    if args.sparams:
        params = [float(x) for x in args.sparams]
        # draw spirograph with given parameters
        # black by default
        col = (0.0, 0.0, 0.0)
        spiro = Spiro(0, 0, col, *params)
        spiro.draw()
    else:
        # create animator object
        spiroAnim = SpiroAnimator(4)
        # add key handler to toggle turtle cursor
        turtle.onkey(spiroAnim.toggleTurtles, "t")
        # add key handler to restart animation
        turtle.onkey(spiroAnim.restart, "space")

    # start turtle main loop
    turtle.mainloop()
示例#19
0
 def __init__(self, title="Game of Life", dimension=(1200,800), speed='slow', dotsize=10):
     """  initialze the turtle object  """
     self.dotsize = dotsize
     w, h = dimension
     turtle.setup(w, h, 0,0)
     turtle.title(title)
     turtle.speed(speed)
     turtle.shape('blank')
     turtle.Turtle.__init__(self)
示例#20
0
def draw_square(turtle, size):
	turtle.shape("triangle");
	turtle.speed(10);
	turtle.color("white");

	for i in range(0, 4):
		turtle.forward(size);
		turtle.right(90);

	turtle.right(10);
示例#21
0
 def render(self):
     turtle.up()
     w=turtle.window_width()
     self.dist=w/len(self.string)
     turtle.back(w/2)
     turtle.shape("turtle")
     for c in self.string:
         self.draw(c)
     turtle.hideturtle()
     turtle.exitonclick()        
    def show_attraction_point(self, att):
        turtle.color('black')
        turtle.shape('circle')
        turtle.fillcolor("")
        turtle.resizemode("user")
        turtle.shapesize(1.5, 1.5, 1)

        turtle.setposition(att)
        turtle.setheading(0)
        turtle.stamp()
        turtle.update()
示例#23
0
 def show_path(self, path):
     turtle.color("red")
     turtle.shape('dot')
     for x,y in path:
         nb_y = self.height - y - 1
         scaled_x = int(x * self.one_px)
         scaled_y = int(nb_y * self.one_px)
         turtle.setposition(x, nb_y)
         turtle.down()
     turtle.up()
     turtle.update()
示例#24
0
def initialisePostLoad(path):
    """See: initialise method: same process without screen resolution process

    Adds extra 'title' functionality, displaying the name of the loaded file as
    the title.
    """
    turtle.title(path)
    turtle.shape("turtle")
    turtle.color("black")
    turtle.speed(7)
    turtle.pendown()
示例#25
0
def render_with_turtle():
    turtle.pensize(pen_size)
    turtle.speed(0)
    turtle.shape("turtle")
    for y in range(-canvas_half, canvas_half, pen_size):
        turtle.penup()
        turtle.setpos(-canvas_half, y)
        turtle.pendown()
        for x in range(-canvas_half, canvas_half, pen_size):
            turtle.pencolor(pixel_color(x, y))
            turtle.forward(pen_size)
    wait()
示例#26
0
 def draw_vertex(self,  domain_name, domain ):
    if len(domain) == 1:
       shape_name = self.colors[ domain[0] ]
    else:
       shape_name = "uncolored"
    
    if shape_name != self.previous_color[domain_name]:
       self.previous_color[domain_name] = shape_name
       position = tuple(map(lambda x: x+0.4, self.positions[domain_name]))
       turtle.shape( shape_name )
       turtle.setposition( position )
       turtle.stamp()
示例#27
0
def nyg(n):
    n=int(n)
    import turtle
    turtle.shape('turtle')
    turtle.speed('fastest')
    turtle.left(180-(180*(n-2)/(2*n)))
    for i in range(n):
        turtle.forward(10*n)
        turtle.left(180-(180*(n-2)/n))
    turtle.right(180-(180*(n-2)/(2*n)))
    turtle.penup()
    turtle.forward(3.3*n)
    turtle.pendown()
示例#28
0
def main():
    turtle.shape("blank")
    p1 = Point(0, 0)
    p2 = Point(100, 0)
    p3 = Point(50, 50 * math.sqrt(3))
    l1 = Line(p1, p3)
    l2 = Line(p3, p2)
    l3 = Line(p2, p1)
    prev = [l1, l2, l3]
    for i in range(0, 5):
        prev = iteration(prev)

    drawLines(prev)
示例#29
0
def disp(A, cellsize = 1 / 10.5):
    turtle.clear()
    turtle.shape("square")
    turtle.penup()
    turtle.speed(0)
    turtle.shapesize(0.5, 0.5, 1)
    turtle.ht()
    top = len(A) / cellsize
    left = -len(A[0]) / cellsize
    for r in range(len(A)):
        for c in range(len(A[r])):
            if A[r][c]: 
                turtle.goto(c * 10.5 + left, top - r * 10.5)
                turtle.stamp()
示例#30
0
 def tortue_mini_spirale(self, debu1, debu2):
     turtle.shape("turtle")
     for pas in range(debu1, debu2, 2):
         turtle.forward(pas)
         turtle.right(pas)
示例#31
0
import random as r    #랜덤 함수 불러오기
import turtle as t    #거북이 함수 불러오기
t.shape("turtle")     #모양 거북이로 바꾸기

#사각형 그리기
t.penup()           #거북이 꼬리들기
t.setx(-250)        #거북이의 x좌표를 -250으로 설정
t.sety(250)         #거북이의 y좌표를 250으로 설정
t.pendown()         #거북이 꼬리내리기    
t.pensize(2)

for i in range(4) :     #4번 반복
    t.forward(500)      #앞으로 500픽셀 전진
    t.right(90)         #오른쪽으로 90도 회전     

t.penup()               #원점으로 오기
t.setx(100)             #거북이 x좌표를 100으로 설정
t.sety(50)              #거북이 y좌표를 50으로 설정
t.pendown()    

for i in range(4) :    #장애물 그리기
    t.forward(100)     #한 변이 100픽셀인 사각형을 그린다
    t.right(90)

t.penup()
t.home()       


t.right(r.randrange(0,360))     #출발 각 랜덤지정

while True :                       #무한 반복
up()
#delay(10)
speed(0)
bgcolor("white")

fd(270)
lt(90)
down()
begin_poly()
draw_7_shape(270, 190)
lt(90)
fd(380)
lt(90)
draw_7_shape(190, 110)
lt(90)
fd(240)
lt(90)
draw_7_shape(110, 20)
#sleep(5)
end_poly()

spir = get_poly()
register_shape("spiral", spir)
shape("spiral")
reset()
speed(0)
fillcolor("black")
while True:
    lt(2)
#done()
示例#33
0
def draw():
    turtle.ht()
    turtle.shape("turtle")
    turtle.speed(0)  # make the turtle go as fast as possible
    drawPhyllotacticPattern(200, 160, 137.508, 4, 10)
import turtle
import pandas

data = pandas.read_csv("50_states.csv")
all_states = data.state.to_list()

# print(states_50)
screen = turtle.Screen()
screen.title("U.S States Game")

image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
guess_states = []

while len(guess_states) < 50:
    answer_state = screen.textinput(
        title=f"{len(guess_states)}/50 the State",
        prompt="What's another state's name? ".title())
    if answer_state == "Exit":
        missed_state = []
        for state in all_states:
            if state not in guess_states:
                missed_state.append(state)

        new_data = pandas.DataFrame(missed_state)
        new_data.to_csv("new_state_to_learn.csv")

        break
    if answer_state in all_states:
        guess_states.append(answer_state)
import turtle

turtle.shape("turtle")
turtle.color("thistle")
turtle.speed(.5)


def square():
    for i in range(4):
        turtle.forward(100)
        turtle.right(90)


for i in range(55):
    square()
    turtle.right(5)

turtle.exitonclick()
示例#36
0
	def draw(self):
		tk.shape('circle')
		tk.shapesize(self.__major, self.__minor, 1)
		tk.color("orange")
		tk.exitonclick()
示例#37
0
# Makes the turtle visible
turtle.showturtle()
turtle.st()

# Tells you if your turtle is visible or not
# Returns true is visible
turtle.isvisible()

# ------------------------------------------------

#Turtle Appearance

# Sets the turtle shape to a given, valid shapename in the form of a string
# If there is no given shapename, then it returns the current turtle shape
turtle.shape("triangle")
turtle.shape()

# Chanes the size of the turtle; if no string is given, then it returns the current resize mode
# "auto": changes the turtle corresponding to the pensize
# "user": changes the turtle according to the stretch factor and outline width
# "noresize": no change is made to the turtle appearance
turtle.resizemode("auto")

# Returns or sets the pen's attributes (x/y stretchfactors and/or outline)
# First value is the stretch width, second is the stretch len, and third is the outline; all values are positive
# Either method works
turtle.shapesize(2, 3, 6)
turtle.turtlesize()

示例#38
0
# -*- coding: utf-8 -*-
# author: ColinPython_榴莲老师
# 关注微信公众号:“ 青联科创 ”获得等多有趣代码教程
# 日期:2020-4-27,使用的工具:PyCharm,文件名:绘制五角星

# 做一个海龟画图大全,缩短turtle为t
import turtle as t
import time

# 定义控制面板函数
# c = t.textinput('想画什么', '输入数字,0查看菜单')
t.color("brown", "yellow")  # 定义默认画笔颜色red,填充颜色黄色
t.shape('turtle')  # 定义画笔造型为小海龟
t.screensize(700, 500, "silver")  # 银色700*500画布
t.speed(10)  # 画笔速度,0-10,10最快


# 2.五角星
def pentagram(a):
    t.hideturtle()
    t.color("red")
    t.begin_fill()
    for i in range(5):
        t.fd(a)
        t.right(144)  # 五角星的角度
    t.end_fill()


pentagram()
t.done()
示例#39
0
import turtle
turtle.shape('classic')


def square(x, y, a):
    turtle.penup()
    turtle.goto(x - a / 2, y - a / 2)
    turtle.pendown()
    for i in 0, 2, 3, 4:
        turtle.forward(a)
        turtle.left(90)
    turtle.penup()


square(0, 0, 100)
turtle.getscreen()._root.mainloop()
示例#40
0
def displayBanner(banner, position):
    the_turtle = turtle.getturtle()
    turtle.setposition(position[0], position[1])
    turtle.shape(banner)
    turtle.stamp()
示例#41
0
import turtle as t
window = t.Screen()
t.reset()
t.shape("turtle")
t.bgcolor("black")
t.speed(100)
t.pensize(2)
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
for i in range(360):
    t.pensize(i / 100 + 1)
    t.color(colors[i % len(colors)])
    t.forward(i)
    t.left(59)
t.exitonclick()
示例#42
0

class Bouge_Tortue():
    def tortue_carre(self, var1, var2):
        for i in range(var1, var2):
            turtle.forward(50)
            turtle.left(90)

    def tortue_mini_spirale(self, debu1, debu2):
        turtle.shape("turtle")
        for pas in range(debu1, debu2, 2):
            turtle.forward(pas)
            turtle.right(pas)


"""
# tout le code ci-dessous est fait pour faire comprendre 
# l'instantiation, entre autres, et comment cette instantiation peut-être utilisé 
# dans une boucle.

# le shape permet d'avoir un format de tortue 

turtle.shape("turtle")

# instantiation de la classe
			
varia1 = Bouge_Tortue()


# on utilise les deux méthodes , pour avoir une automatisation de dessin.
# Pour info, chaque nouveau dessin commence là ou finit l'ancien.
示例#43
0
import turtle
import pandas

#INITIALIZATION
screen = turtle.Screen()
screen.title("U.S. States Game")
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)  #CHANGES THE SHAPE OF THE SCREEN


def get_coordinates(state):
    '''Returns coordinates for guessed state'''
    global data
    state_values = data[data.state ==
                        state]  #GETS THE DATAS FOR THE GUESSED STATE
    return (int(state_values.x), int(state_values.y)
            )  # ←ALSO THE RETURN FUNCTION CAN BE LIKE THIS


'''    print(int(state_values.x))
    state_index = state_values.index[0] #GIVES THE INDEX OF THE STATE
    print(state_index)
    state_dict = data[data.state == state].to_dict() #RETURNS THE STATE DATAS IN FORM OF A DICTIONARY
    print(state_dict)
    return (state_dict["x"][state_index], state_dict["y"][state_index])'''
#return (int(state_values.x), int(state_values.y)) #ALSO THE RETURN FUNCTION CAN BE LIKE THIS

data = pandas.read_csv("50_states.csv")
states = data.state.to_list()
score = 0
示例#44
0
from turtle import Turtle, Screen
import turtle
import pandas as p

IMAGE_PATH = r"Working with CSV\Guess the state\blank_states_img.gif"
CSV_PATH = r"Working with CSV\Guess the state\50_states.csv"

screen = Screen()
screen.title("U.S. States Game")
screen.addshape(IMAGE_PATH)
turtle.shape(IMAGE_PATH)

statePosition = Turtle()
statePosition.penup()
statePosition.hideturtle()

data = p.read_csv(CSV_PATH)
stateList = data.state.to_list()
answer_list = []

# xList = data.x.to_list()
# yList = data.y.to_list()

# To get the state coordinates
# def getMouseClickCoor(x,y):
#     print(x,y)
# turtle.onscreenclick(getMouseClickCoor)
# turtle.mainloop()

score = 0
示例#45
0
import turtle
turtle.penup()
turtle.shape("square")
food = turtle.clone()
food.shape("circle")
food.color("orange")
food_pos = [(100, 100), (-100, 100), (-100, -100), (100, -100)]
food_stamps = []

for this_food_pos in food_pos:
    food.goto(this_food_pos[0], this_food_pos[1])
    b = food.stamp()
    food_stamps.append(b)
    turtle.hideturtle()


def make_food():
    min_x = -int(SIZE_X / 2 / SQUARE_SIZE) + 1
    max_x = int(SIZE_X / 2 / SQUARE_SIZE) - 1
    min_y = -int(SIZE_X / 2 / SQUARE_SIZE) - 1
    max_y = int(SIZE_X / 2 / SQUARE_SIZE) + 1

    food_x = random.randint(min_x, max_x) * SQUARE_SIZE
    food_y = random.randint(min_y, max_y) * SQUARE_SIZE

    food.goto(food_x, food_y)
    food_pos.append((food_x, food_y))
    a = food.stamp()
    food_stamps.append(a)
import turtle
turtle.bgcolor("blue")
turtle.pensize(10)
turtle.color("green", "yellow")
turtle.begin_fill()
turtle.speed(1)
turtle.shape("turtle")
turtle.fd(50)
turtle.circle(70)
turtle.shapesize(5, 1)
turtle.settiltangle(90)
turtle.fd(100)
turtle.end_fill()

turtle.shape("square")
turtle.shaptransform(4, -1, 0, 2)
turtle.get_shapepoly()
turtle.end_fill()

turtle.reset()
turtle.resizemode("auto")
turtle.speed(6)
turtle.shape("triangle")
turtle.tilt(90)
turtle.shaptransform()
turtle.end_fill()
示例#47
0
import turtle as t
t.shape("classic")

d = 200
angle = 120

for x in range(3):
    t.forward(d)
    t.left(angle)
示例#48
0
import turtle as t  # turtle이라는 외부 툴을 가져와서 사용, 약어 t로 사용
t.shape('turtle')  # 펜의 모양
t.color('pink')  # 펜의 컬러
for i in range(4):  # 앞으로 100, 오른쪽으로 90도 꺽는 것을 4번 반복
    t.forward(100)
    t.right(90)

t2 = t.Pen()  # 펜 기능을 t2에 부여
t2.shape('turtle')
t2.color('red')
t2.penup()  # 펜을 듬
t2.goto(-200, 100)  # 펜을 해당 좌표로 이동
t2.pendown()
t2.begin_fill()
t2.fillcolor('orange')
t2.circle(25)  # 반지름 기준으로 원을 그림
t2.end_fill()

t3 = t.Pen()
t3.shape('turtle')
t3.shapesize(5)
t3.color('blue')
t3.penup()
t3.goto(100, 100)
t3.pendown()
for i in range(5):
    t3.fd(100)
    t3.right(72)

t4 = t.Pen()
t4.shape('turtle')
示例#49
0
import turtle

turtle.shape('arrow')
turtle.speed('fast')

print('enter height of numbers')
a = int(input())
print('enter a zip code (6 digits)')
x = input()

turtle.penup()
turtle.goto(-3 * a, a // 2)
turtle.pendown()


def draw_zero(a: int):
    for i in range(2):
        turtle.forward(a)
        turtle.right(90)
        turtle.forward(2 * a)
        turtle.right(90)

    turtle.penup()
    turtle.forward(a)
    turtle.pendown()

    turtle.penup()
    turtle.forward(a)
    turtle.pendown()

示例#50
0
import turtle as tr
import math as mth
from random import randint

tr.shape('turtle')


class Ufo:
    def __init__(self,
                 name,
                 x,
                 y,
                 size,
                 color,
                 color_pillars,
                 color_lamps,
                 color_circle,
                 count_pillars,
                 count_lamps,
                 speed=1,
                 pillars_down=True,
                 show_name=True,
                 made_in='Russia',
                 engine_grade='Turbo Ufo'):

        self.name = name
        self.x = x
        self.y = y
        self.size = size
        self.color = color
        self.color_pillars = color_pillars
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import turtle
>>> turtle.Screen()
<turtle._Screen object at 0x00000235157046D0>
>>> turtle.pen()
{'shown': True, 'pendown': True, 'pencolor': 'black', 'fillcolor': 'black', 'pensize': 1, 'speed': 3, 'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 1, 'tilt': 0.0}
>>> turtle.shape('turtle')
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.clear()
>>> 
>>> for i in range(4):
	turtle.forward(200)
	turtle.left(90)

>>> 
示例#52
0
文件: house4.py 项目: Sophie-top/Test
def draw_house(x: int, y: int, width: int, height: int):
    """
        Рисует дом в координатах Х и Y;
        X и Y - координаты средней нижней точки фундамента
        height - полная высота дома( фундамент, крыша и стены)
        width - ширина дома 
    """
    t.shape("turtle")
    t.speed("fast")
    t.penup()

    #счет параметров
    foundation_height = height * 0.05
    foundation_line_color = "#000"
    foundation_fill_color = "#ff0000"
    #стены
    wall_plus_roof_height = height * 0.95
    wall_height = wall_plus_roof_height * 0.62
    wall_line_color = "#000"
    wall_fill_color = "#00ff00"
    #крыша
    roof_height = wall_plus_roof_height * 0.38
    roof_width = width / 2 * 1.3
    roof_line_color = "#000"
    roof_fill_color = "#0000ff"
    print(f"Дом нарисован в X {x} и Y {y}, высотой {height}, шириной {width}")

    def draw_rectangle(x, y, height, width, line_color, fill_color):
        """
        TODO
        """
        t.begin_fill()
        t.color(line_color, fill_color)
        t.goto(x, y)
        t.pendown()
        t.fd(width / 2)
        t.lt(90)
        t.fd(height)
        t.lt(90)
        t.fd(width)
        t.lt(90)
        t.fd(height)
        t.lt(90)
        t.fd(width / 2)
        t.end_fill()
        t.penup()

    def draw_foundation():
        #TODO Выделить цвета в переменные
        #line_color, fill_color
        draw_rectangle(x, y, foundation_height, width, foundation_line_color,
                       foundation_fill_color)

        print(f"Нарисовал фундамент в X {x} и Y {y}")

    def draw_walls():
        #x, y, height,  width, line_color, fill_color
        draw_rectangle(x, y + foundation_height, wall_height, width,
                       wall_line_color, wall_fill_color)

    def draw_roof():
        t.begin_fill()
        t.color(roof_line_color, roof_fill_color)
        t.goto(
            x,
            y + foundation_height + wall_height,
        )
        t.pendown()
        t.fd(roof_width)
        t.goto(x, y + foundation_height + wall_height + roof_height)
        t.goto(x - roof_width, y + foundation_height + wall_height)
        t.goto(x, y + foundation_height + wall_height)
        t.end_fill()
        t.penup()

    draw_foundation()
    draw_walls()
    draw_roof()
示例#53
0
# 1 - Import needed modules 


import turtle
import os, sys


# 2 - Create screen


background = "background_1.gif"

screen = turtle.Screen()
screen.addshape(background)
turtle.shape(background)

bob = turtle.Turtle()
bob.hideturtle()
bob.speed("fastest")

from collections import namedtuple
Button = namedtuple('Button', 'x y w h label')
bob.buttons = []

    
# 3 - Define helper functions


def jump(t, x, y):
    t.penup()
    t.goto(x,y)
示例#54
0
def main():
	windows = turtle.Screen()#????
	windows.bgcolor('blue')#????

	bran = turtle.Turtle()#????
	turtle.shape("turtle")
	turtle.color("red")
	turtle.speed(2)

	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 

	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 

	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(90)
	bran.forward(100)
	bran.right(100) 
	angie = turtle.Turtle()#????
示例#55
0
def tur():
    turtle.shape("turtle")
    turtle.color("skyblue")
    turtle.write("CONNECT THE PYTHONISTAS", font=("궁서체", 18, "bold"))
    turtle.done()
示例#56
0
from turtle import left, right, forward, shape, clear, exitonclick, penup, pendown

shape("turtle")

penup()
left(180)
forward(500)
left(180)
pendown()

for i in range(10):

    left(90)
    forward(100)
    right(90)
    forward(100)
    left(135)
    forward((5000)**(1 / 2))
    left(90)
    forward((5000)**(1 / 2))
    left(90)
    forward(20000**(1 / 2))
    left(135)
    forward(100)
    left(135)
    forward(20000**(1 / 2))
    left(135)
    forward(150)

exitonclick()
示例#57
0
import turtle

turtle.shape('turtle')


class Ball:
    def __init__(self):
        self.x = 0
        self.y = 0
        self.v_x = 1
        self.v_y = 0
        self.a_y = -0.5

    def jump(self):
        self.v_y = 10

    def move(self):
        self.x += self.v_x
        self.v_y += self.a_y
        self.y += self.v_y
        turtle.goto(self.x, self.y)
        if self.y < 0:
            self.jump()


ball_1 = Ball()
while True:
    ball_1.move()
示例#58
0
import turtle as t


def draw_pos(x, y):
    t.clear()
    t.setpos(x, y)
    t.stamp()

    hl = -(t.window_height() / 2)
    tm = 0

    while True:
        d = (9.8 * tm**2) / 2
        ny = y - int(d)

        if (ny > hl):
            t.goto(x, ny)
            t.stamp()
            tm = tm + 0.3
        else:
            break


t.setup(500, 600)
t.shape('circle')
t.shapesize(0.3, 0.3, 0)
t.penup()
s = t.Screen()
s.onscreenclick(draw_pos)
s.listen()
示例#59
0
te = t.Turtle()
te.shape('turtle')
te.color('black')
te.speed(0)
te.up()
te.goto(0, 200)

#먹이
ts = t.Turtle()
ts.color('red')
ts.speed(0)
ts.up()
ts.goto(0, -200)

#나
t.title('Turtle Run 2')
t.setup(500, 500)
t.bgcolor('orange')
t.shape('turtle')
t.speed(0)
t.up()
t.color('white')

t.onkeypress(turn_right, 'Right')
t.onkeypress(turn_left, 'Left')
t.onkeypress(turn_up, 'Up')
t.onkeypress(turn_down, 'Down')
t.onkeypress(start, 'space')
t.listen()
message('Turtle Run 2', '[Space]')
示例#60
-1
def setup(col, x, y, w, s, shape): 
    turtle.up()
    turtle.goto(x,y)
    turtle.width(w)
    turtle.turtlesize(s)
    turtle.color(col)
    turtle.shape(shape)
    turtle.bgpic("assets/dancing-banana.gif")
    turtle.down()
    wn.listen()
    turtle.getscreen()._root.bind_all('<Key>', key_pressed)
    turtle.getscreen()._root.mainloop()