Exemple #1
15
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()
def dragging(x, y):
    t.ondrag(None)
    t.setheading(t.towards(x, y))
    t.goto(x, y)
    t.ondrag(dragging)
    global cleared
    cleared = False
Exemple #3
0
def main():
    turtle.listen()

    turtle.ondrag(dragging)

    turtle.onscreenclick(clickright,3)

    turtle.mainloop()
Exemple #4
0
def drag_handler(x, y):
    if state != DRAGGING:  # ignore stray events
        return

    turtle.ondrag(None)  # disable event inside event handler
    turtle.pendown()
    turtle.setheading(turtle.towards(x, y))
    turtle.goto(x, y)
    turtle.ondrag(drag_handler)  # reenable event on event handler exit
def dragging(x, y):
    global colors
    turtle.ondrag(None)
    color1 = random.choice(colors)
    color2 = random.choice(colors)
    tim.color(color1, color2)
    tim.setheading(tim.towards(x, y))
    tim.goto(x, y)
    turtle.ondrag(dragging)
Exemple #6
0
def release_handler(x, y):
    global state

    turtle.onrelease(None)  # disable until click
    turtle.ondrag(None)  # disable competing handler

    turtle.onclick(click_handler)  # watch for click event
    onmove(screen, move_handler)  # dragging is now motion until click

    state = MOVING
Exemple #7
0
def click_handler(x, y):
    global state

    turtle.onclick(None)  # disable until release
    onmove(screen, None)  # disable competing handler

    turtle.onrelease(release_handler)  # watch for release event
    turtle.ondrag(drag_handler)  # motion is now dragging until release

    state = DRAGGING
Exemple #8
0
def draw(x, y):
    turtle.ondrag(None)
    turtle.goto(x, y)
    for i in range(1, number_of_divisions):
        if i < 4:
            new_x = x * xt[i]

            new_y = y * yt[i]
        else:

            new_y = x * xt[i]

            new_x = y * yt[i]

        allTurtles[i].goto(new_x, new_y)

    turtle.update()
    turtle.ondrag(draw)
def draw(x, y):
    print(x, y)
    turtle.ondrag(None)
    turtle.goto(x, y)
    xt = [1, 1, -1, -1, 1, 1, -1, -1]
    yt = [1, 1, -1, -1, 1, 1, -1, -1]
    for a in range(1, number_of_divisions):
        new_x = x
        new_y = y
        if a < 4:
            new_x = x * xt[a]
            new_y = y * yt[a]
        else:
            new_x = y * yt[a]
            new_y = x * xt[a]
        allTurtles[a].goto(new_x, new_y)
    turtle.update()
    turtle.ondrag(draw)
Exemple #10
0
def dragging(x,y):
    turtle.ondrag(None)
    turtle.setheading(turtle.towards(x,y))
    turtle.goto(x,y)
    turtle.ondrag(dragging)
Exemple #11
0
	turtle.shapesize(lengthSize+1,widthSize+1)
	lengthSize += 1
	widthSize += 1
turtle.onkeypress(enlarge,"equal")
def reduceSize():
	global lengthSize
	global widthSize
	turtle.resizemode("user")
	if lengthSize > 1 and widthSize >1:
		turtle.shapesize(lengthSize-1,widthSize-1)
		lengthSize -= 1
		widthSize -= 1
	else:
		turtle.shapesize(1,1)
		lengthSize = 1
		widthSize = 1
turtle.onkeypress(reduceSize,"minus")
#Stamp function and definition
def stamp(x,y):
	turtle.pu()
	turtle.goto(x,y)
	turtle.stamp()

turtle.ondrag(stamp, btn = 1, add = True)
######
turtle.onscreenclick(turtle.goto, btn = 1, add = True)
turtle.onkeypress(turtle.clear, "space")
print(turtle.shapesize(), turtle.turtlesize())
turtle.getscreen().listen()
turtle.mainloop()
t.goto(-250,0)
t.pendown()
t.showturtle()
t.pensize(1)

#이동(그리기)함수
def goto(x,y):
    t.goto(x,y)

#점 인쇄 함수
def dotprod():
    t.dot(12, 'purple')
    x0.append(t.xcor())
    y0.append(t.ycor())
    threading.Timer(0.2, dotprod).start()


#함수 실행 ###########################################################
t.ondrag(goto)
dotprod()
# s.onkeypress(dotprod, 'a')
# s.listen()

