示例#1
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()
示例#2
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
示例#3
0
def draw_tree(n, b, l, size):
	if n < 0:						#base-case
		return
	elif n == 0:					#Draw Leaves
		turtle.color("green")							#Color of leaves
		turtle.width(1)
		numberOfLeaves = random.randint(5, 15)			#Random number of leaves ranging from 5 to 15
		angle = int(270 / numberOfLeaves)				#Angle Range between leaves determined by number of leaves
		for i in range(numberOfLeaves):
			if (randomB(l)):
				angle2 = random.randint(0 + (i * angle), 0 + ((i + 1) * angle))	#Angle between different leaves can be different given the Angle Range
				angle2-=135
				turtle.right(angle2)
				turtle.forward(5)
				turtle.back(5)
				turtle.left(angle2)
		return
	else:							#Draw Tree
		turtle.color("brown")						#Color of Tree
		turtle.forward(size)
		b1 = math.floor(5 * b)						#Using Bushiness to calculate number of branches: Max branchess are 5
		angle = int(270 / b1);						#Angle Range between branches determined by Number of Branches
		for i in range(b1):
			if randomB(b1):
				angle2 = random.randint(0 + (i * angle), 0 + ((i + 1) * angle))	#Angle between different branches can be different given the Angle Range
				angle2-=135
				turtle.right(angle2)
				draw_tree(n - 1, b, l, size * random.uniform(0.4, 0.7))			#Recursion step: size of sub-tree is random
				turtle.left(angle2)
		turtle.color("brown")
		turtle.back(size)
	return
def drawBoard():
    global b
    #actually draw the board :D
    turtle.ht()
    turtle.width(5)
    turtle.up()
    turtle.goto(-3*b/2.0,b/2.0)
    turtle.down()
    turtle.seth(0)
    turtle.forward(3*b)
    turtle.up()
    turtle.goto(-3*b/2.0,-b/2.0)
    turtle.down()
    turtle.seth(0)
    turtle.forward(3*b)
    turtle.up()
    turtle.goto(-b/2.0,3*b/2.0)
    turtle.down()
    turtle.seth(270)
    turtle.forward(3*b)
    turtle.up()
    turtle.goto(b/2.0,3*b/2.0)
    turtle.down()
    turtle.seth(270)
    turtle.forward(3*b)
示例#5
0
文件: sudoku.py 项目: jpbat/freetime
def grid(side):

	sqrt = math.sqrt(squares)

	#horizontal
	for i in range(1,squares):
		if i % sqrt == 0:
			turtle.width(2)
			turtle.color("red")
		move(-side*squares/2., side*squares/2.-i*side)
		turtle.fd(side*squares)
		turtle.width(1)
		turtle.color("black")

	#vertical
	turtle.setheading(-90)
	for i in range(1,squares):
		if i % sqrt == 0:
			turtle.width(2)
			turtle.color("red")
		move(-side*squares/2.+i*side, side*squares/2.)
		turtle.fd(side*squares)
		turtle.width(1)
		turtle.color("black")

	#big square
	move(-side*squares/2., side*squares/2.)
	turtle.width(3)
	turtle.setheading(0)
	turtle.color("blue")
	for i in range(4):
		turtle.fd(side*squares)
		turtle.rt(90)
示例#6
0
文件: 30.py 项目: jpbat/freetime
def grid(side):
	turtle.color("blue")
	#horizontal
	for i in range(1, 5):
		move(-side*3, side*3-i*side)
		turtle.fd(6*side)

	#vertical
	turtle.setheading(-90)
	for i in range(1, 6):
		move(-side*3+i*side, side*3)
		turtle.fd(5*side)
	
	#big square
	turtle.color("red")
	turtle.width(2)
	turtle.setheading(0)
	move(-side*3, side*3)
	for i in range(4):
		if (i % 2 == 0):
			cena = side * 6
		else:
			cena = side * 5
		turtle.fd(cena)
		turtle.rt(90)
示例#7
0
文件: problem3.py 项目: hchiam/code7
def drawLine(x,y,rotation,width,length):
    turtle.penup()
    turtle.goto(x,y)
    turtle.width(width)
    turtle.setheading(rotation)
    turtle.pendown()
    turtle.forward(length)
    return turtle.position()
 def draw(self,turtle):
     turtle.width(self.width)
     turtle.pencolor(self.color)
     turtle.forward(self.longside)
     turtle.right(90)
     turtle.forward(self.shortside)
     turtle.right(90)
     turtle.forward(self.longside)
     turtle.right(90)
     turtle.forward(self.shortside)
