I have a code. And I generated random fibers with turtle. But I would like to obtain 100 different randamized images. I will create a dataset. How can i change the code and obtain the 100 images in a file by turtle ?
from turtle import Screen, Turtle
from random import randint
width, height = 500,500
fiber_r = 35
fiber_num = 50
cursor_size = 20
screen = Screen()
screen.setup(width, height)
fiber = Turtle()
fiber.hideturtle()
fiber.color('black')
fiber.shape('circle')
fiber.shapesize(fiber_r / cursor_size)
fiber.speed('fastest')
fiber.penup()
fibers = []
for _ in range(fiber_num):
fiberr = fiber.clone()
fiberr.setposition( \
randint(fiber_r - width/2, width/2 - fiber_r), \
randint(fiber_r - height/2, height/2 - fiber_r) \
)
while any(map((lambda a: lambda b: a.distance(b) < fiber_r)(fiberr), fibers)):
fiberr.setposition( \
randint(fiber_r - width/2, width/2 - fiber_r), \
randint(fiber_r - height/2, height/2 - fiber_r) \
)
fiberr.showturtle()
fibers.append(fiberr)
screen.exitonclick()
Aucun commentaire:
Enregistrer un commentaire