Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

import turtle

import math
fereastra=turtle.Screen()
fereastra.title("Desen")
fereastra.setup(600,600)

t1=turtle.Turtle()
t1.shape("arrow")
t1.pencolor("purple")
t1.speed(10)
t1.pensize(3)

t1.penup()
t1.goto(-200,300)
t1.pendown()
t1.setheading(270)
t1.forward(600)
ar=0
br=0
ab=0
bb=0
ag=0
bg=0
gumx=0
gumy=0
asa=0
bsb=0

def cerc(x,y,z):
t1.penup()
t1.goto(x,y)
if(z==1):
rosu()
else:
if(z==2):
blue()
else:
if(z==3):
green()

def rosu():
global ar, br
t1.pencolor("red")
t1.fillcolor("red")
t1.pendown()
t1.begin_fill()
t1.circle(15)
t1.end_fill()
ar=t1.xcor()
br=t1.ycor()

def blue():
global ab, bb
t1.pencolor("blue")
t1.fillcolor("blue")
t1.pendown()
t1.begin_fill()
t1.circle(15)
t1.end_fill()
ab=t1.xcor()
bb=t1.ycor()

def green():
global ag, bg
t1.pencolor("green")
t1.fillcolor("green")
t1.pendown()
t1.begin_fill()
t1.circle(15)
t1.end_fill()
ag=t1.xcor()
bg=t1.ycor()

cerc(-270,200,1)
cerc(-270,100,2)
cerc(-270,0,3)

def guma(x,y):
global gumx, gumy
t1.penup()
t1.goto(x,y)
t1.pendown()
t1.pencolor("black")
t1.fillcolor("black")
t1.begin_fill()
t1.left(90)
dreptunghi(20,90,15)
t1.end_fill()
t1.right(90)
dreptunghi(10,270,15)
gumx=t1.xcor()
gumy=t1.ycor()

def dreptunghi(a,b,c):
t1.forward(a)
t1.left(b)
t1.forward(c)
t1.left(b)
t1.forward(a)
t1.left(b)
t1.forward(c)

guma(-260,-100)

#a=forward L
#b=left/right
#c=forward l

def save(x,y):
t1.penup()
t1.goto(x,y)
t1.pendown()
t1.pensize(1)
t1.pencolor("magenta")
t1.fillcolor("magenta")
t1.left(90)
dreptunghi(30,90,20)
t1.begin_fill()
dreptunghi(15,90,30)
t1.end_fill()
t1.fillcolor("white")
t1.setheading(0)
t1.forward(6)
t1.right(90)
t1.begin_fill()
dreptunghi(12,90,18)
t1.end_fill()
global asa, bsb
asa=t1.xcor()
bsb=t1.ycor()

save(-270,-165)

#######
####
t1.pencolor("purple")
t1.pensize(3)
t1.penup()
t1.goto(-200,220)
t1.pendown()
t1.setheading(0)
t1.forward(500)

####
t1.penup()
t1.goto(240,220)
t1.pendown()
t1.setheading(270)
t1.forward(550)

t1.setheading(180)
t1.penup()
t1.goto(240,-220)
t1.pendown()
t1.forward(440)

xblack=0
yblack=0
def triunghi(x):
global xblack, yblack
t1.setheading(90)
t1.forward(x)
t1.left(120)
t1.forward(x)
xblack=t1.xcor()
yblack=t1.ycor()
t1.left(120)
t1.forward(x)

t1.pencolor("black")
t1.penup()
t1.goto(270,150)
t1.pendown()
t1.fillcolor("black")
t1.begin_fill()
triunghi(20)
t1.end_fill()
t1.pencolor("DarkKhaki")
t1.penup()
t1.goto(260,110)
t1.pendown()
t1.fillcolor("DarkKhaki")
t1.begin_fill()
t1.circle(10)
t1.end_fill()
xKaki=t1.xcor()
yKaki=t1.ycor()

t1.setheading(180)
t1.pencolor("LimeGreen")
t1.penup()
t1.goto(272,90)
t1.pendown()
t1.fillcolor("LimeGreen")
t1.begin_fill()
dreptunghi(15,90,15)
t1.end_fill()
xLime=t1.xcor()
yLime=t1.ycor()

t1.pencolor("goldenrod")
t1.penup()
t1.goto(265,35)
t1.pendown()
t1.fillcolor("goldenrod")
t1.begin_fill()
t1.setheading(90)
t1.forward(25)
t1.left(150)
t1.forward(15)
t1.left(60)
t1.forward(15)
t1.end_fill()
xgold=t1.xcor()
ygold=t1.ycor()

t1.hideturtle()

############
t2=turtle.Turtle()
t2.shape("turtle")
t2.pencolor("blue")
t2.speed(10)
t2.pensize(3)

def desen(x,y):
t2.goto(x,y)
t2.ondrag(desen)

desen2=0
def alegere(x,y):
if(math.fabs(x-ar)<=25 and math.fabs(y-br)<=25):
t2.pencolor("red")
else:
if(math.fabs(x-ab)<=25 and math.fabs(y-bb)<=25):
t2.pencolor("blue")
else:
if(math.fabs(x-ag)<=25 and math.fabs(y-bg)<=25):
t2.pencolor("green")
else:
if(math.fabs(x-gumx)<=25 and math.fabs(y-gumy)<=25):
t2.clear()
else:
if(math.fabs(x-xblack)<=20 and math.fabs(y-yblack)<=20):
t2.shape("triangle")
t2.ondrag(desen)
else:
if(math.fabs(x-xKaki)<=20 and math.fabs(y-yKaki)<=20):
t2.shape("circle")
t2.ondrag(desen)
else:
if(math.fabs(x-asa)<=25 and math.fabs(y-bsb)<=25):
global desen2

desen2=t2.getscreen().getcanvas().postscript(file="desenSalvat.ps")
#https://psviewer.org/onlineviewer.aspx
else:
if(math.fabs(x-xLime)<=20 and math.fabs(y-
yLime)<=20):
t2.shape("square")
t2.ondrag(desen)
else:
if(math.fabs(x-xgold)<=20 and math.fabs(y-
ygold)<=20):
t2.shape("arrow")
t2.ondrag(desen)

def initial():
t2.shape("turtle")
t2.ondrag(desen)

def final():
t2.shape("classic")
t2.ondrag(desen)
def fulg():
t2.clear()
t2.penup()
t2.goto(0,0)
t2.pendown()
t2.setheading(0)
def vshape():
t2.right(25)
t2.forward(50)
t2.backward(50)
t2.left(50)
t2.forward(50)
t2.backward(50)
t2.right(25)

def snowflakeA():
for x in range(0,4):
t2.forward(30)
vshape()
t2.backward(120)

def snowflake():
for x in range(0,6):
snowflakeA()
t2.right(60)

snowflake()
t2.hideturtle()

def initial2():
t2.clear()
t2.showturtle()
t2.ondrag(desen)

turtle.listen()

turtle.ondrag(desen)
turtle.onscreenclick(alegere)
turtle.onkeypress(initial,'i')
turtle.onkeypress(final,'f')
turtle.onkeypress(fulg,'u')
turtle.onkeypress(initial2,'a')

You might also like