t.done()

#리스트 중복 제거를 위한 함수 선언
def getx():
    return x0
def gety():
    return y0
Exemple #13
0
            new_x = x * xt[i]

            new_y = y * yt[i]
        else:

            new_y = x * xt[i]

            new_x = y * yt[i]

        allTurtles[i].goto(new_x, new_y)

    turtle.update()
    turtle.ondrag(draw)


turtle.ondrag(draw)

colours = [
    "black", "tomato", "spring green", "slate blue", "turquoise", "orchid",
    "gold"
]


def click(x, y):
    if x <= -130:
        for thisTurtle in allTurtles:
            thisTurtle.color(colours[0])
    elif x <= -80:

        for thisTurtle in allTurtles:
            thisTurtle.color(colours[1])
Exemple #14
0
def draw_canvas2():
    draw_circle()
    turtle.color('red', 'red')
    turtle.onscreenclick(turtle.goto,btn=1,add=True)
    turtle.ondrag(turtle.goto,btn=1,add=True)
Exemple #15
0
#clear
def clear():
	turtle.clear()
#COLOR CHANGING
def Switch_color1():
	turtle.color("red")

def Switch_color2():
	turtle.color("blue")
#when pressing O, change color

turtle.getscreen().onkeypress(Switch_color2,"o")
#press p = change color 
turtle.getscreen().onkeypress(Switch_color1, "p")
#clear
turtle.getscreen().onkeypress(clear, "c")



#dragging left click

turtle.ondrag(stamp1, btn=1, add=True)

#dragging right click

turtle.ondrag(stamp2, btn=2, add=True)


turtle.getscreen().listen()
turtle.mainloop()
"""
    This program acts like a sketchbook.
    Drag the turtle to draw freely on the window.
"""

import turtle

# This function jumps the turtle to the place clicked on the screen.
def jump(x, y):
    turtle.up()
    turtle.goto(x, y)
    turtle.down()

turtle.reset()

turtle.shape("turtle")
turtle.pencolor("blue") # Color is set to blue
turtle.pensize(3) # Pensize is set to 3

turtle.onscreenclick(jump)
turtle.ondrag(turtle.goto) # The goto function uses the x and y coordinates passed by ondrag event
turtle.speed(0)

turtle.done()
Exemple #17
0
#NEW FUNCTION #2
#fills turtle color w/ violet and black border
turtle.fillcolor("violet")

#turtle does function without leaving a trace(invisible)
def fun():
  turtle.penup()
  turtle.goto(100,100)
  turtle.pendown()
  turtle.dot(100, "lightgreen") #creates a lightgreen dot at the point (50, 50)
#NEW EVENT #1
turtle.onrelease(fun())

#when the user drags the turtle, it creates a drawing
#if the penup function is used, the user can drag the turtle anywhere leaving an invisible trail
turtle.penup()
#NEW EVENT #2
turtle.ondrag(turtle.goto)

#makes the turtle black and makes it write text with parameters
turtle.color("black")
turtle.write("Move the turtle inside the blue circle", move = True, align = "right", font=("Arial", 13, "normal"))

#creates a function where the turtle writes text with parameters
#makes the function run after 6000 milliseconds on a timer
def function():
  turtle.write("Good Job!   ", move = True, align = "right", font=("Arial", 13, "normal"))
screen = turtle.Screen()
screen.ontimer(function, 6000) # runs function fun after 360 milliseconds
Exemple #18
0
def orsom(event):    
    turtle.ondrag(turtle.goto, add=True)
Exemple #19
0
def dragg(turtle, x, y):
    turtle.up()
    turtle.ondrag(None)  # disable ondrag event inside drag_handler
    turtle.goto(x, y)
    turtle.ondrag(lambda x, y, turtle=turtle: dragg(turtle, x, y))
Exemple #20
0
def circle(x,y):
	turtle.begin_fill()
	turtle.penup()
	turtle.goto(x,y)
	turtle.pendown()
	turtle.circle(30)
	turtle.color("red", "green")
	turtle.color()
	('red', 'green')
	color("#285078", "#a0c8f0")
	color()
	((40.0, 80.0, 120.0), (160.0, 200.0, 240.0))
	
turtle.onscreenclick(circle,btn=1,add=True)
turtle.ondrag(circle)

