示例#1
0
文件: wordcloud.py 项目: cs10/twitter
def drawCloud(words, num = 20):
    """ Draws a wordcloud with 20 random words, sized by frequency found in 
    the WORDS dictionary. """
    t.reset()
    t.up()
    t.hideturtle()
    topCounts = sorted([words[word] for word in list(words.keys()) if len(word) > 3])
    largest = topCounts[0]
    normalized_counts = {}
    for item in list(words.keys()):
        if len(item) > 3:
            newSize = int(float(words[item]) / largest * 24)
            normalized_counts[item] = newSize
    
    size = t.screensize()
    width_dim = (int(-1 * size[0] / 1.5), int(size[0] / 2))
    height_dim = (int(-1 * size[1] / 1.5), int(size[1] / 1.5))
    

    for item in random.sample(list(normalized_counts.keys()), num):
        t.goto(random.randint(*width_dim), random.randint(*height_dim))
        t.color(random.choice(COLORS))
        try:
            t.write(item, font = ("Arial", int(normalized_counts[item]), "normal"))
        except:
            try:
                t.write(str(item, errors = 'ignore'), font = ("Arial", int(normalized_counts[item]), "normal"))
            except:
                pass
def makeSquare(size, person=None, fill=False):
    origPosition = turtle.pos()
    origHead = turtle.heading()
    turtle.penup()
    goDown(size)
    if(person != None or fill == True):
        if(fill==True or person.affected):
            turtle.begin_fill()
    turtle.pendown()
    goLeft(size)
    goUp(2*size)
    goRight(2*size)
    goDown(2*size)
    goLeft(size)
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.end_fill()
    turtle.penup()
    turtle.goto(origPosition)
    turtle.setheading(origHead)
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.color('black')
        if(person.multipleNotShown == 0):
            turtle.write(str(person.name())+"\n"+probString(person), align="center")
        else:
            turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center")
    turtle.color('blue')
    turtle.penup()
示例#3
0
def main():
    """
    Tous les phase du battleship passe par le main()
    et il sert de boucle principal car il est appelé à
    tous les 0.5 secondes
    """
    if i.phase == "PlaceShip":
        i.placeShip()
    elif i.phase == "Attack": # Nom fictif
        i.attack()
    elif i.phase == "win":
        print('Vous avez gagné!')
        turtle.goto(0,0)
        turtle.pencolor('black')
        turtle.write('Vous avez gagné!',align="center",font=("Arial",70, "normal"))
        i.phase = "exit"
    elif i.phase == "lose":
        print('Vous avez perdu!')
        turtle.goto(0,0)
        turtle.pencolor('black')
        turtle.write('Vous avez perdu!',align="center",font=("Arial",70, "normal"))
        i.phase = "exit"
    elif i.phase == "exit":
        turtle.exitonclick()
        return None
    else:
        print('out')

    turtle.ontimer(main,500)
示例#4
0
def play():           # 게임을 실제로 플레이 하는 함수.
    global score
    global playing
    t.forward(10)       # 주인공 거북이 10만큼 앞으로 이동합니다.
    if random.randint(1, 5) == 3: # 1~5사이에서 뽑은 수가 3이면(20%확률)
        ang = te.towards(t.pos())
        te.sethading(ang)        # 악당 거북이가 주인공 거북이를 바라봅니다
    speed = score + 5            # 점수에 5를 더해서 속도를 올립니다.
                                 # 점수가 올라가면 빨라집니다.
                                 
    if speed > 15:               # 속도가 15를 넘지는 않도록 합니다
        speed = 15
    te.forward(speed)
    
    if t.distance(te) < 12:      # 주인공과 악당의 거리가 12보다 작으면
                                 # 게임을 종료합니다.  
        
        text = "Score : " + str(score)
        message("Game Over", text)
        playing = False
        score = 0
    
    
    if t.distance(ts) < 12:      # 주인공과 먹이의 거리가 12보다 작으면(가까우면)
        score = score + 1        # 점수를 올립니다.
        t.write(score)           # 점수를 화면에 표시합니다.
        star_x = random.randint(-230, 230)
        star_y = random.randint(-230, 230)
        ts.goto(star_x, star_y)  # 먹이를 다른 곳으로 옮깁니다.
        
    if playing:
        t.ontimer(play, 100)     # 게임 플레이 중이면 0.1초후
示例#5
0
def hands( freq=166 ):
    """Draw three hands.

    :param freq: Frequency of refresh in milliseconds.
    """
    global running
    now= datetime.datetime.now()
    time= now.time()
    h, m, s, ms = time.hour, time.minute, time.second, int(time.microsecond/1000)

    # Erase old hands.
    while turtle.undobufferentries():
        turtle.undo()

    # Draw new hands.
    hand( h*5+m/60+s/3600, .6*R, 3 )
    hand( m+s/60, .8*R, 2 )
    hand( s+ms/1000, .9*R, 1 )

    # Draw date and time
    turtle.penup(); turtle.home()
    turtle.goto( 0, -120 ); turtle.write( now.strftime("%b %d %H:%M:%S"), align="center", font=("Helvetica", 24, "normal") )

    # Reschedule hands function
    if running:
        # Reset timer for next second (including microsecond tweak)
        turtle.ontimer( hands, freq-(ms%freq) )
def makeDiamond(size, person=None, fill=False):
    origPosition = turtle.pos()
    origHead = turtle.heading()
    turtle.penup()
    goDown(size)
    turtle.pendown()
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.begin_fill()
    goNorthEast(2*size/np.sqrt(2))
    goNorthWest(2*size/np.sqrt(2))
    goSouthWest(2*size/np.sqrt(2))
    goSouthEast(2*size/np.sqrt(2))
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.end_fill()
    turtle.penup()
    turtle.goto(origPosition)
    turtle.setheading(origHead)
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.color('black')
        if(person.multipleNotShown == 0):
            turtle.write(str(person.name())+"\n"+probString(person), align="center")
        else:
            turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center")
    turtle.color('blue')
    turtle.penup()
