示例#1
0
文件: A_Star.py 项目: mrton/A_Star
def turtlePrint(board, width, height):
    turtle.hideturtle()
    turtle.speed(0)
    turtle.penup()
    turtle.goto(-210, -60)
    turtle.pendown()
    turtle.goto(20*width-210, -60)
    turtle.goto(20*width-210, 20*height-60)
    turtle.goto(-210, 20*height-60)
    turtle.goto(-210, -60)
    turtle.penup()

    for y in xrange(height):
        for x in xrange(width):
            turtle.penup()
            turtle.goto(20*x-200,20*y-50)
            turtle.pendown()
            if board[x][y] is 1:
                turtle.pencolor("green")
                turtle.dot(10)
                turtle.pencolor("black")
            elif board[x][y] is 2:
                turtle.dot(20)
            elif board[x][y] is 3:
                turtle.pencolor("red")
                turtle.dot(10)
                turtle.pencolor("black")
            elif board[x][y] is 8:
                turtle.pencolor("blue")
                turtle.dot()
                turtle.pencolor("black")

    turtle.exitonclick()
示例#2
0
def hang():
	turtle.speed(0)
	if stage[0]==0:
		go_to(-300,0,0)
		turtle.forward(600)
		go_to(-100,0, 90)
		turtle.forward(200)
		turtle.right(90)
		turtle.forward(100)
		turtle.right(90)
		turtle.forward(25)
	elif stage[0]==1:
		go_to(0, 150, 0)
		turtle.circle(12.5)
	elif stage[0]==2:
		go_to(0,150, -90)
		turtle.forward(50)
	elif stage[0]==3:
		go_to(0,140, -45)
		turtle.forward(25)
		go_to(0,140, -135)
		turtle.forward(25)
	elif stage[0]==4:
		go_to(0,100, -45)
		turtle.forward(25)
		go_to(0,100, -135)
		turtle.forward(25)
	stage[0]+=1
	return 0
def polygon(side = 50, angle = None, xstart = None, ystart = None, numberSides = 3, color = 'black', fill = False):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    if angle != None:
        turtle.left(angle)
    
    turtle.penup()
    if fill == True:
        if xstart != None or ystart != None:
            turtle.goto(xstart, ystart)
        else:
            turtle.goto(0, 0)
        turtle.color(color)
        turtle.pendown()
        turtle.begin_fill()
        turtle.circle(side, 360, numberSides)
        turtle.end_fill()
        turtle.penup()
        
    else:
        turtle.goto(xstart, ystart)
        turtle.color(color)
        turtle.pendown()
        turtle.circle(side, 360, numberSides)
        turtle.penup()
    
    return
示例#4
0
    def __init__(self):
        # Janela sobre
        self.janSobre = None


        # Cor de fundo
        self.corFundo = "gray"


        turtle.screensize(1000, 700, self.corFundo)
        turtle.setup(width=1000, height=700)
        turtle.title("cidadeBela - Janela de desenho")


        turtle.speed(0)
        turtle.tracer(4)

        # Definindo variáveis globais
        self._tamPadrao = ""

        # Listas de prédios
        self.predios = ['Casa', 'Hotel']
        self.prediosProc = [ 'hotel', 'hotelInv', 'casa', 'casaInv' ]


        # Sorteando elementos
        self.sorteioPredios    = [["casa", 1], ["hotel", 1]]
        self.sorteioPrediosInv = [["casaInv", 1], ["hotelInv", 1]]


        #  Cores dos prédios
        self.coresHotel = ["076080190", "255255255", "167064057", "153204255", "000090245",
                           "201232098", "255058123", "010056150", "130255255", "255255000",
                           "255000000", "255127042", "000255000", "255170255", "000255170",
                           "212000255", "170255127", "127212255", "255127127", "255212085",
                           "212212255", "255255127", "222202144" ]
        self.coresCasa  = ['209187103', '115155225', '130047006', '255137111', '203229057',
                           '017130100', '025195159', '204057065', '194082255', '092221159',
                           '167045055', '238243030', '069241248', '000156228', '159094040',
                           '048033253', '040209239', '138164253', '190042177', '000122159',
                           '255255255', '253208201', '245228133']
        self.coresLoja  = ['255255255', '253208201', '245228133' ]

        #  Janelas dos prédios
        self.janelasHotel = janelas.janelasHotel
        self.janelasCasa  = janelas.janelasCasa
        self.janelasLoja  = janelas.janelasLoja
        self.janelasTodas = janelas.janelasTodas

        #  Tetos dos prédios
        self.tetosHotel = tetos.tetosHotel
        self.tetosCasa  = tetos.tetosCasa
        self.tetosLoja  = tetos.tetosLoja
        self.tetosTodas = tetos.tetosTodas

        #  Portas dos prédios
        self.portasHotel = portas.portasHotel
        self.portasCasa  = portas.portasCasa
        self.portasLoja  = portas.portasLoja
        self.portasTodas = portas.portasTodas
