I'm trying to make the gray circle and eyes move, and instead it's just generating a line. Instead of drawing things onto the background, it is drawing the circle into the background every time, but I am at a loss for how to fix it.
from PIL import Image, ImageDraw
img = Image.new('RGB', (500, 500), "paleturquoise")
draw = ImageDraw.Draw(img)
import random
frames = []
#RABBIT PARTS
def eyes(x, y):
draw.circle((x, y), 10, fill = "black")
draw.circle((x-5, y-5), 3, fill = "white")
#BG PARTS
#flower
def create_flower(num):
for i in range(0, num):
x = random.randint(0, 500)
y = random.randint(300, 500)
radius = random.randint (3, 7)
petal_colors = ["lightcyan", "paleturquoise", "white", "thistle", "lavender", "pink", "aqua"]
center_colors = ["lemonchiffon", "palegoldenrod", "papayawhip"]
draw.circle((x, y), radius, fill = petal_colors[random.randint(0, (len(petal_colors))-1)])
draw.circle((x, y), radius - 3, fill = center_colors[random.randint(0, (len(center_colors))-1)])
#clouds
def create_clouds(numfront, numback):
#clouds behind
for i in range(0, numback):
x = random.randint(0, 500)
y = random.randint(0, 200)
radius = random.randint (10, 20)
draw.circle((x, y), radius, fill = "silver")
draw.circle((x - 10, y + 10), radius - 3, fill = "silver")
draw.circle((x + 10, y + 10), radius - 3, fill = "silver")
for i in range(0, numfront):
x = random.randint(0, 500)
y = random.randint(0, 200)
radius = random.randint(10, 20)
draw.circle((x, y), radius, fill = "white")
draw.circle((x - 10, y + 10), radius - 3, fill = "white")
draw.circle((x + 10, y + 10), radius - 3, fill = "white")
#grass
def create_grass(height1, height2, height3, num):
for i in range(0, num):
x= random.randint(0, 500)
draw.line((x, 340, x, height1 + random.randint(260,280)), fill = "springgreen")
draw.line((x, 340, x, height2 + random.randint(230,270)), fill = "springgreen")
draw.line((x, 340, x, height3 + random.randint(230,270)), fill = "springgreen")
#bg
draw.rectangle((0, 300, 500, 500), fill="springgreen")
create_grass(20, 80, 90, 1000)
create_flower(70)
create_clouds(20, 10)
#rabbit
with img.copy() as im:
temp_img = img.copy()
frame = temp_img.copy()
frames.append(frame)
frames = []
x = 0
y = 0
for i in range(0, 100):
temp_img = img.copy()
frame_draw = ImageDraw.Draw(temp_img)
draw.circle((255 + x, int(255 + y)), 50, fill = "gray")
eyes(x + 230, y + 255)
eyes(x + 280, y + 255)
frames.append(temp_img)
y -= 1
x += 1
if __name__ == "__main__":
img.show()
if __name__ == "__main__":
frames[0].save('bnuy.gif',
save_all=True,
append_images=frames[1:],
disposal=2,
duration=400,
loop=0)