Compare commits
2 Commits
1e6459eece
...
bffbecab78
Author | SHA1 | Date |
---|---|---|
|
bffbecab78 | |
|
ba9aa38055 |
|
@ -0,0 +1,170 @@
|
||||||
|
import turtle as tl
|
||||||
|
import random as rd
|
||||||
|
#setup
|
||||||
|
tl.setup(600,600,None,None)
|
||||||
|
tl.hideturtle()
|
||||||
|
tl.colormode(255)
|
||||||
|
t = tl.Turtle()
|
||||||
|
t.color("Blue")
|
||||||
|
t.goto(100,0)
|
||||||
|
t2 = tl.Turtle()
|
||||||
|
t2.color("Red")
|
||||||
|
t2.goto(-100,0)
|
||||||
|
tl.tracer(1)
|
||||||
|
|
||||||
|
#CENÁRIO
|
||||||
|
|
||||||
|
#moldura
|
||||||
|
tl.tracer(0)
|
||||||
|
tl.color("black")
|
||||||
|
tl.up()
|
||||||
|
tl.goto(-300,-300)
|
||||||
|
tl.down()
|
||||||
|
tl.goto(-300,300)
|
||||||
|
tl.goto(300,300)
|
||||||
|
tl.goto(300,-300)
|
||||||
|
|
||||||
|
#linhas
|
||||||
|
tl.bgcolor((205, 133, 63))
|
||||||
|
for _ in range(-6, 6):
|
||||||
|
tl.color((139, 69, 19))
|
||||||
|
tl.up()
|
||||||
|
tl.goto(-300, _ * 50)
|
||||||
|
tl.down()
|
||||||
|
tl.goto(300, _ * 50)
|
||||||
|
tl.up()
|
||||||
|
|
||||||
|
tl.color("light blue")
|
||||||
|
tl.goto(-300, 300)
|
||||||
|
tl.down()
|
||||||
|
tl.begin_fill()
|
||||||
|
|
||||||
|
#parede
|
||||||
|
tl.goto(-300, 250)
|
||||||
|
tl.goto(300, 250)
|
||||||
|
tl.goto(300,300)
|
||||||
|
tl.end_fill()
|
||||||
|
|
||||||
|
#casa de rato
|
||||||
|
tl.up()
|
||||||
|
tl.goto(170, 250)
|
||||||
|
tl.color("black")
|
||||||
|
tl.down()
|
||||||
|
tl.begin_fill()
|
||||||
|
tl.goto(190,250)
|
||||||
|
tl.goto(190,260)
|
||||||
|
tl.left(90)
|
||||||
|
tl.circle(10, 180)
|
||||||
|
tl.end_fill()
|
||||||
|
|
||||||
|
#FIM-CENÁRIO
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
|
||||||
|
|
||||||
|
#funções
|
||||||
|
def colide():
|
||||||
|
if t.distance(t2) < 10:
|
||||||
|
print("Vitoria")
|
||||||
|
tl.bye()
|
||||||
|
|
||||||
|
|
||||||
|
def godir():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(0)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
#pass
|
||||||
|
def goleft():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(180)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
#pass
|
||||||
|
def goup():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(90)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
#pass
|
||||||
|
def godown():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(270)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
# pass
|
||||||
|
|
||||||
|
|
||||||
|
#segunda tartaruga
|
||||||
|
def godir2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(0)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
#pass
|
||||||
|
def goleft2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(180)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
#pass
|
||||||
|
def goup2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(90)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
|
||||||
|
|
||||||
|
#pass
|
||||||
|
def godown2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(270)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide()
|
||||||
|
#pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#execução
|
||||||
|
tl.onkeypress(godir,"d")
|
||||||
|
tl.onkeypress(goleft,"a")
|
||||||
|
tl.onkeypress(goup,"w")
|
||||||
|
tl.onkeypress(godown, "s")
|
||||||
|
tl.onkeypress(godir2,"6")
|
||||||
|
tl.onkeypress(goleft2,"4")
|
||||||
|
tl.onkeypress(goup2,"8")
|
||||||
|
tl.onkeypress(godown2, "5")
|
||||||
|
tl.listen()
|
||||||
|
|
||||||
|
#loop
|
||||||
|
tl.mainloop()
|
|
@ -0,0 +1,98 @@
|
||||||
|
import turtle as tl
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
tl.setup(600, 600, None, None)
|
||||||
|
t = tl.Turtle()
|
||||||
|
t.goto(100, 0)
|
||||||
|
t.color("Blue")
|
||||||
|
t2 = tl.Turtle()
|
||||||
|
t2.color("Red")
|
||||||
|
t2.goto(-100, 0)
|
||||||
|
tl.tracer(1)
|
||||||
|
|
||||||
|
# Função de colisão
|
||||||
|
def colide():
|
||||||
|
# Verifica se as tartarugas estão na mesma posição (distância é 0)
|
||||||
|
if t.distance(t2) < 10: # Considerando uma distância pequena como colisão
|
||||||
|
print("VITÓRIA!")
|
||||||
|
tl.bye() # Fecha a janela quando as tartarugas colidem
|
||||||
|
|
||||||
|
# Funções de movimento para a primeira tartaruga
|
||||||
|
def godir():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(0)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
def goleft():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(180)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
def goup():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(90)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
def godown():
|
||||||
|
tl.tracer(0)
|
||||||
|
t.seth(270)
|
||||||
|
t.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
# Funções de movimento para a segunda tartaruga
|
||||||
|
def godir2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(0)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
def goleft2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(180)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
def goup2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(90)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
def godown2():
|
||||||
|
tl.tracer(0)
|
||||||
|
t2.seth(270)
|
||||||
|
t2.forward(50)
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
colide() # Verifica colisão após o movimento
|
||||||
|
|
||||||
|
# Execução
|
||||||
|
tl.onkeypress(godir, "d")
|
||||||
|
tl.onkeypress(goleft, "a")
|
||||||
|
tl.onkeypress(goup, "w")
|
||||||
|
tl.onkeypress(godown, "s")
|
||||||
|
tl.onkeypress(godir2, "6")
|
||||||
|
tl.onkeypress(goleft2, "4")
|
||||||
|
tl.onkeypress(goup2, "8")
|
||||||
|
tl.onkeypress(godown2, "5")
|
||||||
|
tl.listen()
|
||||||
|
|
||||||
|
# Loop
|
||||||
|
tl.mainloop()
|
|
@ -0,0 +1,131 @@
|
||||||
|
import turtle as tl
|
||||||
|
import time
|
||||||
|
|
||||||
|
#setup
|
||||||
|
tl.setup(900,600,None,None)
|
||||||
|
|
||||||
|
#funções aleatorias super nescessarias
|
||||||
|
def retan(color):
|
||||||
|
tl.begin_fill()
|
||||||
|
tl.color(color)
|
||||||
|
tl.fd(200)
|
||||||
|
tl.left(90)
|
||||||
|
tl.fd(100)
|
||||||
|
tl.left(90)
|
||||||
|
tl.fd(200)
|
||||||
|
tl.left(90)
|
||||||
|
tl.fd(100)
|
||||||
|
tl.end_fill()
|
||||||
|
tl.up()
|
||||||
|
tl.left(180)
|
||||||
|
tl.fd(100)
|
||||||
|
tl.right(90)
|
||||||
|
#pass
|
||||||
|
|
||||||
|
def eyes(size):
|
||||||
|
tl.down()
|
||||||
|
tl.color("white")
|
||||||
|
tl.begin_fill()
|
||||||
|
tl.circle(size)
|
||||||
|
tl.end_fill()
|
||||||
|
tl.color("black")
|
||||||
|
tl.circle(size)
|
||||||
|
tl.up()
|
||||||
|
#pass
|
||||||
|
|
||||||
|
#63 iterações no reichtangle
|
||||||
|
def reichtangle(pos):
|
||||||
|
tl.goto(pos, -150)
|
||||||
|
tl.down()
|
||||||
|
retan("black")
|
||||||
|
retan("light gray")
|
||||||
|
retan("red")
|
||||||
|
tl.up()
|
||||||
|
tl.right(90)
|
||||||
|
tl.fd(50)
|
||||||
|
tl.left(90)
|
||||||
|
tl.fd(50)
|
||||||
|
eyes(15)
|
||||||
|
tl.fd(100)
|
||||||
|
eyes(15)
|
||||||
|
#pass
|
||||||
|
|
||||||
|
def french(pos, state):
|
||||||
|
tl.up()
|
||||||
|
tl.goto(pos,-150)
|
||||||
|
tl.begin_fill()
|
||||||
|
tl.color("white")
|
||||||
|
tl.circle(100)
|
||||||
|
tl.end_fill()
|
||||||
|
tl.color("black")
|
||||||
|
tl.circle(100)
|
||||||
|
tl.circle(100,30)
|
||||||
|
tl.begin_fill()
|
||||||
|
tl.color("blue")
|
||||||
|
tl.circle(100, 120)
|
||||||
|
tl.end_fill()
|
||||||
|
tl.color("black")
|
||||||
|
tl.circle(100, 60)
|
||||||
|
tl.begin_fill()
|
||||||
|
tl.color("red")
|
||||||
|
tl.circle(100, 120)
|
||||||
|
tl.end_fill()
|
||||||
|
if state == "normal":
|
||||||
|
tl.circle(100,60)
|
||||||
|
tl.seth(90)
|
||||||
|
tl.fd(130)
|
||||||
|
tl.left(90)
|
||||||
|
eyes(10)
|
||||||
|
tl.fd(50)
|
||||||
|
eyes(10)
|
||||||
|
elif state == "startled":
|
||||||
|
tl.circle(100,40)
|
||||||
|
tl.seth(90)
|
||||||
|
tl.fd(150)
|
||||||
|
tl.seth(180)
|
||||||
|
eyes(15)
|
||||||
|
tl.fd(80)
|
||||||
|
eyes(15)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#fundo de tela
|
||||||
|
tl.tracer(0)
|
||||||
|
tl.bgcolor("light blue")
|
||||||
|
bg = tl.Turtle()
|
||||||
|
bg.up()
|
||||||
|
bg.begin_fill()
|
||||||
|
bg.color("green")
|
||||||
|
bg.goto(-450,-300)
|
||||||
|
bg.down()
|
||||||
|
bg.goto(-450, 0)
|
||||||
|
bg.goto(450, 0)
|
||||||
|
bg.goto(450,-300)
|
||||||
|
bg.goto(-450,-300)
|
||||||
|
bg.end_fill()
|
||||||
|
bg.up()
|
||||||
|
bg.goto(400,250)
|
||||||
|
bg.begin_fill()
|
||||||
|
bg.color("Yellow")
|
||||||
|
bg.circle(25)
|
||||||
|
bg.end_fill()
|
||||||
|
bg.hideturtle()
|
||||||
|
tl.update()
|
||||||
|
tl.tracer(1)
|
||||||
|
tl.up()
|
||||||
|
|
||||||
|
tl.tracer(0)
|
||||||
|
reichtangle(-400)
|
||||||
|
french(200, "startled")
|
||||||
|
tl.update()
|
||||||
|
#63 é o numero de iterações para 1 reichtangle
|
||||||
|
#for i in range(63):
|
||||||
|
#tl.undo()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
tl.exitonclick()
|
||||||
|
tl.mainloop()
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 360 KiB |
Loading…
Reference in New Issue