示例#5
0
def ejes():
    ####################################
    # Ejes Coordenados                 #
    # los ejes x e y van de -150 a 150 #
    ####################################
    turtle.delay(0)
    turtle.ht()
    turtle.speed(0)
    turtle.pencolor('red')
    turtle.down()
    turtle.fd(301)
    turtle.rt(90)
    turtle.fd(1)
    turtle.rt(90)
    turtle.fd(300)
    turtle.lt(90)
    turtle.fd(300)
    turtle.rt(90)
    turtle.fd(1)
    turtle.rt(90)
    turtle.fd(300)
    turtle.lt(90)
    turtle.fd(300)
    turtle.rt(90)
    turtle.fd(1)
    turtle.rt(90)
    turtle.fd(300)
    turtle.lt(90)
    turtle.fd(300)
    turtle.rt(90)
    turtle.fd(1)
    turtle.rt(90)
    turtle.fd(300)
    turtle.up()
    turtle.pencolor('blue')
示例#6
0
	def plot(self, node1, node2, debug=False):
		"""Plots wires and intersection points with python turtle"""
		tu.setup(width=800, height=800, startx=0, starty=0)
		tu.setworldcoordinates(-self.lav, -self.lav, self.sample_dimension+self.lav, self.sample_dimension+self.lav)
		tu.speed(0)
		tu.hideturtle()
		for i in self.index:
			if debug:
				time.sleep(2)   # Debug only
			tu.penup()
			tu.goto(self.startcoords[i][0], self.startcoords[i][1])
			tu.pendown()
			tu.goto(self.endcoords[i][0], self.endcoords[i][1])
		tu.penup()
		if self.list_of_nodes is None:
			intersect = self.intersections(noprint=True)
		else:
			intersect = self.list_of_nodes
		tu.goto(intersect[node1][0], intersect[node1][1])
		tu.dot(10, "blue")
		tu.goto(intersect[node2][0], intersect[node2][1])
		tu.dot(10, "blue")
		for i in intersect:
			tu.goto(i[0], i[1])
			tu.dot(4, "red")
		tu.done()
		return "Plot complete"
示例#7
0
def init_turtle():
    """
    Стартовые настройки для рисования
    """
    turtle.colormode(255)
    turtle.speed(10)
    turtle.pensize(3)
示例#8
0
def main():
  ap = ArgumentParser()
  ap.add_argument('--speed', type=int, default=10,
                  help='Number 1-10 for drawing speed, or 0 for no added delay')
  ap.add_argument('program')
  args = ap.parse_args()

  for kind, number, path in parse_images(args.program):
    title = '%s #%d, path length %d' % (kind, number, path.shape[0])
    print(title)
    if not path.size:
      continue
    pen_up = (path==0).all(axis=1)
    # convert from path (0 to 65536) to turtle coords (0 to 655.36)
    path = path / 100.
    turtle.title(title)
    turtle.speed(args.speed)
    turtle.setworldcoordinates(0, 655.36, 655.36, 0)
    turtle.pen(shown=False, pendown=False, pensize=10)
    for i,pos in enumerate(path):
      if pen_up[i]:
        turtle.penup()
      else:
        turtle.setpos(pos)
        turtle.pendown()
        turtle.dot(size=10)
    _input('Press enter to continue')
    turtle.clear()
  turtle.bye()
