I was thinking of doing some simple animations in python,Tkinter and my biggest problem was getting things to move together. so I was wondering if there was a way to make say an arc and rectangle into one object to rotate and such.

sorry about leaving off my code but I had to cut it down to be small enough and still have the problem visible but here it is

``````from Tkinter import *
import math,cmath

def spin(canvas,item,angle):
cangle = cmath.exp((angle*math.pi/180)*1j)
coordinates = canvas.coords(item)
xs,ys = [],[]
for x,y in zip(coordinates[::2],coordinates[1::2]):
xs.append(x)
ys.append(y)
center = complex((max(xs)-min(xs))/2+min(xs),(max(ys)-min(ys))/2+min(ys))
lists = []
for x,y in zip(coordinates[::2],coordinates[1::2]):
v = cangle * (complex(x, y) - center) + center
lists.append(int(v.real))
lists.append(int(v.imag))
print lists
return lists

class App:

def __init__(self, master):

frame = Frame(master)
frame.grid()

canvas = Canvas(frame, width = 225, height = 225, bg="white")
canvas.grid()

canvas.create_arc(150,50, 200,100, extent=180, fill="blue", tag="arm")
##        shoulder
canvas.create_rectangle(150,75, 200,100, fill="blue", tag="arm")
##        sleeve
canvas.create_line(151,75, 199,75, fill="blue", tag="arm")
##        line between shoulder/sleeve

canvas.create_rectangle(150,100, 200,200, fill="tan", tag="arm")
##        the arm

for x in canvas.find_withtag("arm"):
coordinates = spin(canvas,x,90)
a,b,c,d = coordinates
canvas.coords(x, a,b,c,d)

canvas.create_arc(50,50, 100,100, extent=180, fill="blue", tag="arm")
##        shoulder
canvas.create_rectangle(50,75, 100,100, fill="blue", tag="arm")
##        sleeve
canvas.create_line(51,75, 99,75, fill="blue", tag="arm")
##        line between shoulder/sleeve

canvas.create_rectangle(50,100, 100,200, fill="tan", tag="arm")
##        the arm

root = Tk()

d = App(root)

root.wait_window()``````

it's a before and after view of the 90 degree spin. the arc didn't move but I probably just need to change the start/extent on it to make it spin.

ok I got the images merged by making a second canvas and drawing on that now I just need to get it to rotate but that can wait for another day.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.