示例#9
0
def drawAxe(padEcart):
	turtle.color(0.7,0.7,0.7)	
	turtle.width(1)
	padAngle = math.pi/5
	for idx in range(0,5):
		turtle.up()
		turtle.goto((math.sin(idx*padAngle)*padEcart*11.0),math.cos(idx*padAngle)*padEcart*11.0)
		turtle.down()
		turtle.goto(-math.sin(idx*padAngle)*padEcart*11.0,-math.cos(idx*padAngle)*padEcart*11.0)
	turtle.down()
示例#10
0
 def draw(self,turtle):
     turtle.width(self.width)
     turtle.pencolor(self.color)
     turtle.forward(self.length)
     turtle.right(90)
     turtle.forward(self.length)
     turtle.right(90)
     turtle.forward(self.length)
     turtle.right(90)
     turtle.forward(self.length)
     turtle.right(90)
示例#11
0
def polygon(sides, length, colour = "Black", width = 1, speed = 10):

    turtle.pencolor(colour)
    turtle.width(width)
    turtle.speed(speed)
    turtle.pendown()
    for vector in range(sides):
        turtle.forward(length)
        turtle.right(360 / sides)
    turtle.penup()
    turtle.done()
 def writing():
     turtle.width(1)
     turtle.color("white")
     Base((-250,-100))
     turtle.setheading(162)
     turtle.pu()
     turtle.fd(28)
     turtle.setheading(180)
     turtle.fd(10)
     turtle.write("Raphaella and Danes' ", font=("Calibri", 12, "italic"))
     turtle.fd(14)
     turtle.pd()
     turtle.write("   Apple Tree",font = ("Calibri",12,"bold"))
示例#13
0
文件: tree.py 项目: rirwin/sandbox
def tree(n,l):
    if n==0:
        return
    turtle.down()
    turtle.width(6*float(n)/max_depth)
    turtle.color(float(n)/max_depth,1-float(n)/max_depth,0.2)
    turtle.forward(l)
    turtle.left(20+turn_scalar*n)
    tree(n-1,l/length_scalar)
    turtle.right(40+2*turn_scalar*n)
    tree(n-1,l/length_scalar)
    turtle.left(20+turn_scalar*n)
    turtle.up()
    turtle.backward(l)
示例#14
0
def drawBase(size,n,widthh):
	turtle.width(widthh)
	widthh+=.5
	if n<0:
		return
	else:
		turtle.forward(size)
		turtle.left(120)
		for i in range(6):
			turtle.forward(size)
			turtle.left(60)
		turtle.right(120)
		turtle.back(size)
		drawBase(.8*size,n-1,widthh)
	return
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.down()
    wn.onkey(up, "Up")
    wn.onkey(left, "Left")
    wn.onkey(right, "Right")
    wn.onkey(back, "Down")
    wn.onkey(quitTurtles, "Escape")
    wn.listen()
    wn.mainloop()
示例#16
0
def draw_lines(lines, color='black', width=3, dots=0, visible=False):
	"""draw every line in lines"""
	turtle.pen(speed=10,shown=False)
	turtle.color(color)
	turtle.width(width)
	for line in lines:
		((x0,y0),(x1,y1)) = list(line)
		turtle.penup()
		turtle.goto((x0,y0))
		turtle.pendown()
		if dots>0: turtle.dot(dots)
		if visible:
#			 turtle.pen(speed=10,shown=True)
			turtle.goto((x1,y1))
#			 turtle.pen(speed=10,shown=False)
		else:
			turtle.goto((x1,y1))
示例#17
0
def draw_axis(camera, viewer):
	turtle.width(10)
	X, Y, Z, O = apply_perspective([(300,0,0),(0,300,0),(0,0,300),(0,0,0)],camera,viewer)
	turtle.color(1,0,0)
	turtle.up()
	turtle.goto(O)
	turtle.down()
	turtle.goto(X)
	turtle.goto(O)
	turtle.color(0,1,0)
	turtle.goto(Y)
	turtle.goto(O)
	turtle.color(0,0,1)
	turtle.goto(Z)
	turtle.goto(O)
	turtle.color(0,0,0)
	turtle.width(1)