示例#9
0
def draw_walk(x, y, speed = 'slowest', scale = 20):
    ''' Animate a two-dimensional random walk.

    Args:
        x       x positions
        y       y positions
        speed   speed of the animation
        scale   scale of the drawing
    '''
    # Reset the turtle.
    turtle.reset()
    turtle.speed(speed)

    # Combine the x and y coordinates.
    walk = zip(x * scale, y * scale)
    start = next(walk)

    # Move the turtle to the starting point.
    turtle.penup()
    turtle.goto(*start)

    # Draw the random walk.
    turtle.pendown()
    for _x, _y in walk:
        turtle.goto(_x, _y)
示例#10
0
def tscheme_speed(s):
    """Set the turtle's animation speed as indicated by S (an integer in
    0-10, with 0 indicating no animation (lines draw instantly), and 1-10
    indicating faster and faster movement."""
    check_type(s, scheme_integerp, 0, "speed")
    _tscheme_prep()
    turtle.speed(s)
示例#11
0
def tree1(argv, x, y):
	lsys_filename1 = argv[1]
	lsys1 = ls.createLsystemFromFile( lsys_filename1 )
	print lsys1
	num_iter1 = int( 3 )
	dist = float( 5 )
	angle1 = float( 22 )
	
	s1 = ls.buildString( lsys1, num_iter1 )
	
	#draw lsystem1
	'''this is my first lsystem
		with filename mysystem1.txt
		with 3 iterations and
		with angle = 45 dist = 10'''
	turtle.tracer(False)
	turtle.speed(50000000)
	turtle.up()
	turtle.goto(0,0)
	turtle.goto(x, y)
	turtle.down()
	turtle.pencolor('White')
	it.drawString( s1, dist, angle1 )
	
	# wait and update
	turtle.update()
示例#12
0
def main():
    while True:
        side = input("Please enter the total length of the figure: ")
        try:
            side = int(side)
        except:
            print('Please enter a valid number.\n')
            continue
        break

    while True:
        id = input("Please enter MSU ID (including the starting letter): ")
        if len(id) == 9 and id[0].isalpha() and all(d.isdigit() for d in id[1:]):
            break
        else:
            print('Please enter a valid MSU ID.\n')
            continue

    turtle.colormode(1.0)
    turtle.speed(0)

    drawQ1(id, side/2)
    drawQ2(id, side/2)
    drawQ3(id, side/2)
    drawQ4(id, side/2)

    time.sleep(20)
    turtle.bye()
示例#13
0
def draw_flower():
    window = turtle.Screen()
    window.bgcolor('blue')

    bobie = turtle.Turtle()
    turtle.speed('0')
    bobie.shape('classic')
    bobie.color('pink')

    anny = turtle.Turtle()
    anny.color('pink')

    for i in range(1,73):
        bobie.forward(100)
        bobie.right(30)
        bobie.forward(100)
        bobie.right(150)
        bobie.forward(100)
        bobie.right(30)
        bobie.forward(100)
        bobie.right(5)

    anny.right(90)
    anny.forward(300)



    window.exitonclick
