コード例 #1
46
ファイル: turtle_comp.py プロジェクト: silentShadow/CSC101
def main():
    program_key = '''
*** Welcome to Computer Turtle ***

Character       Meaning
f...............move turtle forwad
b...............move turtle backward
l...............turn turtle left
r...............turn turtle right
u...............pen up
d...............pen down

'''
    print( program_key)
    print( "Right click the turtle for more info...")
    get_command()
    t.listen()
    t.onclick( pos, 2)
    inititals()

    t.mainloop()
コード例 #2
15
ファイル: paintOrr.py プロジェクト: orr16-meet/MEET-YL1
def brush_square_blue(x,y):
    turtle.begin_fill()
    turtle.color("blue")
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()
    turtle.goto(x+50,y)
    turtle.goto(x+50,y+50)
    turtle.goto(x,y+50)
    turtle.goto(x,y)
    turtle.end_fill()




turtle.onclick(brush_circle_red, btn=1, add=True)
turtle.onscreenclick(brush_circle_red, btn=1, add=True)
turtle.ondrag(brush_circle_red, btn=1, add=True)


turtle.onclick(brush_square_red, btn=3, add=True)
turtle.onscreenclick(brush_square_red, btn=3, add=True)
turtle.ondrag(brush_square_red, btn=3, add=True)




turtle.listen()
turtle.mainloop()
コード例 #3
0
def f():
    fd(50)
    lt(60)

onscreenclick(makeStamp) # 鼠标绑定
onkey(f, "Up") # 键盘绑定
listen()  # set focus on screen / 不加这一句 onkey 不起作用, 但是  onclick 可以 

done()    # 在 命令行(不马上退出) 或 ipython (能获取焦点)  中执行需要

"""
mainloop()  # 在命令行中执行 
Starts event loop - calling Tkinter's mainloop function.
Must be last statement in a turtle graphics program.
"""


"""
onclick / onrelease 不起作用, 待调试

from turtle import *
class MyTurtle(Turtle):
    def glow(self,x,y):
        self.fillcolor("red")
    def unglow(self,x,y):
        self.fillcolor("")

turtle = MyTurtle()
turtle.onclick(turtle.glow)     # clicking on turtle turns fillcolor red,
turtle.onrelease(turtle.unglow) # releasing turns it to transparent.
"""
コード例 #4
0
#-----game configuration----
filclr = "red"
size = 3
shape = "triangle"
score = 0

#-----initialize turtle-----
triangle.shape(shape)
triangle.shapesize(size)
triangle.fillcolor(filclr)

#-----game functions--------
def tri_clicked(x,y):
    change_position()

def change_position():
    new_xpos = rand.randint(-200,200)
    new_ypos = rand.randint(-150,150)
    triangle.penup()
    triangle.hideturtle()
    triangle.goto(new_xpos,new_ypos)
    triangle.showturtle()



#-----events----------------
triangle.onclick(tri_clicked)

wn = triangle.Screen()
wn.mainloop()
コード例 #5
0
    # this command hides the turtle so that the drawing process speeds up
    turtle.ht()

    # moving turtles randomly on the screen
    turtle.right(random.randrange(361))
    turtle.shape("turtle")

    # adapts the appearance of the turtle according to the values of outline
    turtle.resizemode("user")
    n = random.uniform(0.5, 1)
    turtle.shapesize(n, n, n)
    # make the turtle visible
    turtle.st()


# if turtle gets caught by other turtle, it resets and starts appearing again
def caught(x, y):
    for turtle in wn.turtles():
        turtle.reset()
        turtle.penup()


while 1:

    for turtle in wn.turtles():
        turtle.forward(2)
        # return an random integer in the interval (-30,0)
        turtle.right(33 - random.randrange(63))
        # when the user clicks on the turtle, it triggers function caught and the turtles restart again
        turtle.onclick(caught)
コード例 #6
0
ファイル: star.py プロジェクト: TrevorSpear/OSU-CS-160
import turtle
window = turtle.Screen()
my_turtle = turtle.Turtle
turtle.color("red")
window.bgcolor("black")
##turtle.hideturtle()
turtle.right(90)
turtle.right(22.5)
def star(x,y):

	turtle.clear()
	for x in range(0,5):

		turtle.forward(120)
		turtle.left(144)
	