示例#7
0
def Eating(cells):
	for cell in cells:	
		for cell2 in cells:
			if cell!=cell2:
				min_d = cell.get_radius()+cell2.get_radius()
				d = ((cell.xcor()-cell2.xcor())**2+(cell.ycor()-cell2.ycor())**2)**0.5
				if d<min_d:
					if cell.get_radius()>cell2.get_radius():
						if cell2==user_cell:
							turtle.pensize(50)
							turtle.write("Game Over!")
							meet.mainloop()
						x=meet.get_random_x()
						y=meet.get_random_y()
						cell2.goto(x,y)
						r = cell.get_radius() + 0.2 * cell2.get_radius() 
						cell.set_radius(r)
					if cell2.get_radius()>cell.get_radius():
						if cell==user_cell:
							turtle.pensize(50)
							turtle.write("Game Over!")
							meet.mainloop()
						x=meet.get_random_x()
						y=meet.get_random_y()
						cell.goto(x,y)
						r = cell2.get_radius() + 0.2 * cell.get_radius()
						cell2.set_radius(r)
示例#8
0
def drawLine():
	turtle.penup()
	turtle.goto(-50, 300)
	turtle.pendown()
	turtle.write("Base Line", font=("Arial", 14, "normal"))
	turtle.color("red")
	turtle.forward(500)
def printwin(turtle):
  turtle.stamp()
  turtle.hideturtle()
  turtle.penup()
  turtle.goto(0,0)
  turtle.color("green")
  turtle.write("You Win!",font=("Arial",30), align = "center")
示例#10
0
def draw_grid(ll,ur):
	size = ur - ll
	for gridsize in [1, 2, 5, 10, 20, 50, 100 ,200, 500]:
		lines = (ur-ll)/gridsize
		# print('gridsize', gridsize, '->', int(lines)+1, 'lines')
		if lines <= 11: break
	turtle.color('gray')
	turtle.width(1)
	x = ll
	while x <= ur:
		if int(x/gridsize)*gridsize == x:
			turtle.penup()
			turtle.goto(x, ll-.25*gridsize)
			turtle.write(str(x),align="center",font=("Arial",12,"normal"))
			turtle.goto(x,ll)
			turtle.pendown()
			turtle.goto(x,ur)
			# print(x,ll,'to',x,ur)
		x += 1
	y = ll
	while y <= ur:
		# horizontal grid lines:
		if int(y/gridsize)*gridsize == y:
			turtle.penup()
			turtle.goto(ll-.1*gridsize, y - .06*gridsize)
			turtle.write(str(y),align="right",font=("Arial",12,"normal"))
			turtle.goto(ll,y)
			turtle.pendown()
			turtle.goto(ur,y)
			# print(ll,y,'to',ur,y)
		y += 1
示例#11
0
文件: 30.py 项目: jpbat/freetime
def write(side):
	turtle.color("green")
	for i in range(5):
		for j in range(6):
			move(-side*5/2.+j*side, side*6/2.-(i+1)*side)
			turtle.write(table[i][j], align="center", font=("Arial", side/2, "bold"))
	return