示例#14
0
   def initialize_plot(self, positions):
      self.positions = positions
      self.minX = minX = min(x for x,y in positions.values())
      maxX = max(x for x,y in positions.values())
      minY = min(y for x,y in positions.values())
      self.maxY = maxY = max(y for x,y in positions.values())
      
      ts = turtle.getscreen()
      if ts.window_width > ts.window_height:
          max_size = ts.window_height()
      else:
          max_size = ts.window_width()
      self.width, self.height = max_size, max_size
      
      turtle.setworldcoordinates(minX-5,minY-5,maxX+5,maxY+5)
      
      turtle.setup(width=self.width, height=self.height)
      turtle.speed("fastest") # important! turtle is intolerably slow otherwise
      turtle.tracer(False)    # This too: rendering the 'turtle' wastes time
      turtle.hideturtle()
      turtle.penup()
      
      self.colors = ["#d9684c","#3d658e","#b5c810","#ffb160","#bd42b3","#0eab6c","#1228da","#60f2b7" ]

      for color in self.colors:         
         s = turtle.Shape("compound")
         poly1 = ((0,0),(self.cell_size,0),(self.cell_size,-self.cell_size),(0,-self.cell_size))
         s.addcomponent(poly1, color, "#000000")
         turtle.register_shape(color, s)
      
      s = turtle.Shape("compound")
      poly1 = ((0,0),(self.cell_size,0),(self.cell_size,-self.cell_size),(0,-self.cell_size))
      s.addcomponent(poly1, "#000000", "#000000")
      turtle.register_shape("uncolored", s)
def rectangle(length = 50, width = 30, x = 0, y = 0, color = 'black', fill = False):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    if fill == True:
        turtle.color(color)
        for i in range(width): 
            turtle.setposition(x, (y+i))
            turtle.pendown()
            turtle.setposition((x+length), (y+i))
            turtle.penup()
    else:
        turtle.penup()
        turtle.goto(x,y)
        turtle.color(color)
        turtle.pendown()
        turtle.forward(length)
        turtle.left(90)
        turtle.forward(width)
        turtle.left(90)
        turtle.forward(length)
        turtle.left(90)
        turtle.forward(width)
        turtle.left(90)
        turtle.penup()

    return
示例#16
0
文件: 30.py 项目: jpbat/freetime
def show():
	turtle.hideturtle()
	turtle.speed(0)
	side = turtle.window_height()/7
	grid(side)
	write(side)
	turtle.exitonclick()
示例#17
0
def turtle_init():
	turtle.ht()
	turtle.up()
	turtle.speed(0)
	turtle.left(90)
	turtle.backward(350)
	turtle.down()
示例#18
0
def main():
    path_data = open('path.txt').read()
    
    print turtle.position()
    turtle.penup()
    turtle.setposition(-400,200)
    turtle.pendown()
    turtle.speed(0)
    turtle.delay(0)
    for c in path_data:
        if c in 'NSEW*':
            if c == 'N':
                turtle.setheading(90)
                turtle.forward(1)
            if c == 'S':
                turtle.setheading(270)
                turtle.forward(1)
            if c == 'E':
                turtle.setheading(0)
                turtle.forward(1)
            if c == 'W':
                turtle.setheading(180)
                turtle.forward(1)
            if c == '*':
                if turtle.isdown():
                    turtle.penup()
                else:
                    turtle.pendown()
示例#19
0
文件: pylsys.py 项目: masterzu/pylsys
    def __init__(self, length=10, angle=90, colors=None, lsystem=None):
        import turtle
        self.length = length
        self.angle = angle
        if colors is None:
            self.colors = ['red', 'green', 'blue', 'orange', 'yellow', 'brown']
        if lsystem is not None:
            self.lsystem(lsystem)

        # draw number
        self.ith_draw = 0

        # origin of next draw
        self.origin = [0, 0]

        # bounding_box
        self._box = 0, 0, 0, 0


        # turtle head north and positive angles is clockwise
        turtle.mode('world')
        turtle.setheading(90)
        turtle.speed(0) # fastest
        turtle.hideturtle()
        turtle.tracer(0, 1)
	
        # set pencolor
        self.pencolor()
示例#20
0
文件: project2.py 项目: gK996/Othello
def drawBoard(b):
    #set up window
    t.setup(600,600)
    t.bgcolor("dark green")
    
    #turtle settings
    t.hideturtle()
    t.speed(0)
    
    num=len(b)
    side=600/num
    xcod=-300
    ycod=-300
    for x in b:
        for y in x:
            if(y> 0):
                drawsquare(xcod,ycod,side,'black')
            if(y< 0):
                drawsquare(xcod,ycod,side,'white')
            if(y==0):
                drawsquare(xcod,ycod,side,'dark green')
            
            xcod=xcod+side
        xcod=-300
        ycod=ycod+side