turtle.onclick(star)
window.mainloop()
コード例 #7
0
    turtle.penup()


def p():
    turtle.forward(25)
    turtle.pendown()
    turtle.forward(25)
    turtle.left(90)
    turtle.forward(25)
    turtle.left(90)
    turtle.forward(25)
    turtle.left(90)
    turtle.forward(50)
    turtle.penup()


def main(x, y):
    turtle.clear()
    j()
    a()
    z()
    d()
    e()
    e()
    p()


turtle.onclick(main)

window.mainloop()
コード例 #8
0
    turtle.rt(90)
    turtle.fd(16)
    turtle.penup()
    turtle.lt(90)
    turtle.fd(30)
    turtle.lt(90)
    turtle.fd(50)
    turtle.pendown()  #Lower-case l
    turtle.rt(180)
    turtle.fd(50)
    turtle.penup()
    turtle.lt(90)
    turtle.fd(40)
    turtle.lt(90)
    turtle.fd(50)
    turtle.rt(180)
    turtle.pendown()  #Lower-case d
    turtle.fd(50)
    turtle.rt(90)
    turtle.fd(10)
    turtle.circle(-12, 180)
    turtle.fd(10)
    turtle.penup()  #END
    turtle.fd(90)  #Turtle repositioning
    turtle.fd(100)
    turtle.rt(90)


turtle.onclick(name)  #Restarts when turtle is clicked again
window.mainloop()
コード例 #9
0
def straight(x, y):
    turtle.reset()
    turtle.forward(100)
    turtle.right(144)
    turtle.forward(100)
    turtle.right(144)
    turtle.forward(100)
    turtle.right(144)
    turtle.forward(100)
    turtle.right(144)
    turtle.forward(100)
    turtle.right(144)


turtle.onclick(straight)

run = True


def start():
    #	char=list(main)
    #	valid=["c", "C", "e", "E", "l", "L", "i", "I", "f", "F", "h", "H"]
    #	if valid[1] or valid[2] or valid[3] or valid[4] or valid[5] or valid[6] or valid[7] or valid[8] or valid[9] or valid[10] or valid[11] or valid[12]:
    #	main=str(input("Please choose any of the follwing six letters to see them printed out in ASCII art (C, E, L, I, F, H). Or type 'quit' to leave the loop: "))
    string1 = str(len(main))
    list1 = list(main)
    i = 0

    #	main=str(input("Please choose any of the follwing six letters to see them printed out in ASCII art (C, E, L, I, F, H). Or type 'quit' to leave the loop: "))
    turtle.reset()
コード例 #10
0
    column = 0
    row = 0
    for letter in text:
        draw_letter_at_box(letter, row, column)
        column = column + 1
        if column == 12:
            row = row + 1
            column = 0


def calledWhenOnClicked(x, y):
    text = turtle.textinput('Text Input',
                            "Enter Text(letters and spaces only)")
    turtle.clear()
    write_text(text.upper())
    turtle.pu()
    turtle.home()


################################## entry starts here ###################
turtle.title(
    'Turtle Text Drawing - Click the turtle to draw letters by entering text')

turtle.pensize(5)
turtle.pu()
turtle.home()
turtle.onclick(calledWhenOnClicked)
draw_alphabet()
turtle.home()
turtle.mainloop()
コード例 #11
0
ファイル: name.py プロジェクト: jrotithor/CS_160
	turtle.left(90);
	turtle.forward(30);
	turtle.penup();



def p():
	turtle.forward(25);
	turtle.pendown();
	turtle.forward(25);
	turtle.left(90);
	turtle.forward(25);
	turtle.left(90);
	turtle.forward(25);
	turtle.left(90);
	turtle.forward(50);
	turtle.penup();

def main(x,y):
	turtle.clear();
	j();
	a();
	z();
	d();
	e();
	e();
	p();
turtle.onclick(main);

window.mainloop();
コード例 #12
0
ファイル: myturtle.py プロジェクト: NilushaNaresh/turtle
def left():
    my_turtle.setheading(180)
    my_turtle.forward(100)


def right():
    my_turtle.setheading(0)
    my_turtle.forward(100)


def clickleft(x, y):
    my_turtle.color(random.choice(colors))