示例#18
0
文件: keyboard.py 项目: malsf21/dmcs
def setup(x,y):
	wn.screensize(400,400)	
	#turtle.up()
	turtle.penup()
	turtle.goto(x,y)
	turtle.pendown()
	turtle.width(2)
	turtle.turtlesize(2)
	turtle.color("green")
	turtle.shape("yoda.gif")
	#turtle.down()
	#time.sleep(1)
	wn.listen()
	wn.onkey(home,"t")
	wn.onkey(up, "Up")
	wn.onkey(down, "Down")
	wn.onkey(right, "Right")
	wn.onkey(left, "Left")
	wn.onkey(escaper, "Escape")
示例#19
0
 def basic_actions_parametric (cls):
     actions = {}
     actions[Symbol(' ')] = lambda (obj,s) : obj.nop()
     actions[Symbol('[')] = lambda (obj,s) : obj.push()
     actions[Symbol(']')] = lambda (obj,s) : obj.pop()
     actions[Symbol('F')] = lambda (obj,s) : t.forward(s.parameters[0])
     actions[Symbol('!')] = lambda (obj,s) : t.width(s.parameters[0])
     actions[Symbol('+')] = lambda (obj,s) : t.left(s.parameters[0])
     actions[Symbol('-')] = lambda (obj,s) : t.right(s.parameters[0])
     return actions
示例#20
0
文件: Squares.py 项目: wish343/Python
def drawSquare(size,depth,number):
	walk=0
	#Base condition
	if depth<1:
		return walk
	#Recursion to draw squares
	elif depth>=1:
		for _ in range(4):
			#Calculating how much turtle walked and drawing at the same time
			walk+=drawSquare(size/3,depth-1,number+1)
			if 0==(number%2):
				turtle.width(1)
			if 0!=(number%2):
				turtle.width(4)
			turtle.forward(size)
			walk+=size
			turtle.left(90)
		#return distance walked
		return walk
def sign():
    turtle.color("chocolate")
    turtle.width(5)
    Base((-250,-200))
    turtle.setheading(0)
    turtle.fd(100)
    Tip = turtle.pos()
    turtle.fill(True)
    for x in range (1,5):
        
        
        
        turtle.setheading(turtle.heading() + 90)
        if x % 2 != 0:
            turtle.fd(150)
        else:
            turtle.fd(75)
        if turtle.heading() == 180:
            turtle.fd(25)
            turtle.bk(25)
    turtle.fillcolor('chocolate')
    turtle.fill(False)
    

    def writing():
        turtle.width(1)
        turtle.color("white")
        Base((-250,-100))
        turtle.setheading(162)
        turtle.pu()
        turtle.fd(28)
        turtle.setheading(180)
        turtle.fd(10)
        turtle.write("Raphaella and Danes' ", font=("Calibri", 12, "italic"))
        turtle.fd(14)
        turtle.pd()
        turtle.write("   Apple Tree",font = ("Calibri",12,"bold"))
        
    
    writing()
    turtle.setheading(0)
def tree(length, angle, color, width):
    t.color(color)
    t.width(width)
    t.pendown()

    if length < 10:
        return

    t.forward(length)
    t.left(angle)

    tree(length*0.75, angle, (color[0], color[1] + 3, color[2] + 1), width * 1.03)

    t.right(2 * angle)

    tree(length*0.75, angle, (color[0], color[1] + 3, color[2] + 1), width * 1.03)

    t.left(angle)
    t.color(gcolor)
    t.penup()
    t.back(length)
示例#23
0
def tree(levels, degrees, distance, thickness, scale):
	if levels == 0:
		return
	turtle.width(thickness)
	initial_heading = turtle.heading()
	r, g, b = GREEN[0] + levels*dR, GREEN[1] + levels*dG, GREEN[2] + levels*dB
	turtle.color((r, g, b))
	turtle.forward(distance)
	start = turtle.position()

	turtle.left(degrees)
	tree(levels-1, degrees, scale*distance, scale*thickness, scale)

	turtle.color((r,g,b))
	turtle.up()
	turtle.goto(*start)
	turtle.down()
	turtle.setheading(initial_heading)
	turtle.right(degrees)
	tree(levels-1, degrees, scale*distance, scale*thickness, scale)
	return
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")
示例#25
0
def demo():    
    turtle.width(1)
    turtle.color("black")
    # move out of the way
    turtle.tracer(0)
    turtle.up()
    turtle.right(90)
    turtle.forward(100)
    turtle.right(90)
    turtle.forward(100)
    turtle.right(180)
    turtle.down()        
    turtle.write("start", 1)
    turtle.color("red")    
    for i in range(5):
        turtle.forward(20)
        turtle.left(90)
        turtle.forward(20)
        turtle.right(90)    
    turtle.fill(0)
    turtle.tracer(1)
    # more text
    turtle.write("end")