示例#21
0
def passeio(dim, lado, passos):    
    # Prepara grelha
    turtle.speed(0)
    grelha_2(dim,lado)
    turtle.color('red')
    turtle.home()
    turtle.pendown()
    # Passeio
    turtle.speed(6)
    turtle.dot()
    turtle.showturtle()
    lim_x = lim_y = (dim*lado)//2
    cor_x = 0
    cor_y = 0
    for i in range(passos):
        vai_para = random.choice(['N','E','S','W'])
        if (vai_para == 'N') and (cor_y < lim_y):
            cor_y += lado
            turtle.setheading(90)
            turtle.fd(lado)
        elif (vai_para == 'E') and (cor_x < lim_x):
            cor_x += lado
            turtle.setheading(0)
            turtle.fd(lado)
        elif (vai_para == 'S') and (cor_y > -lim_y):
            cor_y -= lado
            turtle.setheading(270)
            turtle.fd(lado)
        elif (vai_para == 'W') and (cor_x > -lim_x):
            cor_x -= lado
            turtle.setheading(180)
            turtle.fd(lado) 
        else:
            print((vai_para,turtle.xcor(),turtle.ycor()))
            continue
示例#22
0
def turtleProgram():
    import turtle
    import random
    global length
    turtle.title("CPSC 1301 Assignment 4 MBowen") #Makes the title of the graphic box
    turtle.speed(0) #Makes the turtle go rather fast
    for x in range(1,(numHex+1)): #For loop for creating the hexagons, and filling them up
        turtle.color(random.random(),random.random(),random.random()) #Defines a random color
        turtle.begin_fill()
        turtle.forward(length)
        turtle.left(60)
        turtle.forward(length)
        turtle.left(60)
        turtle.forward(length)
        turtle.left(60)
        turtle.forward(length)
        turtle.left(60)
        turtle.forward(length)
        turtle.left(60)
        turtle.forward(length)
        turtle.left(60)
        turtle.end_fill()
        turtle.left(2160/(numHex))
        length = length - (length/numHex) #Shrinks the hexagons by a small ratio in order to create a more impressive shape
    turtle.penup()   
    turtle.goto(5*length1/2, 0) #Sends turtle to a blank spot
    turtle.color("Black")
    turtle.hideturtle()
    turtle.write("You have drawn %d hexagons in this pattern." %numHex) #Captions the turtle graphic
    turtle.mainloop()
示例#23
0
def draw_starrows(row):
    color2 = 1
    color = get_color(color2)
    x = -160
    y = 150
    ## This for loop draws 10 stars for each row above (5 total x 10 = 50).
    for z in range(10):
        x += 15
        turtle.up()
        turtle.color(color)
        turtle.speed(100)
        turtle.setpos(x,row)
        turtle.begin_fill()
        turtle.down()
        turtle.forward(6.154)
        turtle.left(144)
        turtle.forward(6.154)
        turtle.left(144)
        turtle.forward(6.154)
        turtle.left(144)
        turtle.forward(6.154)
        turtle.left(144)
        turtle.forward(6.154)
        turtle.left(144)
        turtle.end_fill()
示例#24
0
def tree(trunkLength,height):
    turtle.speed(1)
    turtle.reset()
    turtle.left(90)
    turtle.pu()
    turtle.backward(200)
    turtle.pd()
    grow(trunkLength,height)
示例#25
0
文件: demo.py 项目: JCGitHubJC/CM4K
def fireworks(pos, color, size, turtle):
	turtle.shapesize(0)
	turtle.goto(pos)
	turtle.color(color)
	for i in range(0, 36):
		turtle.speed(0)
		turtle.fd(size)
		turtle.lt(250)
示例#26
0
def ready(pensize,speed):
    '''
    This function picks the turtle up, orents it north on the canvas, sets the speed fast, and sets the pen to size 2
    '''
    U()
    L(90)
    turtle.speed(speed)
    turtle.pensize(pensize)