evyatar=turtle.Turtle()

def square(x,y):
	evyatar.penup()
	evyatar.goto(x,y)
	evyatar.pendown()
	evyatar.goto(x-40,y)
	evyatar.goto(x-40,y-40)
	evyatar.goto(x,y-40)
	evyatar.goto(x,y)

turtle.onscreenclick(square,btn=3,add=True)
evyatar.ondrag(square)
Exemple #21
0
def draw_canvas3():
    draw_triangle(0, 0)
    turtle.color('red', 'red')
    turtle.onscreenclick(turtle.goto, btn=1, add=True)
    turtle.ondrag(turtle.goto, btn=1, add=True)
Exemple #22
0
def draw_canvas2():
    draw_circle()
    turtle.color('red', 'red')
    turtle.onscreenclick(turtle.goto, btn=1, add=True)
    turtle.ondrag(turtle.goto, btn=1, add=True)
import turtle

turtle.ondrag(turtle.goto)

turtle.done() 
Exemple #24
0
def Bigger():
	global size
	size=size+10


def Smaller():
	global size
	size=size-10


turtle.getscreen().onkeypress(finish,"e")

turtle.getscreen().onkeypress(switch,"s"or"S")

turtle.getscreen().onkeypress(color,"c"or"C")

turtle.getscreen().onkeypress(Bigger,"8")

turtle.getscreen().onkeypress(Smaller,"9")

turtle.ondrag(draw,1,add=True)

turtle.onscreenclick(draw)

turtle.pu()

turtle.getscreen().listen()

turtle.mainloop()

Exemple #25
0
def drawwhenuclick1(x,y):# (-200,200 is the original point)
    turtle.ondrag(None)
    print(x,y)
    
    locationx=0
    locationy=0
    if x>-200 and x<-170:
        locationx = 13
    elif x>-170 and x<-140:
        locationx = 12
    elif x>-140 and x<-110:
        locationx = 11
    elif x>-110 and x<-80:
        locationx = 10
    elif x>-80 and x<-50:
        locationx = 9
    elif x>-50 and x<-20:
        locationx = 8
    elif x>-20 and x<10:
        locationx = 7
    elif x>10 and x<40:
        locationx = 6
    elif x>40 and x<70:
        locationx = 5
    elif x>70 and x<100:
        locationx = 4
    elif x>100 and x<130:
        locationx = 3
    elif x>130 and x<160:
        locationx = 2
    elif x>160 and x<190:
        locationx = 1
    if y>170 and y<200:
        locationy = 13
    elif y>140 and y<170:
        locationy = 12
    elif y>110 and y<140:
        locationy = 11
    elif y>80 and y<110:
        locationy = 10
    elif y>50 and y<80:
        locationy = 9
    elif y>20 and y<50:
        locationy = 8
    elif y>-10 and y<20:
        locationy = 7
    elif y>-40 and y<-10:
        locationy = 6
    elif y>-70 and y<-40:
        locationy = 5
    elif y>-110 and y<-70:
        locationy = 4
    elif y>-140 and y<-110:
        locationy = 3
    elif y>-170 and y<-140:
        locationy = 2
    elif y>-200 and y<-170:
        locationy = 1
    if locationx!=0 and locationy!=0:
        draw(width,locationx,locationy,"orange")
    turtle.ondrag(drawwhenuclick1)
Exemple #26
0
    # c. Place the crocodile (enemy) in the left hand side randomly
    enemy.up()
    x = -(window_width + enemy_width) / 2
    y = random.randint(-(river_width-enemy_height)/2, (river_width-enemy_height)/2)
    enemy.goto(x, y)

    # d. Add the new crocodile (enemy) to the list 'enemies'
    enemies.append(enemy)

    # 5.1.2. Generate a random speed and store it in 'enemy_speeds'
    for _ in range(number_of_enemies): 
        enemy_speeds.append(random.randint(enemy_speed_min, enemy_speed_max))

# Prepare the player turtle
turtle.shape("turtle")
turtle.left(180)
turtle.color("GreenYellow")
turtle.up()