def clickright(x, y):
    my_turtle.stamp()


turtle.listen()

turtle.onclick(clickleft, 1)
turtle.onclick(clickright, 3)

turtle.onkey(up, 'Up')
turtle.onkey(down, 'Down')
turtle.onkey(left, 'Left')
turtle.onkey(right, 'Right')

turtle.mainloop()
コード例 #13
0
ファイル: moretesting.py プロジェクト: Nstremmel/projects
def left():
    i.fd(50)
    i.left(90)
    i.fd(50)
    i.setheading(90)


def move():
    i.color("blue")
    t.onkey(right, "Right")
    t.onkey(left, "Left")
    t.listen()


#Gameplay
##########################################################################################################################
# input ("To pick who goes first, choose a player 1 and player 2. Press ENTER when you are finished.")
# sleep (.2)
# choice = randint(1,2)
# print ("")
# print ("Player " + str(choice) + ", you will go first. (You are Red)")

while True:
    sleep(.1)
    for i in pieces:
        if i in red:
            print("check")
            t.onclick(move)
            t.listen()
            sleep(.5)
コード例 #14
0
ファイル: star.py プロジェクト: jrotithor/CS_160
import turtle
window = turtle.Screen();
turtle = turtle.Turtle();
turtle.setheading(324);
def drawstar(x,y):
	turtle.clear();
	for x in range (0,5):
		turtle.forward(100);
		turtle.left(144);
		x += 1;
turtle.onclick(drawstar);
window.mainloop();
コード例 #15
0
ファイル: tamarb.py プロジェクト: tamar16-meet/MEET-YL1
def brush_b_square(x,y):
    turtle.begin_fill()
    turtle.color("blue")
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()
    turtle.goto(x+50,y)
    turtle.goto(x+50,y+50)
    turtle.goto(x,y+50)
    turtle.goto(x,y)
    turtle.end_fill()

'''


turtle.onclick(brush_b_circle,btn=1, add=True)
turtle.onscreenclick(brush_b_circle,btn=1, add=True)

turtle.onclick(brush_b_square,btn=3, add=True)
turtle.onscreenclick(brush_b_square,btn=3, add=True)

def change_to_red():
    turtle.color("red")
    turtle.pencolor("red")
turtle.onkeypress(change_to_red, "r")

def change_to_blue():
    turtle.color("blue")
    turtle.pencolor("blue")
turtle.onkeypress(change_to_blue, "b")
    
コード例 #16
0
ファイル: logoclok.py プロジェクト: slott56/HamCalc-2.1
    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 stop(x,y):
    print( "Stopping" )
    running= False
    turtle.bye()

#turtle.speed("fastest") # Doesn't much matter
turtle.hideturtle()
turtle.tracer(False) # Essential in order to eliminate animation.
face(tick_circles)

turtle.onclick(stop)
now= datetime.datetime.now()
wait= 1000-(now.time().microsecond//1000)
turtle.ontimer( hands, wait )
print( "Initial wait", wait, "ms after", now.strftime("%H:%M:%S" ) )
turtle.mainloop()

コード例 #17
0
def main():
    # Bind handlers with the mouse-click event
    turtle.onclick(displayMousePoint)
    turtle.onclick(displayCircle, add = True)
 
    turtle.done() 
コード例 #18
-1
ファイル: test.py プロジェクト: doraithodla/Pyteach
def main():
    #t.speed(20)
    #t.shapesize(1000,1000)
    t.up()
    t.goto(1000,0)
    #t.ht()
    #t.onkey(showTurtle,"a")
    #t.listen()
    t.onclick(getPos)
    t.onrelease(hideTurtle)
    t.mainloop()
    raw_input(">")
コード例 #19
-1
import turtle

#t = turtle.Pen()
#t.reset()
#t.forward(100)
#t.right(90)
#t.forward(100)
#t.right(90)
#t.forward(100)
#t.right(90)
#t.forward(100)
#t.hideturtle()

turtle.Pen()
turtle.forward(100)

class MyTurtle(turtle):
    def glow(self,x,y):
        self.fillcolor("red")
    def unglow(self,x,y):
        self.fillcolor("")


turtle = MyTurtle()
turtle.onclick(turtle.glow)
turtle.onrelease(turtle.unglow)