示例#27
0
文件: zad3.py 项目: Cube189/WdPPyth
def main(i):
    t.speed('fastest'); t.tracer(1,0); t.colormode(255)

    t.lt(90)
    while (i >= 1):
        drawLineOfSqrs(i)
        i -= 1
    raw_input()
示例#28
0
def main():
    turtle.speed("fastest");
    turtle.color("red");
    penup();
    sety(36);
    for x in range(5):
        write_modmessage2(ycor() - 18, "message.txt");
    done();
示例#29
0
def ready(rad):
    turtle.speed(0)
    turtle.ht()
    turtle.up()
    turtle.goto(0,-rad)
    turtle.down()
    turtle.colormode(1)
    turtle.bgcolor('black')
    turtle.pensize(1.1)
示例#30
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)
示例#31
0
import turtle
turtle.speed("fastest")


def draw_levi(length, d):
    if d == 0:
        turtle.forward(length)
    else:
        draw_levi(length / 2, d - 1)
        turtle.left(90)
        draw_levi(length / 2, d - 1)
        turtle.left(90)
        draw_levi(length / 2, d - 1)
        turtle.right(135)
        draw_levi(length, d - 1)
        turtle.left(135)
        draw_levi(length / 2, d - 1)
        turtle.right(135)
        draw_levi(length, d - 1)
        turtle.left(135)
        draw_levi(length / 2, d - 1)
        turtle.right(135)
        draw_levi(length, d - 1)
        turtle.right(90)
        draw_levi(length, d - 1)
        turtle.right(135)
        draw_levi(length / 2, d - 1)
        turtle.left(135)
        draw_levi(length, d - 1)
        turtle.right(135)
        draw_levi(length / 2, d - 1)
import numpy as np
import turtle as t
from curling_env import curling_env
from DQN_Prioritized_Replay_py import DQN, Replay_buffer, train, plot_curse
import os
import torch 
from torch import nn, optim

LOAD_KEY = True
path = 'param\culing_dqnper.pkl'

t.setup(1000,1000)
t.pensize(5)
t.speed(10)
t.pencolor('purple')
map_scale = 4

# Hyperparameter
learning_rate = 0.001
memory_len = 30000
gamma = 0.9
batch_size = 64
output_size = 4
state_size = 8
replay_len = 2000

epoch_num = 600
max_steps = 300
update_target_interval = 25
replay_time = 50
alpha = 0.6
示例#33
0
def draw_body(piece):
    """
    A series of turtle commands to draw the body, to be executed one at a time.
    """
    def head():
        t.penup()
        t.setpos((175, 225))
        t.pendown()
        t.circle(25)
        t.penup()
        t.setpos((165, 255))
        t.dot()
        t.setpos((185, 255))
        t.dot()

    def body():
        t.penup()
        t.setpos((175, 225))
        t.pendown()
        t.setpos((175, 125))

    def arm1():
        t.penup()
        t.setpos((175, 200))
        t.pendown()
        t.setpos((145, 220))

    def arm2():
        t.penup()
        t.setpos((175, 200))
        t.pendown()
        t.setpos((205, 220))

    def leg1():
        t.penup()
        t.setpos((175, 125))
        t.pendown()
        t.setpos((145, 95))

    def leg2():
        t.penup()
        t.setpos((175, 125))
        t.pendown()
        t.setpos((205, 95))

    def open_mouth():
        t.penup()
        t.setpos((175, 235))
        t.pendown()
        t.dot(10)

    def frown():
        t.penup()
        t.setpos((175, 235))
        t.pendown()
        t.dot(15, 'white')
        t.penup()
        t.setpos((165, 235))
        t.pendown()
        t.left(90)
        t.circle(-10, extent=180)
        t.penup()

    def smile():
        t.penup()
        t.setpos((175, 235))
        t.pendown()
        t.dot(15, 'white')
        t.penup()
        t.setpos((165, 240))
        t.pendown()
        t.right(90)
        t.circle(10, extent=180)
        t.penup()

    def deadeyes():
        t.register_shape('dead', ((-5, -5), (-0.01, 0), (-5, 5), (0, 0.01),
                                  (5, 5), (0.01, 0), (5, -5), (0, -0.01)))
        t.penup()
        t.setpos((165, 255))
        t.dot(15, 'white')
        t.shape('dead')
        stamp1 = t.stamp()
        t.setpos((185, 255))
        t.dot(15, 'white')
        stamp2 = t.stamp()

    if piece == 0:
        t.speed(10)
    else:
        t.speed(3)
    parts = [
        'head()', 'body()', 'arm1()', 'arm2()', 'leg1()', 'leg2()',
        'open_mouth()', 'deadeyes()', 'frown()', 'smile()'
    ]
    piece = piece - 1
    eval(parts[piece])