示例#26
0
def drawPI(padEcart,decimales):
	turtle.color(1,1,1)	
	padAngle = 36
	turtle.width(4)

	turtle.up()
	turtle.goto(0,padEcart)
	turtle.down()

	turtle.begin_fill()
	turtle.circle(-padEcart)
	turtle.end_fill()

	turtle.up()
	turtle.goto(0,padEcart)
	turtle.down()

	cpt = 2
	for decimale in decimales:
		turtle.left(90)
		turtle.forward(padEcart)
		turtle.right(90)
		turtle.circle(-padEcart*cpt,decimale*padAngle)
		cpt += 1
def turtle_graphic(turtle):
  turtle.speed(1)
  turtle.width(3) # set pentagram width
  for i in range(1,6): # pentagram
    turtle.forward(length)
    turtle.right(144)  # now heading 0.0
  turtle.right(108) # or bran.setheading(252) #adjust heading to 252.0
  turtle.width(5) # set outer circle width
  turtle.circle(radius,360) # circle around pentagram
  turtle.width(1) # set inner circles width
示例#28
0
tr.goto(d / 5, d / 4)
tr.color('black', 'blue')
tr.pendown()
tr.begin_fill()
circle(120)
tr.end_fill()
tr.penup()

d_g = 1 / np.sin(np.pi / 120)
tr.goto(4 * d / 5 - d_g, d / 4)
tr.pendown()
tr.begin_fill()
circle(120)
tr.end_fill()
tr.penup()

tr.goto(d / 2, d / 6)
tr.pendown()
tr.width(10)
tr.goto(d / 2, -d / 6)
tr.penup()

tr.goto(5 * d / 6, 0)
smile = int(np.pi / np.arcsin(3 / (2 * d)))
tr.left(180)
tr.color('red')
tr.pendown()
hfcircle(smile)

tr.done()
示例#29
0
import turtle as tl

# 设置笔刷宽度
tl.width(2)

# 向前距离
tl.forward(2)

# 右转
#tl.right(90)
tl.forward(2)

# 笔刷颜色
tl.pencolor('red')
tl.forward(2)

# 窗口等待操作,而不是马上关闭
# tl.done()

# 画五角星

tl.pencolor('red')
for x in range(5):
    tl.forward(100)
    tl.right(144)

# 画图练习
tl.setpos(0, 0)  # 设置笔起点位置
tl.color('red', 'yellow')
tl.begin_fill()
while True:
示例#30
0
__author__ = 'student'
import turtle as tu
tu.penup()
tu.goto(-200, 150)
tu.pendown()
tu.width(2)
tu.color('brown')
tu.speed(6000)


def x(l, n):
    if n == 0:
        return
    x(l, n - 1)
    tu.right(90)
    y(l, n - 1)
    tu.forward(l)
    tu.right(90)


def y(l, n):
    if n == 0:
        return
    tu.left(90)
    tu.forward(l)
    x(l, n - 1)
    tu.left(90)
    y(l, n - 1)


tu.forward(20)
示例#31
0
import turtle as t

t.shape('turtle')
t.color('blue')
t.width(2)
t.speed(8)
count = 0
for i in range(0, 100, 10):
    t.forward(10 + count)
    t.left(90)
    t.forward(20 + count)
    t.left(90)
    t.forward(30 + count)
    t.left(90)
    t.forward(40 + count)
    t.left(90)
    count = 40 + count
input()
示例#32
0
def definir_epaisseur(epaisseur):
    turtle.width(epaisseur)
示例#33
0
import turtle
import time

turtle.pu()
turtle.setpos(-200, 0)
turtle.pd()

turtle.pencolor("brown")
turtle.width(3)

turtle.right(60)
turtle.forward(200)
time.sleep(1.5)
turtle.left(60)
turtle.forward(200)
time.sleep(1.5)
turtle.left(60)
turtle.forward(200)
time.sleep(1.5)
turtle.left(60)
turtle.forward(200)
time.sleep(1.5)
turtle.left(60)
turtle.forward(200)
time.sleep(1.5)
turtle.left(60)
turtle.forward(200)
time.sleep(3)
示例#34
0
import turtle