# Part 2 (1 of 2)
# 2.1 Set up event handlers
#    The event handler for turtle.ondrag()
turtle.ondrag(moveplayerturtle)
# Part 3 (2 of 4)
# The event handler for turtle.ontimer()
# 3.2. Schedule the first update
#    It starts the main loop and starts the game
turtle.ontimer(updatescreen,update_interval)
turtle.update()
turtle.done()
Exemple #27
0
def height_square():
  
  global size 
  global color
  
  turtle.begin_fill()
  turtle.fillcolor(color)

  turtle.penup()
  turtle.right(90
  turtle.forward(1.25 * size)
  turtle.left(90)
  turtle.pendown()
  turtle.forward(5 * size)
  turtle.right(90)
  turtle.forward(2.5 * size)
  turtle.right(90)
  turtle.forward(5 * size)
  turtle.right(90)
  turtle.forward(2.5)
  turtle.right(90)

  turtle.end_fill()

def star_4():
  
  global size
  global color

  turtle.penup()
  turtle.right(90)
  turtle.forward(2)
  turtle.left(60)
  tirtle.pendown()
  
  turtle.begin_fill()
  turtle.fillcolor(color)
  
  turtle.forward(2.25 * size)
  turtle.right(30)
  turtle.forward(2.25 * size)
  turtle.left(120)
  turtle.forward(2.25 * size)
  turtle.right(30)
  turtle.forward(2.25 * size)
  turtle.left(120)
  turtle.forward(2.25 * size)
  turtle.right(30)
  turtle.forward(2.25 * size)
  turtle.left(120)
  turtle.forward(2.25 * size)
  turtle.right(30)
  turtle.forward(2.25 * size)
  turtle.left(120)

  turtle.end_fill()

def star_5():
  
  global size
  global color

  turtle.penup()
  turtle.tight(9)
  turtle.forward(2)
  turtle.left(60)
  turtle.pendown()
  
  turtle.begin_fill()
  turtle.colorfill(color)
  
  turtle.forward(2 * size)
  turtle.right(120)
  turtle.forward(2 * size)
  turtle.left(120)
  turtle.forward(2)
  turtle.right(30)
  turtle.forward(2)
  turtle.left(120)
  turtle.forward(2 * size)
  turtle.right(30)
  turtle.forward(2 * size)
  turtle.left(120)
  turtle.forward(2 * size)
  turtle.right(30)
  turtle.forward(2 * size)
  turtle.left(120)
  turtle.forward(2 * size)
  turtle.right(30)
  turtle.left(120)

  turtle.end_fill()
def change_shape():

  global shape

  shape = shape_list[cs]
  cs = cs + 1
  if cs >= len(shape_list)
    cs = 0 



def make_shape():
  
  global shape
  
  if shape == "circle"
    turtle.circle()
  elif shape == "square"
    turtler.square()
  elif shape == "triangle"
    turtle.triangle
  elif shape == "square_width"
    turtle.square_width()
  elif shape== "square_height"
    turtle.square_height()
  elif shape=="star_4"
    turtle.star_4()
  elif shape=="star_5"
    turtle.star_5()
  elif shape == "nothing"
  else  print "error"

  

turtle.getscreen().onkeypress(hide/see_turtle(),"v")
turtle.getscreen().onkeypress(size_big(),"add")
turtle.getscreen().onkeypress(size_small(),"minus")
turtle.getscreen().onkeypress(change_color,"c")
turtle.getscreen().onkeypress(change_shape,"s")
turtle.onscreenclick(make_shape(),btn = 1,add = True)
turtle.ondrag(make_shape(),btn = 1,add = True)

turtle.getscreen().listen()
turtle.mainloop()
cleared = True


def dragging(x, y):
    t.ondrag(None)
    t.setheading(t.towards(x, y))
    t.goto(x, y)
    t.ondrag(dragging)
    global cleared
    cleared = False


screen = Screen()

t.ondrag(dragging)


def many_circles():
    for i in range(50, 155, 5):
        the(i)


def flower():
    for i in range(8):
        many_circles()
        left()
    t.penup()


def the(radius):
def click_right_mouse_button(x, y):
    tim.stamp()


def click_x_key():
    turtle.clearscreen()


turtle.color('black')
tim.hideturtle()
style = ('Courier', 10, 'bold')
turtle.write(
    "press arrow keys,right and left click and drag the turtle from its starting position",
    font=style,
    align='center')
time.sleep(6)
tim.showturtle()
turtle.clearscreen()

turtle.onscreenclick(click_left_mouse_button, 1)
turtle.onscreenclick(click_right_mouse_button, 3)
turtle.ondrag(dragging)
turtle.onkey(click_x_key, 'x')
turtle.onkey(up, 'Up')
turtle.onkey(down, 'Down')
turtle.onkey(right, 'Right')
turtle.onkey(left, 'Left')
turtle.listen()
turtle.mainloop()
Exemple #30
0
def movearound():
    my_ball.goto(turtle.getcanvas().winfo_pointerx() - screen_width * 2,
                 screen_height * 2 - turtle.getcanvas().winfo_pointery())
    turtle.ondrag(turtle.goto)
Exemple #31
0
import turtle
turtle.speed(0)
from random import randint 
def  circle(x,y ):
	turtle.pencolor("brown")
	turtle.color("brown")
	turtle.penup()
	turtle.goto(x,y)
	turtle.pendown()
	turtle.begin_fill()
	turtle.circle(15)
	turtle.end_fill()


turtle.onscreenclick(circle, add=True)
turtle.ondrag(circle)
turtle.pencolor("blue")
turtle.color("red")
def square(x,y):
	turtle.pencolor("green")
	turtle.color("green")
	turtle.penup()
	turtle.goto(x,y)
	turtle.begin_fill()
	turtle.pendown()
	turtle.goto(x+20,y)
	turtle.goto(x+20,y+20)
	turtle.goto(x,y+20)
	turtle.goto(x,y)
	turtle.end_fill()
turtle.ondrag(turtle.goto,add=True)
Exemple #32
0
	turtle.goto(x,y - cursorSize/2)
	turtle.pendown()
	turtle.circle(cursorSize)
	turtle.penup()
	turtle.end_fill()

def onDrag(x,y):
	global cursorDrag
	if(cursorDrag):
		turtle.pendown()
	turtle.goto(x,y)
		

turtle.speed(0)
turtle.hideturtle()

drawPaintBoard()


color = "blue"
cursorCircle = True
cursorFill = False
cursorDrag = False
eraser = False
cursorSize = 10

turtle.onscreenclick(onClick,1,True)
turtle.ondrag(onDrag,1,False)

turtle.mainloop()
Exemple #33
0
def draw_canvas3():
    draw_triangle(0,0)
    turtle.color('red', 'red')
    turtle.onscreenclick(turtle.goto,btn=1,add=True)
    turtle.ondrag(turtle.goto,btn=1,add=True)
Exemple #34
0
def key_d():
    t.pendown()
def key_1():
    t.pensize(1)
def key_3():
    t.pensize(3)
def key_5():
    t.pensize(5)

t.setup(600,600)
s = t.Screen()
t.shapesize(2)
t.speed(0)
t.left(90)
new_clear()
t.ondrag(drag)
s.onkey(key_l,"l")
s.onkey(key_t,"t")
s.onkey(key_r,"r")
s.onkey(key_c,"c")
s.onkey(key_n,"n")
s.onkey(key_u,"u")
s.onkey(key_d,"d")
s.onkey(key_1,"1")
s.onkey(key_3,"3")
s.onkey(key_5,"5")
s.onscreenclick(draw,1)
s.onscreenclick(draw,3)
s.listen()

Exemple #35
0
def drag(x, y):
    t.ondrag(None)
    t.setheading(t.towards(x, y))
    t.goto(x, y)
    t.ondrag(drag)


def penup():
    t.penup()


def pendown():
    t.pendown()


def clean():
    t.clear()


def paint(x, y):
    t.color(random.choice(colors))


turtle.listen()
turtle.ondrag(drag)
turtle.onkey(penup, "z")
turtle.onkey(pendown, "x")
turtle.onscreenclick(paint, 3)
turtle.onkey(clean, "c")
s.mainloop()
Exemple #36
-1
	turtle.color("blue")
	
def change_color_white():
	turtle.pencolor("black")
	turtle.color("white")
	turtle.pensize(100)

turtle.onkeypress(change_color_red, "r")
turtle.onkeypress(change_color_blue, "b")
turtle.onkeypress(change_color_white, "w")
turtle.onkeypress(change_color_random, "k")
turtle.onscreenclick(draw_square, btn=3)



turtle.onscreenclick(draw_circle, add=True)



turtle.ondrag(turtle.goto, add=True)
turtle.ondrag(turtle.goto, btn=3, add=True)



turtle.pencolor("blue")
turtle.color("blue")



turtle.mainloop()