示例#34
0
# turtle colorufull spider web
# L
# 1.9.2012
# python workshop opentechschool berlin

import turtle
from random import randint

size = 5
circles = 20
turtle.speed(10000)

turtle.colormode(255)


def move(length, angle):
    turtle.right(angle)
    turtle.forward(length)


def hex():
    turtle.pendown()
    turtle.color(randint(0, 255), randint(0, 255), randint(0, 255))
    turtle.begin_fill()
    for i in range(6):
        move(size, -60)
    turtle.end_fill()
    turtle.penup()


# start
示例#35
0
main.bind('c', movement.circle)
main.mainloop()

########################################################

import turtle
colors = {"green": "#42692f", "brown": "#765c48"}


def draw_tree(level):
    if level == 0:
        turtle.color(colors["green"])
        turtle.stamp()
        turtle.color(colors["brown"])
    else:
        turtle.pensize(level)
        turtle.forward(30)
        turtle.left(20)
        draw_tree(level - 1)
        turtle.right(40)
        draw_tree(level - 1)
        turtle.left(20)
        turtle.back(30)


turtle.color(colors["brown"])
turtle.speed(0)
turtle.left(90)
scr = turtle.Screen()
draw_tree(5)
scr.exitonclick()
import turtle

turtle.speed(100)
turtle.color("blue")


def star(turtle, side):
    for i in range(5):
        turtle.forward(100)
        turtle.right(144)


for i in range(80):
    star(turtle, 50)
    turtle.right(5)

    size = 1.5

turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()

turtle.color("red")

turtle.speed(20)

size += 1

turtle.speed(20)

turtle.speed(20)
示例#37
0
def init():
    """set up the turtle parameters"""
    turtle.reset()
    turtle.shape('turtle')
    turtle.speed('fastest')
    turtle.up()
colors = cycle([
    'red', 'orange', 'yellow', 'blue', 'green', 'purple', 'white', 'violet',
    'indigo', 'silver'
])


def draw_circle(size, angle, shift):
    t.color(next(colors))
    t.begin_fill()
    t.circle(size)
    t.end_fill()
    t.right(angle)
    t.forward(shift)
    t.color(next(colors))
    t.begin_fill()
    for i in range(4):
        t.forward(2 * size)
        t.left(90)
    t.end_fill()
    draw_circle(size + 10, angle + 5, shift + 1)


t.bgcolor('black')
t.speed('fast')
t.pensize(2)

draw_circle(30, 0, 1)

ti.sleep(3)
t.hideturtle()
示例#39
0
import turtle as tr
tr.speed(1000)
tr.shape('turtle')
n = 6
def circle():
    N = 100
    for i in range(N):
        tr.forward(5)
        tr.left(360 / N)
for k in range(n):
    circle()
    tr.left(360 / n)
    
示例#40
0
# SpaceWare by @TokyoEdTech
# Part III : Getting started
# Game Object / Broder / Boundary Checking

import os
import random
import turtle

turtle.speed(0)  # Set the animations sepeed to the maximum
turtle.bgcolor('black')  # Change the background color
turtle.hideturtle()  # hide the default turtle
turtle.setundobuffer(1)  # This saves memory
turtle.tracer(1)  # This speeds up drawing