# 设置色彩模式是RGB:
turtle.colormode(255)

turtle.lt(90)

lv = 14
l = 120
s = 45

turtle.width(lv)

# 初始化RGB颜色:
r = 0
g = 0
b = 0
turtle.pencolor(r, g, b)

turtle.penup()
turtle.bk(l)
turtle.pendown()
turtle.fd(l)


def draw_tree(l, level):
    global r, g, b
    # save the current pen width
    w = turtle.width()

    # narrow the pen width
示例#35
0
 def draw(self, turtle):
     turtle.width(self.width)
     turtle.pencolor(self.color)
     turtle.circle(self.radius)
    bob.left(5)
    bob.forward(1)
bob.forward(20)
for times in range(43):
    bob.right(4)
    bob.forward(0.5)
bob.forward(5)
for times in range(45):
    bob.left(4)
    bob.forward(0.2)
bob.forward(10)
bob.right(110)
bob.forward(15)

#Razer Logo 2nd Line
turtle.width(4)
turtle.color('lime')
turtle.penup()
turtle.left(90)
turtle.left(90)
turtle.forward(350)
turtle.right(90)
turtle.forward(40)
turtle.pendown()
turtle.left(25)
turtle.right(90)
turtle.right(20)
for times in range(10):
    turtle.forward(1)
    turtle.left(2)
for times in range(20):
示例#37
0
import turtle as tr

# set thikness for each ring
tr.width(8)
tr.bgcolor("#f8f9fa")

tr.color("#0081c8")
tr.penup()
tr.goto(-110, -25)
tr.pendown()
tr.circle(50)

tr.color("black")
tr.penup()
tr.goto(0, -25)
tr.pendown()
tr.circle(50)

tr.color("#ee334e")
tr.penup()
tr.goto(110, -25)
tr.pendown()
tr.circle(50)

tr.color("#fcb131")
tr.penup()
tr.goto(-55, -75)
tr.pendown()
tr.circle(50)

tr.color("#00a651")
示例#38
0
#画布
t.setup(800, 800)
#轮廓
t.speed(0)
t.fillcolor('#ffff00')
t.begin_fill()
t.goto((0, 150))
t.left(90)
t.circle(150, 180)
t.fd(300)
t.circle(150, 180)
t.fd(300)
t.end_fill()