示例#12
0
def render(tree, length, width):
    "Draws a given phylogenetic tree constrained by dimensions of" 
    "length and width."
    root = tree[0]
    leftTree = tree[1]
    rightTree = tree[2]
    if leftTree == (): 
        turtle.dot(10)
        turtle.write(root , font=("Arial", 20, "normal"))
        return
    else:
        turtle.dot(10)
        turtle.write(root, font=("Arial", 20, "normal"))
        turtle.left(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(length)
        render(leftTree, 0.5*length, 0.5*width) 
        turtle.back(length)
        turtle.left(90)
        turtle.backward(2*width)
        turtle.right(90)
        turtle.forward(length)
        render(rightTree, 0.5*length, 0.5*width)
        turtle.back(length)
        turtle.right(90)
        turtle.back(width)
        turtle.left(90)
        return
def draw_coordinate_systen(screen_dimension,function, input_range):
    """
    Draws Coordinate System on screen 
    @param screen_dimension 
    """
    turtle.penup()
    turtle.goto(0,screen_dimension[1])
    turtle.pendown()
    turtle.goto(0,-screen_dimension[1])
    turtle.penup()
    turtle.goto(-screen_dimension[1],0)
    turtle.pendown()
    turtle.goto(screen_dimension[1],0)
    turtle.penup()
    turtle.goto(0,0)

    #titles (equation, input_range)
    turtle.color("red")  
    turtle.penup()
    turtle.goto(-screen_dimension[0]+100,screen_dimension[1]-30)
    turtle.pendown()
    turtle.write("Wykres f(x)="+function)
    turtle.penup()
    turtle.goto(-screen_dimension[0]+100,screen_dimension[1]-40)
    turtle.pendown()
    turtle.write("input_range: "+str(input_range))
    turtle.penup()
示例#14
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()
示例#15
0
def message(m1, m2):             # 메시지를 화면에 표시하는 함수
    t.clear()
    t.goto(0, 100)
    t.write(m1, False, "center", ("", 20))
    t.goto(0, -100)
    t.write(m2, False, "center", ("", 15))
    t.home()
def drawTree(tree, angle, length, width):
    turtle.width(width)

    if tree[0] == "ancestor":
        # left branch
        turtle.left(angle)
        turtle.forward(length)
        turtle.right(angle)
        drawTree(tree[1], angle - 0.2 * angle, length - 0.2 * length, width - 0.3 * width)
        turtle.width(width)
        turtle.left(angle)
        turtle.backward(length)
        turtle.right(angle)
        
        # right branch
        turtle.right(angle)
        turtle.forward(length)
        turtle.left(angle)
        drawTree(tree[2], angle - 0.2 * angle, length - 0.2 * length, width - 0.3 * width)
        turtle.width(width)
        turtle.right(angle)
        turtle.backward(length)
        turtle.left(angle)
    else:
        # draw the ending node
        turtle.pencolor("red")
        turtle.write(tree[0], font=("Monospace", 14, "bold"))
        turtle.pencolor("black")
示例#17
0
def lose():
	s.playing = False
	mesg = 'Score %d - press space to play again' % s.score
	turtle.goto(0, 0)
	turtle.color(TEXTCOLOR)
	turtle.write(mesg, True, align='center', font=('Arial', 24, 'italic'))
	engine.del_obj(s.me)
示例#18
0
def draw_move(turtle, cell_size, offset, domino, dx, dy, move_num, step_count):
    shade = (move_num-1) * 1.0/step_count
    rgb = (0, 1-shade, shade)
    turtle.forward((domino.head.x-offset[0]) * cell_size)
    turtle.left(90)
    turtle.forward((domino.head.y-offset[1]) * cell_size)
    turtle.right(90)
    turtle.setheading(domino.degrees)
    turtle.forward(cell_size*.5)
    turtle.setheading(math.atan2(dy, dx) * 180/math.pi)
    pen = turtle.pen()
    turtle.pencolor(rgb)
    circle_pos = turtle.pos()
    turtle.width(4)
    turtle.forward(cell_size*0.05)
    turtle.down()
    turtle.forward(cell_size*0.4)
    turtle.up()
    turtle.pen(pen)
    turtle.setpos(circle_pos)
    turtle.forward(8)
    turtle.setheading(270)
    turtle.forward(8)
    turtle.left(90)
    turtle.down()
    turtle.pencolor(rgb)
    turtle.fillcolor('white')
    turtle.begin_fill()
    turtle.circle(8)
    turtle.end_fill()
    turtle.pen(pen)
    turtle.write(move_num, align='center')
    turtle.up()
示例#19
0
def path(individual , dat , fitness , len_dat):
    # 適応度の最大値が何番目かを出力
    print("適応度の最大の番地 -> " + str(fitness.index(max(fitness))))
    nowKame = dat.ix[individual[fitness.index(max(fitness))]]

    # 初期設定
    kame = turtle.Turtle()
    kame = turtle.shape('turtle')
    turtle.screensize(500,1000)

    for i in range(len(nowKame)):
        if i == 0:
            kame = turtle.up()
            kame = turtle.goto(nowKame.ix[i , 0] * 2 , nowKame.ix[i , 1] * 2)
            kame = turtle.down()
            kame = turtle.write("Start")
        else:
            kame = turtle.setpos(nowKame.ix[i , 0] * 2 , nowKame.ix[i , 1] * 2)
            kame = turtle.write(i + 1)

    print("exitと入力すると終了します")
    while True:
        line = input()
        if line == "exit":
            break
示例#20
0
def eat_cells(cell):
	global exit
	for cell in cells:
		for cell2 in cells:
			x1 = cell.xcor()
			x2 = cell2.xcor()
			y1 = cell.ycor()
			y2 = cell2.ycor()
			distance = ((x1 - x2)**2 + (y1 - y2)**2)**0.5
			r1 = cell.get_radius()
			r2 = cell2.get_radius()
			min_d = r1 + r2
			if distance < min_d:
				if (r1 > r2):
					cell2.goto(meet.get_random_x(),meet.get_random_y())
					r1 = r1 + r2/10
					cell.set_radius(r1)
					if cell2 == user_cell:
						exit = False
						print("game over")
						turtle.write('Game Over' , align='center', font=('ariel',50,'bold'))
					if user_cell.radius > 75:
						exit = False
						print("You Win")
						turtle.write('You Win' , align='center', font=('ariel',50,'bold'))
def writeText(s, x, y):
    turtle.pensize(1)
    turtle.color(0.28, 0.24, 0.55) # Dark Slate Blue
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.write(s, align="center", font=("Times", 15, "italic"))
示例#22
0
def error(word, char):
	go_to(-5-(len(word)//2*20) - (len(word)//2*10), -200, 0)
	turtle.penup()
	for j in range(stage[0]):
		turtle.forward(20)
	turtle.pendown()
	turtle.write(char, align='center', font=("Arial", 8, "normal"))
	hang()
示例#23
0
def draw_text():
	turtle.goto(-100, MAXY-25)
	turtle.color('white')
	turtle.write("Score: ", align='center', font=('Arial', 14, 'normal'))

	turtle.goto(100, MAXY-25)
	turtle.color('white')
	turtle.write("Time: ", align='center', font=('Arial', 14, 'normal'))
示例#24
0
文件: MyTurtle.py 项目: qrdean/py
 def writeText(x, y, text, color ='black'):
     turtle.showturtle()
     turtle.color(color)
     turtle.penup()
     turtle.goto(x + .05*abs(x),y + .05*abs(y))
     turtle.pendown()
     turtle.write(text)
     turtle.setheading(0)
def printwin(turtle, time, score):
  turtle.hideturtle()
  turtle.penup()
  turtle.goto(0,15)
  turtle.color("green")
  turtle.write("You Win!",font=("Arial",30), align = "center")
  turtle.goto(0,-50)
  turtle.write("Score: %d  Time: %d" %(score.score, time), font=("Arial",15), align = "center")
示例#26
0
def point(word, char, i):
	go_to(-5-(len(word)//2*20) - (len(word)//2*10), -150, 0)
	turtle.penup()
	for j in range(i):
		turtle.forward(20)
		turtle.forward(10)
	turtle.forward(10)
	turtle.pendown()
	turtle.write(char, align='center', font=("Arial", 24, "normal"))
示例#27
0
def write(quantity):
    """Turtle animation function.

    Writes the passed string of text directly above the position of the turtle
    on the screen, with extra parameters defining the font for extra
    readability.
    """
    joined = ' '.join(quantity)
    turtle.write(joined, font = ("Comic Sans", 12, "bold"))
示例#28
0
def radar_chart(data):
    # Some "typical" test data
    #print "Hello"
    length=len(data) # stores the length of the data provided
    turtle.home()   # Sets the turtle to position (0,0)
    division=360/length #what angle is needed for invidual lines
    poslist=[] #list to store current position
    valpos=[]   #list to store position
    j=0
    turtle.hideturtle() #hides the arrow
        #Draw the foundation of the Radar Chart
    for i in range(length): # Loop until all the given data is plotted
        turtle.forward(200) #move turtle forward
        turtle.dot(10,"black") # Draw the black dot at the end of each data
        nowpos=turtle.pos() # store the current position
        poslist.append(nowpos) #append the current position to list
        #turtle.hideturtle()
        turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data
        turtle.write(data[i], True, align="center") # Write the label of data
        turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position
        turtle.back(200) #return home
        turtle.left(division) # rotate by the specific angle
    turtle.home()    # return to turtle home
    #Connect the ends points of the radar chart
    for i in poslist: #
        turtle.setpos(i[0],i[1])
        #turtle.setpos(i[j],i[j+1])
        #turtle.forward(100)
        #turtle.home()
        #turtle.degree(division)
        #turtle.heading()
        #turtle.forward(100)
    turtle.setpos(poslist[0][0],poslist[0][1])
    turtle.home()
    #Draw green Dots 
    for i in range(length):
        incval=data[i]
        turtle.forward(incval*2)
        turtle.dot(15,"green")
        nowpos=turtle.pos()
        valpos.append(nowpos) 
        turtle.back(incval*2)
        turtle.left(division)
    turtle.begin_poly()
    turtle.fill(True)
    #Fill the green Dots
    for i in valpos:
        turtle.setpos(int(i[0]),int(i[1]))
    turtle.setpos(valpos[0][0],valpos[0][1])
    turtle.end_poly()
    p = turtle.get_poly()
    turtle.register_shape("jpt", p)
    turtle.color("Green", "Green")
    turtle.begin_fill()
    #turtle.p(80)
    turtle.end_fill()
    turtle.fill(False)
def reportMsg(msg):
    msgX = -50
    msgY = 90
    turtle.pencolor("red")
    turtle.penup()
    turtle.setpos(msgX, msgY)
    turtle.pendown()
    turtle.write(msg)
    turtle.pencolor(normalcolor)
示例#30
0
	def down() :
		if len(info["tracks"])<=1 :
			turtle.write("no more")
		else :
			info["tracks"].pop()
			pos=info["tracks"][len(info["tracks"])-1]
			turtle.pencolor("WHITE")
			turtle.setpos(pos)
			turtle.pencolor("BLACK")
示例#31
0
def placeText(text, color, x, y):
    t.penup()
    t.setposition(x, y)
    t.pencolor(color)
    t.write(text)
示例#32
0
import turtle
print("hello")
print("test succeed")
#test the sdf
'''what the f**k?'''
print("kill the` bugs")

turtle.showturtle()
turtle.write("Welcome to python")
示例#33
0
turtle.setheading(270)
turtle.forward(h1)

turtle.penup()
turtle.goto(x2 - w2 / 2, y2 - h2 / 2)
turtle.pendown()
turtle.setheading(0)
turtle.forward(w2)
turtle.setheading(90)
turtle.forward(h2)
turtle.setheading(180)
turtle.forward(w2)
turtle.setheading(270)
turtle.forward(h2)

turtle.hideturtle()

turtle.penup()
turtle.setheading(270)
turtle.forward(100)

if left1 < left2 and right1 > right2 and top1 > top2 and bottom1 < bottom2:
    turtle.write("두 번째 사각형이 첫 번째 사각형의 내부에 있다")
elif right1 < left2 or left1 > right2:
    turtle.write("두 번째 사각형이 첫 번째 사각형의 외부에 있다.")
elif (right1 > right2 or left1 < left2) and (top1 < bottom2 or bottom1 > top2):
    turtle.write("두 번째 사각형이 첫 번째 사각형의 외부에 있다.")
else:
    turtle.write("두 번째 사각형과 첫 번째 사각형은 겹친다")

turtle.done()
示例#34
0
# Draw the circle
turtle.penup() # Pull the pen up
turtle.goto(x1, y1 - radius)
turtle.pendown() # Pull the pen down
turtle.circle(radius)

# Draw the point
turtle.penup() # Pull the pen up
turtle.goto(x2, y2)
turtle.pendown() # Pull the pen down
turtle.begin_fill() # Begin to fill color in a shape
turtle.color("red")
turtle.circle(3) 
turtle.end_fill() # Fill the shape

# Display the status
turtle.penup() # Pull the pen up
turtle.goto(x1 - 70, y1 - radius - 20)
turtle.pendown() 

d = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) ** 0.5
if d <= radius:
    turtle.write("The point is inside the circle") 
else:
    turtle.write("The point is outside the circle") 

turtle.hideturtle()

turtle.done()
示例#35
0
def draw_big_point(p):
    turtle.goto(p)
    turtle.color(0.8, 0.9, 0)
    turtle.dot(15)
    turtle.write('     ' + str(p))
示例#36
0
t.goto(-150 * s, -1000 * s)
t.pendown()
t.begin_fill()
t.right(120)
t.circle(300 * s, 115)
t.left(75)
t.circle(300 * s, 100)
t.end_fill()
t.penup()
t.goto(430 * s, -1070 * s)
t.pendown()
t.right(30)
t.circle(-600 * s, 35)
# 文字部分
t.pensize(4)
t.pencolor("purple")
t.penup()
t.goto(-800 * s, -200 * s)
t.pendown()
t.write("******", align="left", font=("arial", 10, "normal"))
t.penup()
t.goto(-800 * s, -300 * s)
t.pendown()
t.write("******", align="left", font=("arial", 10, "normal"))
t.penup()
t.goto(-750 * s, -400 * s)
t.pendown()
t.write("*****", align="left", font=("arial", 10, "normal"))
t.hideturtle()
t.done()
示例#37
0
def writenumber(i):
    turtle.write(int(i), align="center", font=("Courier", 20, "bold"))
示例#38
0
    rand_collumn = random.randint(1, 9)
    x = x + (rand_collumn - 1) * spacing + 0.25 * spacing

    rand_row = random.randint(1, 9)
    y = y + (rand_row - 1) * spacing + 0.25 * spacing
    if (x, y) not in randx_randy and (x,
                                      rand_number) not in randx_randnum and (
                                          y, rand_number) not in randy_randnum:
        randx_randy.append((x, y))
        randx_randnum.append((x, rand_number))
        randy_randnum.append((y, rand_number))
        box_help.append(x)
        box_help.append(y)
        box_help.append(rand_number)
        turtle.goto(x, y)
        turtle.write(str(rand_number), font=("Papyrus", 20, "normal"))
        if x >= -188.875 and x <= -99.875 and y >= -188.875 and y <= -99.875:
            box_1.append(x)
            box_1.append(y)
            box_1.append(rand_number)
            boxes.remove(box_1)
            boxes.append(box_1)
        if x >= -55.375 and x <= 33.625 and y >= -188.875 and y <= -99.875:
            box_2.append(x)
            box_2.append(y)
            box_2.append(rand_number)
            boxes.remove(box_2)
            boxes.append(box_2)
        if x >= 78.125 and x <= 167.125 and y >= -188.875 and y <= -99.875:
            box_3.append(x)
            box_3.append(y)
import turtle

turtle.hideturtle()  #This hides the turtle pointer visibility.

#I wanted the graphic to draw in a specific flow,
#working from left to right and from top to bottom.

#I started with the left/uppermost star.

turtle.penup(
)  #This hides the graphic movement from the default point (0,0) to my starting point (-110,160).
turtle.goto(
    -100, 160)  #I used this function to easily move from one plot to the next.
turtle.pendown()
turtle.dot()  #indicator for the star plots
turtle.write("Betelgeuse")  #labeling the star

turtle.goto(-30, -10)
turtle.dot()
turtle.write("Alnitak")

turtle.goto(-80, -140)
turtle.dot()
turtle.write("Saiph")

turtle.penup()  #This function is meant to return to the star, Alnitak,
turtle.goto(-30, -10)  #so that the graphic doesn't draw from Saiph to Alnilam.
turtle.pendown()

turtle.goto(0, 0)
turtle.dot()
示例#40
0
import turtle
turtle.screensize(1024, 768)
turtle.write("Hello", font=("宋体", 20, "normal"))
turtle.showturtle()  #显示

turtle.begin_fill()
turtle.circle(50)
turtle.color("red")
turtle.end_fill()

turtle.done()
示例#41
0
def message(m1):
    t.clear()
    t.write(m1, False, "center", ("", 20))
    t.goto(0, 200)
    t.home()
turtle.left(144)
turtle.forward(40)
turtle.left(144)
turtle.forward(40)
turtle.left(144)
turtle.forward(40)
turtle.end_fill()

#第5个星星
turtle.goto(-280, 210)
#turtle.pendown()
turtle.begin_fill()
turtle.right(35)
turtle.forward(40)
turtle.left(144)
turtle.forward(40)
turtle.left(144)
turtle.forward(40)
turtle.left(144)
turtle.forward(40)
turtle.left(144)
turtle.forward(40)
turtle.end_fill()

turtle.hideturtle()

#屏幕写字
#print("送给妈妈")
turtle.goto(-100, 0)
turtle.write("送给妈妈", font=('宋体', 40, 'normal'))
示例#43
0
def welcome():
    turtle.goto(0, BORDER_Y)
    turtle.write("Welcome to the Snake Game!",
                 False,
                 align="center",
                 font="Verdana")
示例#44
0
turtle.fillcolor("red")

turtle.begin_fill()
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)

time.sleep(0.5)
turtle.penup()
turtle.goto(-150, -120)
turtle.color("violet")
turtle.write("Done", font=('Arial', 40, 'normal'))
time.sleep(1)

turtle.reset()  #清空窗口,重置turtle状态为起始状态
turtle.pensize(3)
turtle.pencolor("red")
turtle.circle(45)
time.sleep(1)
turtle.fillcolor("green")

turtle.clear()
turtle.circle(120, 180)  # 半圆
time.sleep(1)
turtle.clear()
turtle.penup()
turtle.goto(50, 100)
示例#45
0
turtle.penup()                  #内裤
turtle.goto(-50,-70)
turtle.pendown()
turtle.begin_fill()
turtle.goto(50,-70)
turtle.goto(50,-50)
turtle.goto(-50,-50)
turtle.goto(-50,-70)
turtle.fillcolor("red")
turtle.end_fill()

turtle.penup()
turtle.goto(-10,-70)
turtle.pendown()
turtle.begin_fill()
turtle.goto(-10,-85)
turtle.goto(10,-85)
turtle.goto(10,-70)
turtle.goto(-10,-70)
turtle.fillcolor("red")
turtle.end_fill()

turtle.penup()
turtle.goto(-100,200)
turtle.pendown()
s = "机器猫中的战斗猫"
turtle.write(s,font = ("Arial",20,"normal"))


turtle.done()
def move_snake():
    my_pos = snake.pos()
    x_pos = my_pos[0]
    y_pos = my_pos[1]

    if direction == RIGHT:
        snake.goto(x_pos + SQUARE_SIZE, y_pos)
        print("You moved right!")
    elif direction == LEFT:
        snake.goto(x_pos - SQUARE_SIZE, y_pos)
        print("You moved left!")

    #4. Write the conditions for UP and DOWN on your own
    ##### YOUR CODE HERE
    elif direction == UP:
        snake.goto(x_pos, y_pos + SQUARE_SIZE)
        print("You moved up!")

    elif direction == DOWN:
        snake.goto(x_pos, y_pos - SQUARE_SIZE)
        print("You moved down")

    #Stamp new element and append new stamp in list
    #Remember: The snake position changed - update my_pos()

    my_pos = snake.pos()
    pos_list.append(my_pos)
    new_stamp = snake.stamp()
    stamp_list.append(new_stamp)
    ######## SPECIAL PLACE - Remember it for Part 5
    #pop zeroth element in pos_list to get rid of last the last
    #piece of the tail
    global food_stamps, food_pos, score
    if snake.pos() in food_pos:
        food_ind = food_pos.index(snake.pos())  #What does this do?
        food.clearstamp(food_stamps[food_ind])  #Remove eaten food#stamp
        print(score)
        score += 1
        scorecount.clear()
        scorecount.color('black')
        scorecount.hideturtle()
        scorecount.penup()
        scorecount.goto(0, -350)
        scorecount.write(score, align="center", font=('Arial', 50))
        turtle.bgcolor(bg_color)
        turtle.penup()
        turtle.goto(0, 300)
        turtle.write("SNAKE GAME",
                     align="center",
                     font=('Arial', 50, "normal"))
        turtle.penup()
        turtle.goto(-400, -250)
        turtle.pensize(5)
        turtle.pendown()
        turtle.goto(-400, 250)
        turtle.goto(400, 250)
        turtle.goto(400, -250)
        turtle.goto(-400, -250)
        turtle.penup()
        turtle.goto(0, 0)

        if score == 5:
            snake.fillcolor("yellow")
        elif score == 10:
            snake.fillcolor("blue")
        elif score == 15:
            snake.fillcolor("red")
        elif score == 20:
            snake.fillcolor("white")
        elif score == 25:
            snake.fillcolor("purple")
        elif score == 30:
            snake.fillcolor("green")
        elif score == 35:
            snake.shape("trash.gif")
        elif score == 40:
            snake.shape("diamond.gif")
        elif score == 45:
            snake.shape("glove.gif")

        food_pos.pop(food_ind)  #Remove eaten food position
        food_stamps.pop(food_ind)  #Remove eaten food stamp
        print("You have eaten the food!")
        while len(food_stamps) < 4:
            make_food()

    else:
        old_stamp = stamp_list.pop(0)
        snake.clearstamp(old_stamp)
        pos_list.pop(0)

    if pos_list[-1] in pos_list[:-1]:
        print('you ate yourself!')
        scorecount.clear()
        gameover.write('GAME OVER', font=('Arial', 95), align="center")
        time.sleep(3)
        quit()

    #HINT: This if statement may be useful for Part 8

    #Don't change the rest of the code in move_snake() function:
    #If you have included the timer so the snake moves
    #automatically, the function should finish as before with a
    #call to ontimer()

    UP_EDGE = 250
    DOWN_EDGE = -250
    RIGHT_EDGE = 400
    LEFT_EDGE = -400

    new_pos = snake.pos()
    new_x_pos = new_pos[0]
    new_y_pos = new_pos[1]

    if new_x_pos >= RIGHT_EDGE:
        print("you tuched the edge GAME OVER")
        scorecount.clear()
        gameover.write('GAME OVER', font=('Arial', 95), align="center")
        time.sleep(3)
        quit()
    if new_x_pos <= LEFT_EDGE:
        print("you tuched the edge GAME OVER")
        scorecout.clear()
        gameover.write('GAME OVER', font=('Arial', 95), align="center")
        time.sleep(3)
        quit()
    if new_y_pos >= UP_EDGE:
        print("you tuched the edge GAME OVER")
        scorecount.clear()
        gameover.write('GAME OVER', font=('Arial', 95), align="center")
        time.sleep(3)
        quit()
    if new_y_pos <= DOWN_EDGE:
        print("you tuched the edge GAME OVER")
        scorecount.clear()
        gameover.write('GAME OVER', font=('Arial', 95), align="center")
        time.sleep(3)
        quit()

    turtle.ontimer(move_snake, TIME_STEP)
示例#47
0
inicio2Partes = 10
inicioBienPartes = 10

inicioBorrador = 50

isfirst = False

window = turtle.Screen()
window.bgcolor('gray')
turtle.title('ADN')
turtle.setup(1530, 1000, 0, 0)
turtle.screensize(20, 8000)
turtle.hideturtle()
turtle.penup()
turtle.goto(-170, -40)
turtle.write("Arreglo 3'", False, "left", ("arial", 20, "bold italic"))
turtle.goto(-15, -40)
turtle.write("Arreglo 5'", False, "left", ("arial", 20, "bold italic"))
turtle.goto(-320, -40)
turtle.write("Errores", False, "left", ("arial", 20, "bold italic"))
turtle.goto(150, -40)
turtle.write("Parte", False, "left", ("arial", 20, "bold italic"))
turtle.goto(-500, 300)
turtle.pencolor('red')
turtle.write("Adenina", False, "left", ("arial", 18, "bold italic"))
turtle.goto(-500, 250)
turtle.pencolor('blue')
turtle.write("Guanina", False, "left", ("arial", 18, "bold italic"))
turtle.goto(-500, 200)
turtle.pencolor('green')
turtle.write("Timina", False, "left", ("arial", 18, "bold italic"))
print('green, blue, yellow, pink, red, purple, black, white, brown orange')
bg_color = input("type yur chosen your backround color here ======> ")

score = 0
scorecount = turtle.clone()
scorecount.hideturtle()
gameover = turtle.clone()
gameover.penup()
gameover.goto(0, -400)
gameover.color('black')
gameover.hideturtle()

turtle.bgcolor(bg_color)
turtle.penup()
turtle.goto(0, 300)
turtle.write("SNAKE GAME", align="center", font=('Arial', 50, "normal"))
turtle.penup()
turtle.goto(-400, -250)
turtle.pensize(5)
turtle.pendown()
turtle.goto(-400, 250)
turtle.goto(400, 250)
turtle.goto(400, -250)
turtle.goto(-400, -250)
turtle.penup()
turtle.goto(0, 0)
turtle.tracer(1, 0)  #This helps the turtle move more smoothly

SIZE_X = 1000
SIZE_Y = 1000
TIME_STEP = 100
示例#49
0
    turtle.goto(0,0)
    turtle.pd()
    for i in range (n):
        turtle.fd(50)
        turtle.delay(50)
        turtle.left(head)

if __name__ == '__main__':

    while 1:

        try:
            n = int(raw_input("要画正N边形?N<3 to EXIT:"))

            if n <= 2:
                sys.exit()

            else:
                head = round(360.0/n, 2)
                Polygon(n, head)
                text = str(n)+' ploygon is done. Head is: '+str(head)
                turtle.up()
                turtle.ht()
                turtle.goto(0,-15*n)
                turtle.pd()
                turtle.write(text, True, align='left')
                turtle.up()

        except Exception,e:
            print "请输入整数。"
示例#50
0
def drawSixStars():
    y = 115
    for row in range(0, 5):
        x = -230
        y = y - 4
        for star in range(0, 6):
            x = x + 6
            drawStar(x, y, 'white', 10)
            x = x + 19
        y = y - 20


def drawFiveStars():
    y = 103
    for row in range(0, 4):
        x = -212
        y = y - 4
        for star in range(0, 5):
            drawStar(x, y, 'white', 10)
            x = x + 25
        y = y - 20


drawStripes()
drawSquare()
drawSixStars()
drawFiveStars()
turtle.goto(0, -140)
turtle.write("Go USA")
turtle.back(20)
示例#51
0
def jog1():
    #Turtle race
    #EQM - Games
    #Eduardo Q Marques
    #29/03/2019

    #Janela
    window = turtle.Screen()
    window.title("Turtle Race")
    turtle.bgcolor("forestgreen")
    turtle.color("white")
    turtle.speed(0)
    turtle.penup()
    turtle.setpos(-140, 200)
    turtle.write("Turtle Race", font=("Arial", 30, "bold"))
    turtle.penup()

    #DIRT
    turtle.setpos(-400, -180)
    turtle.color("chocolate")
    turtle.begin_fill()
    turtle.pendown()
    turtle.forward(800)
    turtle.right(90)
    turtle.forward(300)
    turtle.right(90)
    turtle.forward(800)
    turtle.right(90)
    turtle.forward(300)
    turtle.end_fill()

    #Final line
    stamp_size = 20
    square_size = 15
    finish_line = 200

    turtle.color("black")
    turtle.shape("square")
    turtle.shapesize(square_size / stamp_size)
    turtle.penup()

    for i in range(10):
        turtle.setpos(finish_line, (150 - (i * square_size * 2)))
        turtle.stamp()

    for j in range(10):
        turtle.setpos(finish_line + square_size,
                      ((150 - square_size) - (j * square_size * 2)))
        turtle.hideturtle()

    #Jabuti 1
    turtle1 = Turtle()
    turtle1.speed(0)
    turtle1.color("black")
    turtle1.shape("turtle")
    turtle1.penup()
    turtle1.goto(-250, 100)
    turtle1.pendown()

    #Jabuti 2
    turtle2 = Turtle()
    turtle2.speed(0)
    turtle2.color("cyan")
    turtle2.shape("turtle")
    turtle2.penup()
    turtle2.goto(-250, 50)
    turtle2.pendown()

    #Jabuti 3
    turtle3 = Turtle()
    turtle3.speed(0)
    turtle3.color("magenta")
    turtle3.shape("turtle")
    turtle3.penup()
    turtle3.goto(-250, 0)
    turtle3.pendown()

    #Jabuti 4
    turtle4 = Turtle()
    turtle4.speed(0)
    turtle4.color("yellow")
    turtle4.shape("turtle")
    turtle4.penup()
    turtle4.goto(-250, -50)
    turtle4.pendown()

    #Jabuti 5
    turtle5 = Turtle()
    turtle5.speed(0)
    turtle5.color("white")
    turtle5.shape("turtle")
    turtle5.penup()
    turtle5.goto(-250, -100)
    turtle5.pendown()

    time.sleep(2)  #pause in seconds before race

    #Move the jabutis
    for i in range(145):
        turtle1.forward(randint(1, 5))
        turtle2.forward(randint(1, 5))
        turtle3.forward(randint(1, 5))
        turtle4.forward(randint(1, 5))
        turtle5.forward(randint(1, 5))

    turtle.exitonclick()
示例#52
0
def move_player():
    global village, if_player_food
    my_pos = turtle.pos()
    x_pos = my_pos[0]
    y_pos = my_pos[1]

    if direction == RIGHT:
        turtle.goto(x_pos + (1.5 * SQUARE_SIZE), y_pos)
        #print("you moved to the right!")
    elif direction == LEFT:
        turtle.goto(x_pos - (1.5 * SQUARE_SIZE), y_pos)
        #print("you moved to the left!")
    elif direction == UP:
        turtle.goto(x_pos, y_pos + (1.5 * SQUARE_SIZE))
        #print("you moved UP")
    elif direction == DOWN:
        turtle.goto(x_pos, y_pos - (1.5 * SQUARE_SIZE))
        #print("you moved DOWN")
    my_pos = turtle.pos()
    pos_list.append(my_pos)
    #print(pos_list[-1])
    global TIME_STEP
    global count

    #limiting the player in the border
    if x_pos > SIZE_X / 2:
        turtle.ht()
        turtle.goto(-SIZE_X / 2 + 10, y_pos)
        turtle.st()
    elif x_pos <= -SIZE_X / 2:
        turtle.ht()
        turtle.goto(SIZE_X / 2, y_pos)
        turtle.st()

    elif y_pos > SIZE_Y / 2:
        turtle.ht()
        turtle.goto(x_pos, -SIZE_Y / 2 + 2)
        turtle.st()

    elif y_pos <= -SIZE_Y / 2:
        turtle.ht()
        turtle.goto(x_pos, SIZE_Y / 2 - 2)
        turtle.st()
    if -30 < enemy.pos()[0] - turtle.pos()[0] < 30 and -30 < enemy.pos(
    )[1] - turtle.pos()[1] < 30:
        turtle.register_shape("ghost.gif")
        enemy.shape("ghost.gif")
        turtle.register_shape("player_F.gif")
        turtle.shape("player_F.gif")

        village.st()

        enemy.goto(0, 0)

        ## Try to understand me!!!???
        if_player_food = True
    if (-15 < village.pos()[0] - turtle.pos()[0] < 15
            and -15 < village.pos()[1] - turtle.pos()[1] < 15):

        if if_player_food == True:

            score.clear()
            count += 100
            scores.append(count)
            score.pencolor("white")
            score.write("score: " + str(count), font=("Arial", 28, "normal"))

        enemy.shape("ghost_F.gif")
        turtle.shape("player.gif")
        if_player_food == False

    if count == 1000:
        turtle.goto(0, 0)
        turtle.pencolor("white")
        turtle.write("PLayer won!", font=("Ariel", 28, "normal"))
        time.sleep(5)
        quit()

    turtle.ontimer(move_player, TIME_STEP)
示例#53
0
t.left(-10)
t.forward(80)

#画左边胡子
t.up()
t.goto(-20,160)
t.down()
t.right(180)
t.forward(80)

t.up()
t.goto(-20,180)
t.down()
t.right(20)
t.forward(80)

t.up()
t.goto(-20,150)
t.down()
t.right(-40)
t.forward(80)

t.up()
t.goto(0,-80)
t.write("我爱大脸猫", align="center",font=("微软雅黑", 22, "bold"))

t.up()
t.goto(0,-120)
t.write("李家营小学", align="center",font=("方正舒体 常规", 16, "bold"))

t.done()
def game_over():
    Snake.color('yellow')
    leaf.color('yellow')
    t.penup()
    t.hideturtle()
    t.write('GAME OVER!',align='center' , font=('Aerial',30,'normal'))
示例#55
0
    def draw(self):
        turtle.setup(666, 400)
        turtle.bgcolor("black")
        # turtle.bgpic("logo.JPG")
        turtle.hideturtle()
        turtle.speed(10)
        turtle.penup()
        turtle.goto(-200, 50)
        turtle.pendown()
        turtle.pensize(self.pythonSize)
        turtle.seth(-40)
        for i in range(self.len):
            turtle.color(self.colors[i])
            turtle.circle(self.rad, self.angle)
            turtle.circle(-self.rad, self.angle)

        turtle.color("purple")
        turtle.circle(self.rad, self.angle / 2)
        turtle.fd(self.rad)
        turtle.circle(self.neckRad + 1, 180)
        turtle.fd(self.rad * 2 / 3)
        # turtle.write(s, font=(“font-name”, font_size, ”font_type”))
        turtle.penup()
        turtle.goto(-60, -60)
        turtle.color("pink")
        turtle.pendown()
        turtle.write("让我们吃着小龙虾", align="left", font=("Courier", 20, "bold"))
        time.sleep(1)
        turtle.penup()
        turtle.goto(-60, -80)
        turtle.pendown()
        turtle.write("看着屏幕", align="left", font=("Courier", 20, "bold"))
        time.sleep(1)
        turtle.penup()
        turtle.goto(-60, -100)
        turtle.pendown()
        turtle.write("享受这大千世界与开源不求回报的礼物",
                     align="left",
                     font=("Courier", 20, "bold"))
        time.sleep(1)
        turtle.penup()
        turtle.goto(-60, -120)
        turtle.pendown()
        turtle.write("Forever don't forget the day,",
                     align="left",
                     font=("Courier", 20, "bold"))
        time.sleep(1.5)
        turtle.penup()
        turtle.goto(-60, -140)
        turtle.pendown()
        turtle.write("that someone told you excitedly!",
                     align="left",
                     font=("Courier", 20, "bold"))
        time.sleep(1.5)
        turtle.penup()
        turtle.goto(-60, -160)
        turtle.pendown()
        turtle.write("we needn't rewhell!",
                     align="left",
                     font=("Courier", 20, "bold"))
        time.sleep(2)
'''
**3.19 (Turtle: draw a line) Write a program that prompts the user to enter two points
        and draw a line to connect the points and displays the coordinates of the points

/**
 * @author BASSAM FARAMAWI
 * @email [email protected]
 * @since 2018
 */
'''
import turtle  # Import turtle module

# Prompt the user to Enter 2 points
x1, y1, x2, y2 = eval(input("Enter tow points: "))

# Draw the line
turtle.penup()
turtle.goto(x1, y1)
turtle.pendown()
turtle.write("(" + str(x1) + ", " + str(y1) + ")")

turtle.goto(x2, y2)
turtle.write("(" + str(x2) + ", " + str(y2) + ")")

turtle.hideturtle()  # Hide the turtle
turtle.done()  # Don't close the turtle graphics window
示例#57
0
def play(event):
    turtle.clear()
    turtle.update()


ans = True
turtle.ht()
turtle.tracer(0)
turtle.penup()
turtle.goto(-100, -100)
turtle.write("""
		1. INSTRUCTIONS
		2. PLAY!!




		PRESS ENTER TO QUIT
		""",
             True,
             align="center",
             font=("Helvetica", 24, "bold italic"))


def bye(event):
    turtle.bye()


for i in range(10000):
    turtle.getcanvas().bind("<Return>", bye)
    turtle.getcanvas().bind("2", play)
    turtle.getcanvas().bind("1", inst)
示例#58
0
hints = False
answer2 = turtle.textinput("Играем с подсказками или по-взрослому =) ?", "y/n")
if answer2 == 'y':
    hints = True

try_count = 0

while True:
    number = turtle.numinput("Угадайте число", "Число", 0, 0, 100)

    if number == x:
        lastik(-150, 100)
        turtle.color("green")
        gotoxy(-150, 200)
        turtle.write("Вы выиграли!!!", font=("Arial", 28, "normal"))
        break

    else:
        # lastik(-150, 200)
        turtle.color("red")
        gotoxy(-150, 200)
        turtle.write("Неверно!", font=("Arial", 28, "normal"))

        if hints:
            gotoxy(100, 100 - try_count * 15)
            turtle.color("blue")
            if x < number:
                turtle.write(str(number) + " Загаданное число меньше",
                             font=("Arial", 10, "normal"))
            else:
示例#59
0
def score():
    turtle.undo()
    turtle.goto(0, -BORDER_Y)
    turtle.write("SCORE:" + str(SCORE), False, align="center", font="Verdana")
示例#60
0
t.penup()
t.goto(0, 0)
t.pendown()
t.color("blue")
t.goto(100, 0)

t.penup()
t.goto(0, 0)
t.pendown()
t.color("black")
t.goto(0, 125)

t.penup()
t.goto(-140, 0)
t.pendown()
t.write("9")

t.penup()
t.goto(140, 0)
t.pendown()
t.write("3")

t.penup()
t.goto(0, 135)
t.pendown()
t.write("12")

t.penup()
t.goto(0, -150)
t.pendown()
t.circle(150)