turtle.register_shape('fishtank.gif')


class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
        turtle.Turtle.__init__(self, shape=spriteshape)
        #self.shape(spriteshape)
        self.speed(0)
        self.penup()
        self.color(color)
        self.goto(startx, starty)
        self.speed = 1

    def move(self):
        self.fd(self.speed)

        # Boundary detection
示例#41
0
        turtle.forward(2)


# 输入表白的语句,默认I Love you
love = 'I Love you,LXJ'
# 输入署名或者赠谁,没有不执行
me = input(' 输入署名或者赠谁,否则给你看,哼!')

# 窗口大小
turtle.setup(width=900, height=500)
# 颜色
turtle.color('red', 'pink')
# 笔粗细
turtle.pensize(3)
# 速度
turtle.speed(1)
# 提笔
turtle.up()
# 隐藏笔
turtle.hideturtle()
# 去到的坐标,窗口中心为0,0
turtle.goto(0, -180)
turtle.showturtle()
# 画上线
turtle.down()
turtle.speed(1)
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
# 调用画爱心左边的顶部
LittleHeart()
示例#42
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Техническое задание:
На основе цветочка из квадратов, сделанного в первой итерации,
нарисовать картину из этого цветочка и солнышка.
Солнышко такое как тут, подойдет https://docs.python.org/3.7/library/turtle.html
В будущем ожидаю увидеть поле из разных цветов. Может, сделать цветок красивее.
"""

import turtle as t

t.penup()
t.goto(-200, 200)
a = abs(t.pos())
t.speed(400)
t.color('red', 'yellow')
t.begin_fill()
i = 0
while i < 12:
    i = i + 1
    t.pendown()
    t.forward(150)
    t.left(150)
    if abs(t.pos()) < 1:
        break
t.end_fill()
t.penup()


def draw_square(color, x=0, y=0):
示例#43
0
# 科赫雪花 Koch Snowflake vision_2

print('####### 科赫雪花 Koch Snowflake #######')
import turtle as t


def k_snow(n, l):
    if n == 0:
        t.fd(l)
    else:
        for i in [0, 60, -120, 60]:
            t.left(i)
            k_snow(n - 1, l / 3.0)


n = eval(input('你想要画出几阶的科赫雪花?\n'))
t.hideturtle()
t.speed(20)
t.pu()
t.goto(-200, 200)
t.pd()

for i in [0, 120, 120]:
    t.right(i)
    k_snow(n, 400)
t.done()
示例#44
0
__author__ = 'student'

import turtle
turtle.speed(20)


def koch(l, n):
    assert n >= 0
    assert l >= 0
    turtle.shape('turtle')
    if n == 0:
        turtle.forward(l)
        return

    for i in range(n):
        koch(l / 3, n - 1)
        turtle.left(60)
        koch(l / 3, n - 1)
        turtle.right(120)
        koch(l / 3, n - 1)
        turtle.left(60)
        koch(l / 3, n - 1)
        return


l = 2000
n = int(input())
koch(l, n)
turtle.mainloop()
print("2) Square")
print("3) Triangle")
shape1=int(input("      CHOICE: "))
print("")
print("HOW MANY DO YOU WANT?;")
many=int(input("      CHOICE: "))
print("")
# Initiate turtle Module
import turtle
t=turtle.Pen()
# IF/ELIF/ELSE statements
if shape1 == 1:
    for x in range(many):
        turtle.bgcolor("cyan")
        turtle.color("magenta" , "yellow")
        turtle.speed(10)
        turtle.pensize(5)
        turtle.begin_fill()
        turtle.circle(200)
        turtle.end_fill()
        turtle.right(45)
elif shape1 == 2:
    for x in range(many):
        turtle.bgcolor("cyan")
        turtle.color("magenta" , "yellow")
        turtle.speed(10)
        turtle.pensize(5)
        turtle.begin_fill()
        turtle.forward(150)
        turtle.right(90)
        turtle.forward(300)