#眼睛
t.width(4)
t.fillcolor('white')
t.begin_fill()
t.up()
t.goto((-70, 150))
t.down()
t.circle(40)
t.up()
t.goto(-150, 150)
t.down()
t.circle(40)
t.end_fill()
#眼球
t.width(1)
t.fillcolor('black')
t.begin_fill()
示例#39
0
import turtle
colors = ["red", "purple", "blue", "green", "orange", "yellow"]
turtle.pensize(2)
turtle.bgcolor("black")
for x in range(360):
    turtle.pencolor(colors[x % 6])
    turtle.width((x // 100) + 1)
    turtle.forward(x)
    turtle.left(59)
示例#40
0
#!/usr/bin/python

import turtle

line_size = 6
angle = 45;

while True:
	turtle.forward(line_size)
	line_size += 3
	turtle.left(angle)
	turtle.width( int( line_size/8 ) )

	if turtle.distance(0,0) > 200:
		break
	

turtle.exitonclick()
示例#41
0
 def draw(self, turtle):
     turtle.width(self.width)
     turtle.pencolor(self.color)
     turtle.goto(self.x, self.y)
示例#42
0
# Python program to draw Rainbow Benzene using Turtle programming.

import turtle
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
turtle.pen()
turtle.bgcolor('black')

for x in range(360):
    turtle.pencolor(colors[x % 6])
    turtle.width(x // 6)
    turtle.forward(x)
    turtle.left(45)
示例#43
0
    t.dot(120, 'green')
    t.back(100)
    t.right(120)
    t.forward(100)

    t.dot(120, 'blue')
    t.back(100)
    t.right(120)
    t.update()


def animate():
    if state['turn']:
        state['turn'] -= 1
    spinner()
    t.ontimer(animate, 20)


def flick():
    state['turn'] += 10


t.setup(420, 420, 370, 0)
t.hideturtle()
t.tracer(False)
t.width(20)
t.onkey(flick, 'space')
t.listen()
animate()
t.done()

def move_up():
    canvas.yview_scroll(-1, "units")
    turtle.sety(turtle.ycor() + MAGNIFICATION)


def move_down():
    canvas.yview_scroll(1, "units")
    turtle.sety(turtle.ycor() - MAGNIFICATION)


screen = Screen()
width, height = screen.screensize()
screen.screensize(width * MAGNIFICATION, height * MAGNIFICATION)

canvas = screen.getcanvas()
canvas.config(xscrollincrement=str(MAGNIFICATION))
canvas.config(yscrollincrement=str(MAGNIFICATION))

turtle.width(MAGNIFICATION)
turtle.resizemode('auto')

screen.onkey(move_left, "Left")
screen.onkey(move_right, "Right")
screen.onkey(move_up, "Up")
screen.onkey(move_down, "Down")
screen.listen()

turtle.mainloop()
示例#45
0
import turtle as t
t.setup(600, 600, None,None)
t.pu()
t.fd(-120)
t.pensize(1)
t.width(5)
t.pd()
t.fd(250)
t.seth(120)
t.fd(250)
t.seth(-120)
t.fd(250)
t.fd(250)
t.seth(0)
t.fd(250)
t.fd(250)
t.seth(120)
t.fd(250)
t.seth(-120)
t.fd(250)
t.seth(120)
t.fd(250)
import turtle
happy = turtle.Screen()
happy.bgcolor("black")
turtle = turtle.Turtle()
turtle.shape("turtle")
turtle.color("yellow")
turtle.width()
colors = [
    "peru",
    "ivory",
    "dark orange",
    "coral",
    "cyan",
    "hot pink",
    "gold",
    "ivory",
    "yellow",
    "red",
    "pink",
    "green",
    "blue",
    "light blue",
    "light green",
]


def move(x, y):
    turtle.up()
    turtle.setposition(0, 0)
    turtle.setheading(90)
    turtle.rt(90)
示例#47
0
import turtle
turtle.width(10)

turtle.color("blue")
turtle.circle(50)

turtle.penup()
turtle.goto(120, 0)
turtle.pendown()
turtle.color("black")
turtle.circle(50)

turtle.penup()
turtle.goto(240, 0)
turtle.pendown()
turtle.color("red")
turtle.circle(50)

turtle.penup()
turtle.goto(60, -50)
turtle.pendown()
turtle.color("yellow")
turtle.circle(50)

turtle.penup()
turtle.goto(180, -50)
turtle.pendown()
turtle.color("green")
turtle.circle(50)
# 测试是否上传成功
turtle.color("blue")
示例#48
0
def visualize(hightlighted=200):
    ks, vs = readkvp()
    name_to_highlight = ks[hightlighted - 1]
    highlight_neighbor = ''
    ks, colors = coor2color(ks, vs)

    jplan = {}
    with open(os.path.join(BASE, 'plan.json'), 'r') as in_f:
        jplan = json.load(in_f)

    plan = []
    for i, row in enumerate(jplan[0]):
        plan.append((jplan[0][row]['Aisle'], jplan[0][row]['Window']))
        if jplan[0][row]['Aisle'] == name_to_highlight or jplan[0][row][
                'Window'] == name_to_highlight:
            draw = random.randint(0, max(0, min(i - 1, 15)))
            temp = plan[draw]
            plan[draw] = plan[i]
            plan[i] = temp
            if jplan[0][row]['Aisle'] == name_to_highlight:
                highlight_neighbor = jplan[0][row]['Window']
            else:
                highlight_neighbor = jplan[0][row]['Aisle']

    name2id = dict(zip(ks, (i for i in range(len(ks)))))

    # turtle!!!
    DISTANCE = 27
    WIDTH = 1080
    HEIGHT = 675
    BGPIC = os.path.join(BASE, 'background.png')

    turtle.setup(WIDTH, HEIGHT)
    turtle.bgpic(BGPIC)
    turtle.pencolor('grey')
    turtle.shape("square")
    turtle.colormode(255)
    turtle.shapesize(1.3)
    turtle.width(0)

    turtle.tracer(False)
    turtle.up()
    turtle.goto(-(WIDTH / 2) + 108, (HEIGHT / 2) - 100)

    for _, row in enumerate(jplan[0]):
        plan.append((jplan[0][row]['Aisle'], jplan[0][row]['Window']))

    for i in range(7):
        for j in range(2):
            p = name2id[plan[i][j]]

            turtle.fillcolor(colors[p][0], colors[p][1], colors[p][2])
            turtle.stamp()

            if plan[i][j] == name_to_highlight:
                turtle.shape('circle')
                turtle.fillcolor(255, 255, 255)
                turtle.stamp()
                turtle.shape('square')

            turtle.right(90)
            turtle.forward(int(DISTANCE * 1.07))
            turtle.left(90)
        turtle.forward(int(DISTANCE * 1.545))
        turtle.left(90)
        turtle.forward(2 * int(DISTANCE * 1.07))
        turtle.right(90)

    turtle.forward(215)

    for i2 in range(9):
        i = i2 + 9
        for j in range(2):
            p = name2id[plan[i][j]]

            turtle.fillcolor(colors[p][0], colors[p][1], colors[p][2])
            turtle.stamp()
            turtle.right(90)
            turtle.forward(int(DISTANCE * 1.07))
            turtle.left(90)
        turtle.forward(int(DISTANCE * 1.6))
        turtle.left(90)
        turtle.forward(2 * int(DISTANCE * 1.07))
        turtle.right(90)

    turtle.hideturtle()
    ts = turtle.getscreen()
    ts.getcanvas().postscript(file=os.path.join(BASE, 'plan.eps'))
    im = Image.open(os.path.join(BASE, 'plan.eps'))
    im.show()
    #im.save(os.path.join(BASE, 'plan.jpeg'), "JPEG")
    #ts = turtle.getscreen().getcanvas()
    #canvasvg.saveall(os.path.join(BASE, 'plan.svg'), ts)

    #return 0
    # return he's data, color, as well as his neighbor's
    # or visualize it and return the result?
    ret = json.dumps([{
        'Name': name_to_highlight,
        'Preferences': {
            'Window': vs[hightlighted - 1][0],
            'Sleep': vs[hightlighted - 1][1],
            'Networking': vs[hightlighted - 1][2],
            'WindowShading': vs[hightlighted - 1][3],
        },
        'Color': {
            'R': colors[hightlighted - 1][0],
            'G': colors[hightlighted - 1][1],
            'B': colors[hightlighted - 1][2],
        }
    }, {
        'Name': highlight_neighbor,
        'Preferences': {
            'Window': vs[name2id[highlight_neighbor]][0],
            'Sleep': vs[name2id[highlight_neighbor]][1],
            'Networking': vs[name2id[highlight_neighbor]][2],
            'WindowShading': vs[name2id[highlight_neighbor]][3],
        },
        'Color': {
            'R': colors[name2id[highlight_neighbor]][0],
            'G': colors[name2id[highlight_neighbor]][1],
            'B': colors[name2id[highlight_neighbor]][2],
        }
    }])
    return ret


#if __name__ == '__main__':
#visualize()
    turtle.right(90 + angle / 2)

    for i in range(3):
        turtle.begin_fill()
        sector(radius1, angle)
        turtle.left(120)
        turtle.color(outlinecol)
        turtle.end_fill()

    turtle.up()
    turtle.forward(radius2)
    turtle.left(90)
    turtle.down()

    turtle.color(fillcol)
    turtle.begin_fill()
    turtle.circle(radius2)
    turtle.color(outlinecol)
    turtle.end_fill()

    turtle.up()
    turtle.left(90)
    turtle.forward(radius2)
    turtle.width(1)


turtle.reset()
turtle.width(5)
turtle.speed(100)
radioactive(160, 36, 400)
turtle.mainloop()
示例#50
0
import turtle

import time

'''

t = turtle.Pen()

for x in range(360):
    t.forward(x)
    t.left(59)
'''
turtle.width(8)
turtle.color("blue")
turtle.circle(50)

turtle.penup()
turtle.goto(120,0)

turtle.pendown()
turtle.color("red")
turtle.circle(50)

turtle.penup()
turtle.goto(240,0)

turtle.pendown()
turtle.color("green")
turtle.circle(50)

turtle.penup()
import turtle as tr

tr.shape('turtle')
tr.turtlesize(2)
tr.width(3)
tr.color('springgreen')
tr.goto(0, 0)
for i in range(10):
    tr.fd(200)
    tr.stamp()
    tr.goto(0, 0)
    tr.right(36)
tr.exitonclick()
示例#52
0
 def drawoutsquare(self,x,y, dim):   #draw the thick outline squares
     turtle.width(5)
     turtle.penup()
     turtle.goto(x,y)
     turtle.pendown()
     self.drawsquare(dim)
示例#53
0
t.pendown()
t.begin_fill()
figR(60, 1)  # first one
t.end_fill()
left(180)
t.penup()
go(90)
t.pendown()
t.begin_fill()
figL(60, 1)  # second one
t.end_fill()
t.penup()
left(180)
go(45)
right(90)
go(45)
t.pendown()
t.width(9)
t.color('black')
go(30)  # nose
t.penup()
go(20)
left(90)
go(40)
t.color('red')
t.pendown()
right(90)
figN(250, 1)

input()
示例#54
0
文件: hw5.py 项目: eyaroslavsky/CS115
'''
Created on 10/9/18
@author: Edward Yaroslavsky eyarosla
Pledge: I pledge my honor that I have abided by the Stevens Honor System.

CS115 - Hw 5
'''
import turtle  # Needed for graphics

# Ignore 'Undefined variable from import' errors in Eclipse.

width = 16
turtle.left(90)
turtle.pencolor("brown")
turtle.width(width)


def sv_tree(trunk_length, levels):
    '''Draws a tree of levels amount of recursive branches with decreasing
    trunk_length size after every level.'''
    if levels > 0:
        if levels == 1:
            turtle.pencolor("green")
        else:
            turtle.pencolor("brown")
        turtle.forward(trunk_length)
        turtle.width(width // 2)
        turtle.right(30)
        sv_tree(trunk_length // 2, levels - 1)
        turtle.left(60)
        sv_tree(trunk_length // 2, levels - 1)
示例#55
0
t.forward(150)
t.pendown()
t.right(90)  # it's again facing forward

# red square V2
t.pencolor("red")
for i in range(4):
    t.forward (100)
    t.left(90)

# advancing pen backward
t.penup()
t.backward(150)
t.pendown()

t.width(3) # thicker line

# blue square 
t.pencolor("blue")
for i in range(4):
    t.forward (100)
    t.left(90)

# advancing pen backward
t.penup()
t.backward(150)
t.pendown()

# filling the square with a color 
t.pencolor("green")
t.fillcolor("violet")
# TURTLES
# ------------------------------------------------------------------------------
# To use turtles we must first import the package.
import turtle

# EXERCISE 0: (Optional) Customize your turtles appearance.
# ------------------------------------------------------------------------------
# You can change the appearance of the turtle using the following commands
turtle.color("blue")
turtle.shape("turtle")
turtle.turtlesize(2)
turtle.width(5)

# EXERCISE 1: Make your turtle walk in a square.
# ------------------------------------------------------------------------------
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)

# EXERCISE 2: Using a loop make your turtle walk in a square.
# ------------------------------------------------------------------------------
for side in range(4):
    turtle.forward(100)
    turtle.right(90)

# EXERCISE 3: Make your turtle walk in an n-sided shape.
示例#57
0
#!/usr/bin/env python3

import turtle as t
import random as r
title = 'Rainbow Star'
t.title(title)
t.showturtle()
t.colormode(255)
t.speed(5)
t.width(3)


def star():
    x = 1
    if x == 1:
        while x == 1:
            t.color(r.randrange(0, 255), r.randrange(0, 255),
                    r.randrange(0, 255))
            t.begin_fill()
            t.forward(150)
            t.left(220)
            t.end_fill()
    elif x == 0:
        print('Failed to loop')
    else:
        print('Fatal Error! Please Reinstall.')


star()
示例#58
0
import turtle as t
t.setup()
t.bgcolor("black")
t.speed(100)
sides = 6
colors = ["red", "yellow", "lime", "deepskyblue", "orange", "mediumorchid"]
for i in range(230):
    t.pencolor(colors[i % sides])
    t.fd(i * 3 / sides + i)
    t.left(360 / sides + 1)
    t.width(i * sides / 200)
t.done
示例#59
0
import turtle
happy = turtle.Screen()
happy.setup(700, 700)
happy.bgpic("bdday.gif")
turtle = turtle.Turtle()
turtle.shape("turtle")
turtle.width(5)
turtle.speed(150)


def mov(x, y):
    turtle.up()
    turtle.setposition(0, 0)
    turtle.setheading(90)
    turtle.lt(90)
    turtle.fd(x)
    turtle.rt(90)
    turtle.fd(y)
    turtle.pendown()


#letters
def A():
    turtle.rt(16)
    turtle.forward(60)
    turtle.rt(150)
    turtle.fd(60)
    turtle.backward(30)
    turtle.rt(105)
    turtle.fd(15)
示例#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()