هذي بعض اللوحات الفنية باستخدام مكتبة السلحفاة…
هذا الكود للتجربة…
from turtle import Turtle, Screen
import random
window = Screen()
window.setup(width=1000, height=1000)
#window.bgcolor('black')
sam = Turtle()
colors = ["red", "orange", "yellow", "green", "blue", "purple", "aquamarine", "magenta", "pink", "lime"]
sam.speed(20)
def circle():
sam.color(random.choice(colors))
sam.fillcolor(random.choice(colors))
sam.begin_fill()
sam.circle(random.randint(10,100))
sam.end_fill()
def triangle():
distance = random.randint(10,100)
sam.begin_fill()
sam.fillcolor(random.choice(colors))
sam.lt(random.randint(10,60))
for i in range(3):
sam.color(random.choice(colors))
sam.fd(distance)
sam.lt(120)
sam.end_fill()
def square():
distance = random.randint(10,100)
sam.begin_fill()
sam.fillcolor(random.choice(colors))
sam.lt(random.randint(10,60))
for i in range(4):
sam.color(random.choice(colors))
sam.fd(distance)
sam.lt(90)
sam.end_fill()
def cube(s=100):
sam.speed(s)
sam.fillcolor(random.choice(colors))
sam.begin_fill()
for _ in range(4):
sam.fd(50)
sam.lt(90)
sam.end_fill()
sam.fillcolor(random.choice(colors))
sam.begin_fill()
sam.lt(45)
sam.fd(25)
sam.rt(45)
sam.fd(50)
sam.rt(135)
sam.fd(25)
sam.end_fill()
sam.fillcolor(random.choice(colors))
sam.begin_fill()
sam.rt(180)
sam.fd(25)
sam.lt(45)
sam.fd(50)
sam.lt(135)
sam.fd(25)
sam.lt(45)
sam.fd(50)
sam.end_fill()
sam.rt(90)
sam.fd(50)
sam.rt(90)
sam.fd(50)
sam.fillcolor(random.choice(colors))
sam.begin_fill()
sam.rt(45)
sam.fd(30)
sam.rt(45)
sam.fd(48)
sam.rt(130)
sam.fd(30)
sam.end_fill()
def design_1(s=100):
sam.speed(s)
distance = random.randint(30,180)
for i in range(random.randint(15,40)):
sam.color(random.choice(colors))
sam.fillcolor(random.choice(colors))
sam.begin_fill()
sam.fd(distance)
sam.lt(120)
sam.fd(distance)
sam.lt(120)
sam.fd(distance)
sam.end_fill()
sam.lt(130)
def design_2(s=100):
sam.speed(s)
distance = random.randint(30,80)
for i in range(random.randint(10,36)):
sam.color(colors [i%6])
sam.fillcolor(colors [i%6])
sam.begin_fill()
sam.fd(distance)
sam.lt(90)
sam.fd(distance)
sam.lt(90)
sam.fd(distance)
sam.lt(90)
sam.fd(distance)
sam.lt(90)
sam.end_fill()
sam.lt(10)
def design_3(s=100):
sam.speed(s)
distance = random.randint(30,80)
for i in range (random.randint(10,36)):
sam.color(random.choice(colors))
sam.fillcolor(random.choice(colors))
sam.begin_fill()
sam.circle(distance)
sam.lt(10)
sam.end_fill()
def design_4(loop=15, d=5):
sam.speed(50)
distance = 5
for _ in range(loop):
sam.color(random.choice(colors))
sam.fd(distance)
sam.lt(90)
sam.fd(distance)
sam.lt(90)
distance += d
def design_5(s=1000):
sam.speed(s)
sam.rt(90)
sam.color('red2')
for _ in range(10):
size = 1
sam.pu()
sam.goto(random.randint(-450,450), random.randint(-450,450))
sam.pd()
for _ in range(100):
sam.fd(1)
size += 1
sam.pensize(size)
sam.pensize(1)
def design_6():
sam.speed(50)
for _ in range(300):
sam.pensize(random.randint(1,20))
sam.color(random.choice(colors))
sam.fd(random.randint(5,200))
sam.lt(random.choice((45,90)))
def my_painting(loop=10):
my_funct = (1, 2, 3, 4, 5, 6, 7, 8)
for _ in range(loop):
sam.pu()
sam.goto(random.randint(-400,400), random.randint(-400,400))
sam.pd()
a = random.choice(my_funct)
if a == 1:
design_1()
elif a == 2:
design_2()
elif a == 3:
design_3()
elif a == 4:
design_4()
elif a == 5:
square()
elif a == 6:
triangle()
elif a == 7:
circle()
else:
cube()
window.exitonclick()